Skip to content

Commit

Permalink
Added token authentication support for mongodb (#5)
Browse files Browse the repository at this point in the history
Co-authored-by: Sai Sandeep Rangisetti <sandeep.sai@flipkart.com>
  • Loading branch information
ssrangisetti and saisandeep-flipkart committed Mar 12, 2024
1 parent 78011d1 commit 5b5bc53
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/srv/db/mongodb/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ func (e *Engine) getConnectionOptions(ctx context.Context, sessionCtx *common.Se
if err != nil {
return nil, trace.Wrap(err)
}
switch {
case e.Auth.IsTokenAuthEnabled() && sessionCtx.Database.IsTokenAuthEnabled():
tlsConfig = nil
}
return []topology.ConnectionOption{
topology.WithTLSConfig(func(*tls.Config) *tls.Config {
return tlsConfig
Expand Down Expand Up @@ -180,6 +184,20 @@ func (e *Engine) getAuthenticator(ctx context.Context, sessionCtx *common.Sessio
switch {
case isAtlasDB && awsutils.IsRoleARN(sessionCtx.DatabaseUser):
return e.getAWSAuthenticator(ctx, sessionCtx)
case e.Auth.IsTokenAuthEnabled() && sessionCtx.Database.IsTokenAuthEnabled():
user, password, err := e.Auth.GetTokenAuthCredentials(ctx, sessionCtx)
if err != nil {
return nil, trace.Wrap(err)
}
authenticator, err := auth.CreateAuthenticator(auth.SCRAMSHA256, &auth.Cred{
Username: user,
Password: password,
Source: "admin",
})
if err != nil {
return nil, trace.Wrap(err)
}
return authenticator, nil
default:
e.Log.Debug("Authenticating to database using certificates.")
authenticator, err := auth.CreateAuthenticator(auth.MongoDBX509, &auth.Cred{
Expand Down

0 comments on commit 5b5bc53

Please sign in to comment.