-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: Authentication
What problem are you facing?
In testing mongosh (both manually and by adding tests) to see if AWS credentials can be loaded from the credentials file I cannot get it to work. It is my understanding that by default it should use the credentials for the default profile and that you should be able to specify a different profile using the AWS_PROFILE.
See the linked mongosh ticket as to why you would want to do this.
What driver and relevant dependency versions are you using?
mongosh 2.0.2 or just latest main, driver version 6.2.0
Steps to reproduce?
add credentials to ~/.aws/credentials file according to the sample here:
https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-credential-providers/#sample-files
then to connect with the default credentials:
~/mongo/mongosh % mongosh "mongodb+srv://mongosh.e06dc.mongodb.net/?authSource=%24external&authMechanism=MONGODB-AWS" (node:27910) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead. (Use `node --trace-deprecation ...` to show where the warning was created) Current Mongosh Log ID: 654e08c6d34a3a3912bc33b2 Connecting to: mongodb+srv://mongosh.e06dc.mongodb.net/?authSource=%24external&authMechanism=MONGODB-AWS&appName=mongosh+2.0.2 MongoAWSError: Could not obtain temporary MONGODB-AWS credentials
or with a specific profile:
~/mongo/mongosh % AWS_PROFILE=user1 mongosh "mongodb+srv://mongosh.e06dc.mongodb.net/?authSource=%24external&authMechanism=MONGODB-AWS" (node:27923) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead. (Use `node --trace-deprecation ...` to show where the warning was created) Current Mongosh Log ID: 654e08e419405ae64e7fb322 Connecting to: mongodb+srv://mongosh.e06dc.mongodb.net/?authSource=%24external&authMechanism=MONGODB-AWS&appName=mongosh+2.0.2 MongoAWSError: Could not obtain temporary MONGODB-AWS credentials
example of my ~/.aws/credentials file:
~/mongo/mongosh % cat ~/.aws/credentials
[default]
aws_access_key_id=redacted
aws_secret_access_key=redacted
[user1]
aws_access_key_id=redacted
aws_secret_access_key=redacted
[invalid]
aws_access_key_id=invalid
aws_secret_access_key=invalid
specifying the same AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY env vars connects fine:
~/mongo/mongosh % env ..blah.. AWS_ACCESS_KEY_ID=redacted AWS_SECRET_ACCESS_KEY=redacted ~/mongo/mongosh % mongosh "mongodb+srv://mongosh.e06dc.mongodb.net/?authSource=%24external&authMechanism=MONGODB-AWS" (node:27976) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead. (Use `node --trace-deprecation ...` to show where the warning was created) Current Mongosh Log ID: 654e093cb683e1d2bf23c04d Connecting to: mongodb+srv://mongosh.e06dc.mongodb.net/?authSource=%24external&authMechanism=MONGODB-AWS&appName=mongosh+2.0.2 Using MongoDB: 4.4.25 Using Mongosh: 2.0.2 For mongosh info see: https://docs.mongodb.com/mongodb-shell/ (node:27976) [DEP0174] DeprecationWarning: Calling promisify on a function that returns a Promise is likely a mistake. (node:27976) [DEP0174] DeprecationWarning: Calling promisify on a function that returns a Promise is likely a mistake. (node:27976) [DEP0174] DeprecationWarning: Calling promisify on a function that returns a Promise is likely a mistake. (node:27976) [DEP0174] DeprecationWarning: Calling promisify on a function that returns a Promise is likely a mistake. (node:27976) [DEP0174] DeprecationWarning: Calling promisify on a function that returns a Promise is likely a mistake. (node:27976) [DEP0174] DeprecationWarning: Calling promisify on a function that returns a Promise is likely a mistake. (node:27976) [DEP0174] DeprecationWarning: Calling promisify on a function that returns a Promise is likely a mistake. Atlas mongosh-shard-0 [primary] test>
The driver uses fromNodeProviderChain which from what I can tell should just work because it should read from the ini files.
- is depended on by
-
MONGOSH-1609 Add support for AWS_PROFILE when authMechanism is MONGODB-AWS
- Closed
- is related to
-
COMPASS-6478 MongoDB Atlas + AWS IAM auth mechanism: implement proper safe obtaining of key/secret/token
- Closed
-
NODE-5567 Enable configuration of AWS credentials provider
- Closed