[GODRIVER-920] Specifying a database name in URI other than admin triggers authentication Created: 02/Apr/19  Updated: 27/Oct/23  Resolved: 04/Apr/19

Status: Closed
Project: Go Driver
Component/s: Authentication
Affects Version/s: 1.0.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Wan Bachtiar Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by GODRIVER-921 with database specified in URI, drive... Closed
Related
related to GODRIVER-1021 Specify behavior where connection str... Closed

 Description   

Connecting using URI as below:

mongoURI := "mongodb://localhost:27017/test"
client, err := mongo.NewClient(options.Client().ApplyURI(mongoURI))

Generates application error:

2019/04/02 15:39:52 auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.
exit status 1

MongoDB (v4.0.8) server log error:

2019-04-02T15:39:52.728+1100 I NETWORK  [conn105] received client metadata from 127.0.0.1:54219 conn105: { driver: { name: "mongo-go-driver", version: "v1.0.0" }, os: { type: "darwin", architecture: "amd64" }, platform: "go1.11.5" }
2019-04-02T15:39:52.728+1100 I ACCESS   [conn105] Supported SASL mechanisms requested for unknown user '@test'
2019-04-02T15:39:52.728+1100 I ACCESS   [conn105] SASL SCRAM-SHA-1 authentication failed for  on test from client 127.0.0.1:54219 ; BadValue: Invalid SCRAM user name: n=

Changing the URI to any of the below works:

mongoURI := "mongodb://localhost:27017"
mongoURI := "mongodb://localhost:27017/admin"
mongoURI := "mongodb://localhost:27017/?authSource=admin"



 Comments   
Comment by David Golden [ 15/May/19 ]

For future reference, the driver specification for authentication has been amended to clarify that database name in URI alone should not trigger an authentication attempt.  The ticket for making that change is GODRIVER-1021.

Comment by David Golden [ 05/Apr/19 ]

Yes, this does affect mongodump (and other tools) after conversion to the Go driver. It appears to be uncovered in our tests.

Comment by Jeffrey Yemin [ 05/Apr/19 ]

david.golden this seems like it would be a problem for mongodump, as currently you can use the database in the URI to specify which database you want to dump:

~$ mongodump --uri mongodb://localhost/test
2019-04-05T09:20:30.841-0400	writing test.restaurants to
2019-04-05T09:20:30.844-0400	done dumping test.restaurants (1 document)

Are you working around that now by stripping the database name before passing to Go driver? Or is it a bug in waiting?

Comment by Ian Whalen (Inactive) [ 04/Apr/19 ]

wan.bachtiar the godriver is spec compliant on it's use of auth database:

https://github.com/mongodb/specifications/blob/master/source/connection-string/connection-string-spec.rst#auth-database-optional

So this is really going to be handled with a better error message in GODRIVER-870.

Comment by Wan Bachtiar [ 02/Apr/19 ]

This is related to clientoptions.go#L127, where if the authSource is not admin it's declaring opts.Auth with Credential. Later in client.go#L237, it detects that Auth is declared an go into authentication mode.

Generated at Thu Feb 08 08:35:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.