Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v9] Never use --tlsUseSystemCA and --tlsCAFile together with mongosh #12363

Merged
merged 1 commit into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/client/db/dbcmd/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,17 +381,17 @@ func (c *CLICommandBuilder) getMongoCommand() *exec.Cmd {
flags.tlsCertKeyFile,
c.profile.DatabaseCertPathForCluster(c.tc.SiteName, c.db.ServiceName))

// mongosh does not load system CAs by default which will cause issues if
// the proxy presents a certificate signed by a non-recognized authority
// which your system trusts (e.g. mkcert).
if hasMongosh {
args = append(args, "--tlsUseSystemCA")
}

if c.options.caPath != "" {
// caPath is set only if mongo connects to the Teleport Proxy via ALPN SNI Local Proxy
// and connection is terminated by proxy identity certificate.
args = append(args, []string{flags.tlsCAFile, c.options.caPath}...)
} else {
// mongosh does not load system CAs by default which will cause issues if
// the proxy presents a certificate signed by a non-recognized authority
// which your system trusts (e.g. mkcert).
if hasMongosh {
args = append(args, "--tlsUseSystemCA")
}
}
}

Expand Down
19 changes: 19 additions & 0 deletions lib/client/db/dbcmd/dbcmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,25 @@ func TestCLICommandBuilderGetConnectCommand(t *testing.T) {
"--tlsUseSystemCA",
"mydb"},
},
{
name: "mongosh",
dbProtocol: defaults.ProtocolMongoDB,
databaseName: "mydb",
opts: []ConnectCommandFunc{
WithLocalProxy("localhost", 12345, "/tmp/keys/example.com/cas/example.com.pem")},
execer: &fakeExec{
execOutput: map[string][]byte{
"mongosh": []byte("1.1.6"),
},
},
cmd: []string{"mongosh",
"--host", "localhost",
"--port", "12345",
"--tls",
"--tlsCertificateKeyFile", "/tmp/keys/example.com/bob-db/db.example.com/mysql-x509.pem",
"--tlsCAFile", "/tmp/keys/example.com/cas/example.com.pem",
"mydb"},
},
{
name: "mongosh no TLS",
dbProtocol: defaults.ProtocolMongoDB,
Expand Down