fix(mongodb): merge URI auth fields with username/password override (#9889)

* fix(mongodb): merge URI auth fields with username/password override

SetAuth replaced the whole Credential parsed from the URI, dropping
AuthSource and AuthMechanism. Start from the URI-parsed Auth and only
override the username and password so credentials scoped to a specific
auth database keep working.

* fix(mongodb): set PasswordSet for explicit credentials

Required by GSSAPI auth when a password is supplied; ignored for other
mechanisms.
This commit is contained in:
Chris Lu
2026-06-09 00:18:33 -07:00
committed by GitHub
parent 2871e6552a
commit 7aba10fa1a
+8 -3
View File
@@ -74,10 +74,15 @@ func (store *MongodbStore) connection(uri string, poolSize uint64, ssl bool, ssl
}
if username != "" && password != "" {
creds := options.Credential{
Username: username,
Password: password,
// Keep auth fields parsed from the URI (AuthSource, AuthMechanism, ...)
// and only override the credentials.
creds := options.Credential{}
if opts.Auth != nil {
creds = *opts.Auth
}
creds.Username = username
creds.Password = password
creds.PasswordSet = true
opts.SetAuth(creds)
}