Skip to content

Commit

Permalink
Merge #82358
Browse files Browse the repository at this point in the history
82358: democluster: ensure `sslrootcert` is populated r=rafiss a=knz

The `pgx` driver defaults the root CA cert to ~/.postgresql/root.crt
if not provided in the connection URL. For demo clusters, that can
never work.

This commit changes the generated demo URLs to include `sslrootcert`
explicitly and point it to the demo-generate root CA cert.

Release note: None

Co-authored-by: Raphael 'kena' Poss <[email protected]>
  • Loading branch information
craig[bot] and knz committed Jun 6, 2022
2 parents 1860eaa + 2eddb52 commit 443f1dc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/cli/democluster/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ go_library(
"//pkg/roachpb",
"//pkg/rpc",
"//pkg/security",
"//pkg/security/certnames",
"//pkg/security/username",
"//pkg/server",
"//pkg/server/pgurl",
Expand Down
11 changes: 10 additions & 1 deletion pkg/cli/democluster/demo_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/rpc"
"github.com/cockroachdb/cockroach/pkg/security"
"github.com/cockroachdb/cockroach/pkg/security/certnames"
"github.com/cockroachdb/cockroach/pkg/security/username"
"github.com/cockroachdb/cockroach/pkg/server"
"github.com/cockroachdb/cockroach/pkg/server/pgurl"
Expand Down Expand Up @@ -1164,9 +1165,17 @@ func (c *transientCluster) getNetworkURLForServer(
if c.demoCtx.Insecure {
u.WithInsecure()
} else {
caCert := certnames.CACertFilename()
if isTenant {
caCert = certnames.TenantClientCACertFilename()
}

u.
WithAuthn(pgurl.AuthnPassword(true, c.adminPassword)).
WithTransport(pgurl.TransportTLS(pgurl.TLSRequire, ""))
WithTransport(pgurl.TransportTLS(
pgurl.TLSRequire,
filepath.Join(c.demoDir, caCert),
))
}
return u, nil
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/cli/interactive_tests/test_demo.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ eexpect "(sql)"
eexpect "demo:"
eexpect ":26258"
eexpect "sslmode=require"
eexpect "sslrootcert="
eexpect "(sql/unix)"
eexpect "demo:"
eexpect "=26258"
Expand All @@ -123,6 +124,7 @@ eexpect "(sql)"
eexpect "demo:"
eexpect ":26257"
eexpect "sslmode=require"
eexpect "sslrootcert="
eexpect "defaultdb>"

send_eof
Expand All @@ -142,6 +144,7 @@ eexpect "http://"
eexpect "(sql)"
eexpect "demo:"
eexpect "sslmode=require"
eexpect "sslrootcert="
eexpect "(sql/unix)"
eexpect "demo:"
eexpect "defaultdb>"
Expand Down Expand Up @@ -190,6 +193,7 @@ spawn $argv demo --insecure=false --no-example-database
# Expect that security related tags are part of the connection URL.
eexpect "(sql)"
eexpect "sslmode=require"
eexpect "sslrootcert="
eexpect "defaultdb>"

send_eof
Expand Down

0 comments on commit 443f1dc

Please sign in to comment.