Skip to content

Commit 875446d

Browse files
authored
DRIVERS-2493 Ensure Auth Environment Variables are Always Dynamic (#1337)
1 parent d13c61d commit 875446d

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

source/auth/auth.rst

+13-2
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,16 @@ request. If so, then in addition to a username and password, users MAY also prov
984984
985985
Environment variables
986986
_____________________
987-
AWS Lambda runtimes set several `environment variables <https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime>`_ during initialization. To support AWS Lambda runtimes Drivers MUST check a subset of these variables, i.e., ``AWS_ACCESS_KEY_ID``, ``AWS_SECRET_ACCESS_KEY``, and ``AWS_SESSION_TOKEN``, for the access key ID, secret access key and session token, respectively if AWS credentials are not explicitly provided in the URI. The ``AWS_SESSION_TOKEN`` may or may not be set. However, if ``AWS_SESSION_TOKEN`` is set Drivers MUST use its value as the session token.
987+
AWS Lambda runtimes set several `environment variables <https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime>`_ during initialization. To support AWS Lambda runtimes Drivers MUST check a subset of these variables, i.e., ``AWS_ACCESS_KEY_ID``, ``AWS_SECRET_ACCESS_KEY``, and ``AWS_SESSION_TOKEN``, for the access key ID, secret access key and session token, respectively if AWS credentials are not explicitly provided in the URI. The ``AWS_SESSION_TOKEN`` may or may not be set. However, if ``AWS_SESSION_TOKEN`` is set Drivers MUST use its value as the session token. Drivers implemented
988+
in programming languages that support altering environment variables MUST always
989+
read environment variables dynamically during authorization, to handle the
990+
case where another part the application has refreshed the credentials.
991+
992+
However, if environment variables are not present during initial authorization,
993+
credentials may be fetched from another source and cached. Even if the
994+
environmnet variables are present in subsequent authorization attempts,
995+
the driver MUST use the cached credentials, or refresh them if applicable.
996+
This behavior is consistent with how the AWS SDKs behave.
988997

989998
AssumeRoleWithWebIdentity
990999
_________________________
@@ -1137,7 +1146,8 @@ be used in lieu of manual caching.
11371146
If using manual caching, the "Expiration" field MUST be stored
11381147
and used to determine when to clear the cache. Credentials are considered
11391148
valid if they are more than five minutes away from expiring; to the reduce the
1140-
chance of expiration before they are validated by the server.
1149+
chance of expiration before they are validated by the server. Credentials
1150+
that are retreived from environment variables MUST NOT be cached.
11411151

11421152
If there are no current valid cached credentials, the driver MUST initiate a
11431153
credential request. To avoid adding a bottleneck that would override the
@@ -1385,6 +1395,7 @@ Q: Should drivers support accessing Amazon EC2 instance metadata in Amazon ECS?
13851395
Changelog
13861396
=========
13871397

1398+
:2022-11-02: Require environment variables to be read dynamically.
13881399
:2022-10-28: Recommend the use of AWS SDKs where available.
13891400
:2022-10-07: Require caching of AWS credentials fetched by the driver.
13901401
:2022-10-05: Remove spec front matter and convert version history to changelog.

source/auth/tests/mongodb-aws.rst

+23-2
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ Cached Credentials
123123

124124
Drivers MUST ensure that they are testing the ability to cache credentials.
125125
Drivers will need to be able to query and override the cached credentials to
126-
verify usage. To determine whether to run the cache tests, the driver can
127-
check for the absence of the AWS_ACCESS_KEY_ID and of credentials in the URI.
126+
verify usage. To determine whether to run the cache tests, the driver can
127+
check for the absence of the AWS_ACCESS_KEY_ID environment variable and of
128+
credentials in the URI.
128129

129130
#. Clear the cache.
130131
#. Create a new client.
@@ -133,9 +134,29 @@ check for the absence of the AWS_ACCESS_KEY_ID and of credentials in the URI.
133134
minute of the current UTC time.
134135
#. Create a new client.
135136
#. Ensure that a ``find`` operation updates the credentials in the cache.
137+
136138
#. Poison the cache with an invalid access key id.
137139
#. Create a new client.
138140
#. Ensure that a ``find`` operation results in an error.
139141
#. Ensure that the cache has been cleared.
140142
#. Ensure that a subsequent ``find`` operation succeeds.
141143
#. Ensure that the cache has been set.
144+
145+
If the drivers's language supports dynamically setting environment variables,
146+
add the following tests. Note that if integration tests are run in
147+
parallel for the driver, then these tests must be run as unit tests interacting
148+
with the auth provider directly instead of using a client.
149+
150+
#. Create a new client.
151+
#. Ensure that a ``find`` operation adds credentials to the cache.
152+
#. Set the AWS environment variables based on the cached credentials.
153+
#. Clear the cache.
154+
#. Ensure that a ``find`` operation succeeds and does not add credentials to
155+
the cache.
156+
#. Set the AWS environment variables to invalid values.
157+
#. Ensure that a ``find`` operation results in an error.
158+
159+
#. Create a new client.
160+
#. Ensure that a ``find`` operation adds credentials to the cache.
161+
#. Set the AWS environment variables to invalid values.
162+
#. Ensure that a ``find`` operation succeeds.

0 commit comments

Comments
 (0)