Skip to content
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
6 changes: 6 additions & 0 deletions lib/srv/db/common/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,9 +892,15 @@ func shouldUseSystemCertPool(database types.Database) bool {
case types.DatabaseTypeOpenSearch:
// OpenSearch is commonly hosted on AWS and uses Amazon Root CAs.
return true

case types.DatabaseTypeSpanner:
// Spanner is hosted on GCP.
return true

case types.DatabaseTypeMongoAtlas:
// Atlas may use either Let's Encrypt or Google GTS Root R3/R4:
// https://www.mongodb.com/docs/atlas/reference/faq/security/
return true
}
return false
}
Expand Down
35 changes: 28 additions & 7 deletions lib/srv/db/common/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/gravitational/trace"
"github.com/jonboulle/clockwork"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/gravitational/teleport/api/client/proto"
Expand Down Expand Up @@ -228,6 +229,12 @@ func TestAuthGetTLSConfig(t *testing.T) {
expectServerName: "my-postgres.postgres.database.azure.com",
expectRootCAs: systemCertPoolWithCA,
},
{
name: "MongoDB Atlas with downloaded CA",
sessionDatabase: newMongoAtlasDatabaseWithCA(t, fixtures.TLSCACertPEM),
expectClientCertificates: true,
expectRootCAs: systemCertPoolWithCA,
},
}

for _, test := range tests {
Expand All @@ -238,20 +245,20 @@ func TestAuthGetTLSConfig(t *testing.T) {
"defaultUser")
require.NoError(t, err)

require.Equal(t, test.expectServerName, tlsConfig.ServerName)
require.Equal(t, test.expectInsecureSkipVerify, tlsConfig.InsecureSkipVerify)
require.True(t, test.expectRootCAs.Equal(tlsConfig.RootCAs))
assert.Equal(t, test.expectServerName, tlsConfig.ServerName)
assert.Equal(t, test.expectInsecureSkipVerify, tlsConfig.InsecureSkipVerify)
assert.True(t, test.expectRootCAs.Equal(tlsConfig.RootCAs))

if test.expectClientCertificates {
require.Len(t, tlsConfig.Certificates, 1)
assert.Len(t, tlsConfig.Certificates, 1)
} else {
require.Empty(t, tlsConfig.Certificates)
assert.Empty(t, tlsConfig.Certificates)
}

if test.expectVerifyConnection {
require.NotNil(t, tlsConfig.VerifyConnection)
assert.NotNil(t, tlsConfig.VerifyConnection)
} else {
require.Nil(t, tlsConfig.VerifyConnection)
assert.Nil(t, tlsConfig.VerifyConnection)
}
})
}
Expand Down Expand Up @@ -848,6 +855,20 @@ func newMongoAtlasDatabase(t *testing.T, aws types.AWS) types.Database {
return database
}

func newMongoAtlasDatabaseWithCA(t *testing.T, ca string) types.Database {
t.Helper()

database, err := types.NewDatabaseV3(types.Metadata{
Name: "test-database",
}, types.DatabaseSpecV3{
Protocol: defaults.ProtocolMongoDB,
URI: "test.xxxxxxx.mongodb.net",
})
require.NoError(t, err)
database.SetStatusCA(ca)
return database
}

type databaseSpecOpt func(spec *types.DatabaseSpecV3)

func withCA(ca string) databaseSpecOpt {
Expand Down
Loading