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
15 changes: 12 additions & 3 deletions lib/auth/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,25 @@ func (a *Server) generateDatabaseClientCert(ctx context.Context, req *proto.Data
}
// db clients should trust the Database Server CA when establishing
// connection to a database, so return that CA's certs in the response.
dbServerCA, err := a.GetCertAuthority(ctx, types.CertAuthID{
Type: types.DatabaseCA,
//
// The only exception is the SQL Server with PKINIT integration, where the
// `kinit` command line needs our client CA to trust the user certificates
// we pass.
returnedCAType := types.DatabaseCA
if req.CertificateExtensions == proto.DatabaseCertRequest_WINDOWS_SMARTCARD {
returnedCAType = types.DatabaseClientCA
}

returnedCA, err := a.GetCertAuthority(ctx, types.CertAuthID{
Type: returnedCAType,
DomainName: clusterName.GetClusterName(),
}, false)
if err != nil {
return nil, trace.Wrap(err)
}
return &proto.DatabaseCertResponse{
Cert: cert,
CACerts: services.GetTLSCerts(dbServerCA),
CACerts: services.GetTLSCerts(returnedCA),
}, nil
}

Expand Down
25 changes: 21 additions & 4 deletions lib/auth/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func TestDBCertSigning(t *testing.T) {
tests := []struct {
name string
requester proto.DatabaseCertRequest_Requester
extensions proto.DatabaseCertRequest_Extensions
wantCertSigner []byte
wantCACerts [][]byte
wantKeyUsage []x509.ExtKeyUsage
Expand All @@ -170,16 +171,32 @@ func TestDBCertSigning(t *testing.T) {
wantCACerts: [][]byte{activeDBClientCACert, newDBClientCACert},
wantKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
},
{
name: "DB service request for SQL Server databases is signed by active db client and trusts db client CAs",
extensions: proto.DatabaseCertRequest_WINDOWS_SMARTCARD,
wantCertSigner: activeDBClientCACert,
wantCACerts: [][]byte{activeDBClientCACert, newDBClientCACert},
wantKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth},
},
{
name: "tctl request for SQL Server databases is signed by new db CA and trusts db client CAs",
requester: proto.DatabaseCertRequest_TCTL,
extensions: proto.DatabaseCertRequest_WINDOWS_SMARTCARD,
wantCertSigner: newDBCACert,
wantCACerts: [][]byte{activeDBClientCACert, newDBClientCACert},
wantKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
certResp, err := authServer.AuthServer.GenerateDatabaseCert(ctx, &proto.DatabaseCertRequest{
CSR: csr,
ServerName: "localhost",
TTL: proto.Duration(time.Hour),
RequesterName: tt.requester,
CSR: csr,
ServerName: "localhost",
TTL: proto.Duration(time.Hour),
RequesterName: tt.requester,
CertificateExtensions: tt.extensions,
})
require.NoError(t, err)
require.Equal(t, tt.wantCACerts, certResp.CACerts)
Expand Down