-
Notifications
You must be signed in to change notification settings - Fork 906
GODRIVER-3215 Fix default auth source for auth specified via ClientOptions. #1764
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
GODRIVER-3215 Fix default auth source for auth specified via ClientOptions. #1764
Conversation
API Change Report./x/mongo/driver/topologycompatible changesConvertCreds: added |
1643840
to
2422048
Compare
2422048
to
d6a25ad
Compare
|
||
// NewAuthenticator returns a [driver.Authenticator] configured with the given | ||
// credential and HTTP client. It returns nil if cred is nil. | ||
func NewAuthenticator(cred *options.Credential, httpClient *http.Client) (driver.Authenticator, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest repurposing this function with the goal of converting options.Credential
to auth.Cred
. And constructing the Authenticator
using the auth
package where needed. For example,
authCreds := topology.ConvertCreds(clientOpt.Auth)
client.authenticator, err = auth.CreateAuthenticator(clientOpt.Auth.AuthMechanism, authCreds, clientOpt.HTTPClient)
This way we limit the number of functions that return the Authenticator
interface, making a future refactor to correct this anti-pattern more straightforward: GODRIVER-3316
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable, will try that refactor.
|
||
// Test that convertOIDCArgs exhaustively copies all fields of a driver.OIDCArgs | ||
// into an options.OIDCArgs. | ||
func TestConvertOIDCArgs(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest parallelizing the entire test
x/mongo/driver/auth/plain_test.go
Outdated
@@ -26,6 +25,7 @@ func TestPlainAuthenticator_Fails(t *testing.T) { | |||
authenticator := PlainAuthenticator{ | |||
Username: "user", | |||
Password: "pencil", | |||
Source: "$external", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use this so much, what are your thoughts on constantizing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tradeoff is more indirection for lower typo risk. Since the source of truth is the server APIs, there is no risk of out-of-sync constants in the Go Driver. Seems like a good idea overall, will update 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, see suggestions 👍
Co-authored-by: Preston Vasquez <[email protected]>
drivers-pr-bot please backport to master |
This didn't quite work yet, I'll follow up. |
I don't think I have enough golang-foo to cherry-pick this one myself. |
…tions. (mongodb#1764) Co-authored-by: Preston Vasquez <[email protected]> Co-authored-by: Steven Silvester <[email protected]> (cherry picked from commit 18d1b19)
GODRIVER-3215
Summary
ClientOptions
to a new functiontopology.NewAuthenticator
. Use it everywhere that needs to create an authenticator fromClientOptions
.convertOIDCArgs
into thetopology
package.topology.NewConfigWithAuthenticator
, but actually has no effect currently, so no default auth sources are being set.Background & Motivation
Currently, if auth mechanism "MONGODB-AWS" is set using
ClientOptions.SetAuth
, the default auth source is set to "admin" instead of "$external". The result is a confusing error messageThere was a further regression (that hasn't been released yet) caused by #1678, which effectively skips all of the default auth source logic. Refactor the authenticator creation logic and the default auth source logic to make similar regressions more obvious.