Skip to content

Commit cb6a6eb

Browse files
committed
DRIVERS-3131: No URI credentials with MONGODB-AWS
1 parent ace53b1 commit cb6a6eb

File tree

4 files changed

+43
-29
lines changed

4 files changed

+43
-29
lines changed

source/auth/auth.md

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,9 @@ Examples are provided below.
957957
958958
- AWS_SESSION_TOKEN
959959
960-
Drivers MUST allow the user to specify an AWS session token for authentication with temporary credentials.
960+
Drivers MAY allow an AWS session token for authentication with temporary credentials to exist in their API,
961+
internally, but MUST raise an error if the user provided it explicitly via the URI or client options. This property
962+
MUST NOT exist in the public API.
961963
962964
- AWS_CREDENTIAL_PROVIDER
963965
@@ -1011,11 +1013,10 @@ Drivers MAY expose API for default providers for the following scenarios when ap
10111013
10121014
The order in which Drivers MUST search for credentials is:
10131015
1014-
1. The URI
1015-
2. A custom AWS credential provider if the driver supports it.
1016-
3. Environment variables
1017-
4. Using `AssumeRoleWithWebIdentity` if `AWS_WEB_IDENTITY_TOKEN_FILE` and `AWS_ROLE_ARN` are set.
1018-
5. The ECS endpoint if `AWS_CONTAINER_CREDENTIALS_RELATIVE_URI` is set. Otherwise, the EC2 endpoint.
1016+
1. A custom AWS credential provider if the driver supports it.
1017+
2. Environment variables
1018+
3. Using `AssumeRoleWithWebIdentity` if `AWS_WEB_IDENTITY_TOKEN_FILE` and `AWS_ROLE_ARN` are set.
1019+
4. The ECS endpoint if `AWS_CONTAINER_CREDENTIALS_RELATIVE_URI` is set. Otherwise, the EC2 endpoint.
10191020
10201021
> [!NOTE]
10211022
> See *Should drivers support accessing Amazon EC2 instance metadata in Amazon ECS* in [Q & A](#q-and-a)
@@ -1025,32 +1026,16 @@ The order in which Drivers MUST search for credentials is:
10251026
> description of `AssumeRole` below, which is distinct from `AssumeRoleWithWebIdentity` requests that are meant to be
10261027
> handled directly by the driver.
10271028
1028-
##### URI
1029-
1030-
An example URI for authentication with MONGODB-AWS using AWS IAM credentials passed through the URI is as follows:
1031-
1032-
```javascript
1033-
"mongodb://<access_key>:<secret_key>@mongodb.example.com/?authMechanism=MONGODB-AWS"
1034-
```
1035-
1036-
Users MAY have obtained temporary credentials through an
1037-
[AssumeRole](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html) request. If so, then in addition
1038-
to a username and password, users MAY also provide an `AWS_SESSION_TOKEN` as a `mechanism_property`.
1039-
1040-
```javascript
1041-
"mongodb://<access_key>:<secret_key>@mongodb.example.com/?authMechanism=MONGODB-AWS&authMechanismProperties=AWS_SESSION_TOKEN:<security_token>"
1042-
```
1043-
10441029
##### Environment variables
10451030
10461031
AWS Lambda runtimes set several
10471032
[environment variables](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime)
10481033
during initialization. To support AWS Lambda runtimes Drivers MUST check a subset of these variables, i.e.,
10491034
`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_SESSION_TOKEN`, for the access key ID, secret access key and
1050-
session token, respectively if AWS credentials are not explicitly provided in the URI. The `AWS_SESSION_TOKEN` may or
1051-
may not be set. However, if `AWS_SESSION_TOKEN` is set Drivers MUST use its value as the session token. Drivers
1052-
implemented in programming languages that support altering environment variables MUST always read environment variables
1053-
dynamically during authorization, to handle the case where another part the application has refreshed the credentials.
1035+
session token, respectively. The `AWS_SESSION_TOKEN` may or may not be set. However, if `AWS_SESSION_TOKEN` is set Drivers
1036+
MUST use its value as the session token. Drivers implemented in programming languages that support altering environment
1037+
variables MUST always read environment variables dynamically during authorization, to handle the case where another part the
1038+
application has refreshed the credentials.
10541039
10551040
However, if environment variables are not present during initial authorization, credentials may be fetched from another
10561041
source and cached. Even if the environment variables are present in subsequent authorization attempts, the driver MUST
@@ -2165,6 +2150,8 @@ practice to avoid this. (See
21652150

21662151
## Changelog
21672152

2153+
- 2025-09-30: Remove credentials URI support for MONGODDB-AWS.
2154+
21682155
- 2025-09-10: Update precedence of MONGODB-AWS credential fetching behaviour.
21692156

21702157
- 2025-01-29: Add support for custom AWS credential providers.

source/auth/tests/legacy/connection-string.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/auth/tests/legacy/connection-string.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,18 @@ tests:
320320
mechanism: MONGODB-AWS
321321
mechanism_properties:
322322
AWS_SESSION_TOKEN: token!@#$%^&*()_+
323+
- description: should throw an exception if username provided (MONGODB-AWS)
324+
implies default mechanism)
325+
uri: mongodb://user:localhost.com/
326+
valid: false
327+
- description: should throw an exception if username and password provided (MONGODB-AWS)
328+
implies default mechanism)
329+
uri: mongodb://user@pass:localhost.com/
330+
valid: false
331+
- description: should throw an exception if AWS_SESSION_TOKEN provided (MONGODB-AWS)
332+
implies default mechanism)
333+
uri: mongodb://localhost/?authMechanism=MONGODB-AWS&authMechanismProperties=AWS_SESSION_TOKEN:token
334+
valid: false
323335
- description: should recognise the mechanism with test environment (MONGODB-OIDC)
324336
uri: mongodb://localhost/?authMechanism=MONGODB-OIDC&authMechanismProperties=ENVIRONMENT:test
325337
valid: true

source/auth/tests/mongodb-aws.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ Expect authentication to succeed and the custom credential provider was called.
5959

6060
## Regular credentials
6161

62-
Drivers MUST be able to authenticate by providing a valid access key id and secret access key pair as the username and
63-
password, respectively, in the MongoDB URI. An example of a valid URI would be:
62+
Drivers MUST be able to authenticate when a valid access key id and secret access key pair are present in the
63+
environment. Drivers MUST provide the --nouri option to aws_tester.py in drivers-evergreen-tools for this test.
6464

6565
```text
66-
mongodb://<AccessKeyId>:<SecretAccessKey>@localhost/?authMechanism=MONGODB-AWS
66+
mongodb://localhost/?authMechanism=MONGODB-AWS
6767
```
6868

6969
## EC2 Credentials

0 commit comments

Comments
 (0)