Skip to content

Commit fa9a05a

Browse files
authored
DRIVERS-2878 OIDC Atlas Testing Updates (#1558)
1 parent bbb335e commit fa9a05a

File tree

2 files changed

+46
-68
lines changed

2 files changed

+46
-68
lines changed

source/auth/auth.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,8 +1220,8 @@ in the MONGODB-OIDC specification, including sections or blocks that specificall
12201220

12211221
- TOKEN_RESOURCE\
12221222
The URI of the target resource. This property is currently only used and required by the Azure
1223-
built-in OIDC provider integration. If `TOKEN_RESOURCE` is provided and `PROVIDER_NAME` is not `azure` or
1224-
`TOKEN_RESOURCE` is not provided and `PROVIDER_NAME` is `azure`, the driver MUST raise an error.
1223+
built-in OIDC provider integration. If `TOKEN_RESOURCE` is provided and `ENVIRONMENT` is not `azure` or
1224+
`TOKEN_RESOURCE` is not provided and `ENVIRONMENT` is `azure`, the driver MUST raise an error.
12251225

12261226
- OIDC_CALLBACK\
12271227
An [OIDC Callback](#oidc-callback) that returns OIDC credentials. Drivers MAY allow the user to
@@ -1988,6 +1988,8 @@ to EC2 instance metadata in ECS, for security reasons, Amazon states it's best p
19881988

19891989
## Changelog
19901990

1991+
- 2024-03-29: Updated OIDC test setup and descriptions.
1992+
19911993
- 2024-03-21: Added Azure built-in OIDC provider integration.
19921994

19931995
- 2024-03-09: Rename OIDC integration name and values.

source/auth/tests/mongodb-oidc.md

Lines changed: 42 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,9 @@
22

33
## Local Testing
44

5-
To test locally, use the
6-
[oidc_get_tokens.sh](https://github.com/mongodb-labs/drivers-evergreen-tools/blob/master/.evergreen/auth_oidc/oidc_get_tokens.sh)
7-
script from [drivers-evergreen-tools](https://github.com/mongodb-labs/drivers-evergreen-tools/) to download a set of
8-
OIDC tokens, including `test_user1` and `test_user1_expires`. You first have to install the AWS CLI and login using the
9-
SSO flow.
10-
11-
For example, if the selected AWS profile ID is "drivers-test", run:
12-
13-
```shell
14-
aws configure sso
15-
export OIDC_TOKEN_DIR=/tmp/tokens
16-
AWS_PROFILE="drivers-test" oidc_get_tokens.sh
17-
OIDC_TOKEN_FILE="$OIDC_TOKEN_DIR/test_user1" /my/test/command
18-
```
5+
See the detailed instructions in
6+
[drivers-evergreen-tools](https://github.com/mongodb-labs/drivers-evergreen-tools/blob/master/.evergreen/auth_oidc/README.md)
7+
for how to set up your environment for OIDC testing.
198

209
______________________________________________________________________
2110

@@ -36,25 +25,25 @@ Drivers MUST run the prose tests in all supported OIDC environments.
3625
> For test cases that create fail points, drivers MUST either use a unique `appName` or explicitly remove the fail point
3726
> callback to prevent interaction between test cases.
3827
39-
Note that typically the preconfigured Atlas Dev clusters are used for testing, in Evergreen and locally. The URIs can be
40-
fetched from the `drivers/oidc` Secrets vault, see
41-
[vault instructions](https://wiki.corp.mongodb.com/display/DRIVERS/Using+AWS+Secrets+Manager+to+Store+Testing+Secrets).
42-
Use `OIDC_ATLAS_URI_SINGLE` for the `MONGODB_URI`. If using local servers is preferred, using the
43-
[Local Testing](https://github.com/mongodb-labs/drivers-evergreen-tools/blob/master/.evergreen/auth_oidc/README.md#local-testing)
44-
method, use `mongodb://localhost/?authMechanism=MONGODB-OIDC` for `MONGODB_URI`.
28+
After setting up your OIDC
29+
[environment](https://github.com/mongodb-labs/drivers-evergreen-tools/blob/master/.evergreen/auth_oidc/README.md),
30+
source the `secrets-export.sh` file and use the associated env variables in your tests.
31+
32+
An OIDC configured client MUST set the appropriate `ENVIRONMENT` auth mechanism property and include a callback that
33+
gets the appropriate token for the given environment.
4534

4635
### Callback Authentication
4736

4837
**1.1 Callback is called during authentication**
4938

50-
- Create a `MongoClient` configured with an OIDC callback that implements the `ENVIRONMENT:test` logic.
39+
- Create an OIDC configured client.
5140
- Perform a `find` operation that succeeds.
5241
- Assert that the callback was called 1 time.
5342
- Close the client.
5443

5544
**1.2 Callback is called once for multiple connections**
5645

57-
- Create a `MongoClient` configured with an OIDC callback that implements the `ENVIRONMENT:test` logic.
46+
- Create an OIDC configured client.
5847
- Start 10 threads and run 100 `find` operations in each thread that all succeed.
5948
- Assert that the callback was called 1 time.
6049
- Close the client.
@@ -63,49 +52,49 @@ method, use `mongodb://localhost/?authMechanism=MONGODB-OIDC` for `MONGODB_URI`.
6352

6453
**2.1 Valid Callback Inputs**
6554

66-
- Create a `MongoClient` configured with an OIDC callback that validates its inputs and returns a valid access token.
55+
- Create an OIDC configured client with an OIDC callback that validates its inputs and returns a valid access token.
6756
- Perform a `find` operation that succeeds.
6857
- Assert that the OIDC callback was called with the appropriate inputs, including the timeout parameter if possible.
6958
- Close the client.
7059

7160
**2.2 OIDC Callback Returns Null**
7261

73-
- Create a `MongoClient` configured with an OIDC callback that returns `null`.
62+
- Create an OIDC configured client with an OIDC callback that returns `null`.
7463
- Perform a `find` operation that fails.
7564
- Close the client.
7665

7766
**2.3 OIDC Callback Returns Missing Data**
7867

79-
- Create a `MongoClient` configured with an OIDC callback that returns data not conforming to the `OIDCCredential` with
68+
- Create an OIDC configured client with an OIDC callback that returns data not conforming to the `OIDCCredential` with
8069
missing fields.
8170
- Perform a `find` operation that fails.
8271
- Close the client.
8372

8473
**2.4 Invalid Client Configuration with Callback**
8574

86-
- Create a `MongoClient` configured with an OIDC callback and auth mechanism property `ENVIRONMENT:test`.
75+
- Create an OIDC configured client with an OIDC callback and auth mechanism property `ENVIRONMENT:test`.
8776
- Assert it returns a client configuration error.
8877

8978
### (3) Authentication Failure
9079

9180
**3.1 Authentication failure with cached tokens fetch a new token and retry auth**
9281

93-
- Create a `MongoClient` configured with an OIDC callback that implements the `ENVIRONMENT:test` logic.
82+
- Create an OIDC configured client.
9483
- Poison the *Client Cache* with an invalid access token.
9584
- Perform a `find` operation that succeeds.
9685
- Assert that the callback was called 1 time.
9786
- Close the client.
9887

9988
**3.2 Authentication failures without cached tokens return an error**
10089

101-
- Create a `MongoClient` configured with an OIDC callback that always returns invalid access tokens.
90+
- Create an OIDC configured client with an OIDC callback that always returns invalid access tokens.
10291
- Perform a `find` operation that fails.
10392
- Assert that the callback was called 1 time.
10493
- Close the client.
10594

10695
### (4) Reauthentication
10796

108-
- Create a `MongoClient` configured with an OIDC callback that implements the `ENVIRONMENT:test` logic.
97+
- Create an OIDC configured client.
10998
- Set a fail point for `find` commands of the form:
11099

111100
```javascript
@@ -130,18 +119,18 @@ method, use `mongodb://localhost/?authMechanism=MONGODB-OIDC` for `MONGODB_URI`.
130119
## (5) Azure Tests
131120

132121
Drivers MUST only run the Azure tests when testing on an Azure VM. See instructions in
133-
[Drivers Evergreen Tools](https://github.com/mongodb-labs/drivers-evergreen-tools/tree/master/.evergreen/auth_oidc/azure#azure-oidc-testing)
122+
[Drivers Evergreen Tools](https://github.com/mongodb-labs/drivers-evergreen-tools/blob/master/.evergreen/auth_oidc/azure/README.md)
134123
for test setup.
135124

136125
# 5.1 Azure With No Username
137126

138-
- Create a `MongoClient` configured with `ENVIRONMENT:Azure` and a valid `TOKEN_RESOURCE` and no username.
127+
- Create an OIDC configured client with `ENVIRONMENT:azure` and a valid `TOKEN_RESOURCE` and no username.
139128
- Perform a `find` operation that succeeds.
140129
- Close the client.
141130

142131
# 5.2 Azure with Bad Usernam
143132

144-
- Create a `MongoClient` configured with `ENVIRONMENT:Azure` and a valid `TOKEN_RESOURCE` and a username of `"bad"`.
133+
- Create an OIDC configured client with `ENVIRONMENT:azure` and a valid `TOKEN_RESOURCE` and a username of `"bad"`.
145134
- Perform a `find` operation that fails.
146135
- Close the client.
147136

@@ -152,71 +141,58 @@ ______________________________________________________________________
152141
Drivers that support the [Human Authentication Flow](../auth.md#human-authentication-flow) MUST implement all prose
153142
tests in this section. Unless otherwise noted, all `MongoClient` instances MUST be configured with `retryReads=false`.
154143

155-
The human workflow tests MUST only be run when testing in the default environment described beflow.
144+
The human workflow tests MUST only be run when in `ENVIRONMENT:test`.
156145

157146
> [!NOTE]
158147
> For test cases that create fail points, drivers MUST either use a unique `appName` or explicitly remove the fail point
159148
> after the test to prevent interaction between test cases.
160149
161150
Drivers MUST be able to authenticate against a server configured with either one or two configured identity providers.
162151

163-
Note that typically the preconfigured Atlas Dev clusters are used for testing, in Evergreen and locally. The URIs can be
164-
fetched from the `drivers/oidc` Secrets vault, see
165-
[vault instructions](https://wiki.corp.mongodb.com/display/DRIVERS/Using+AWS+Secrets+Manager+to+Store+Testing+Secrets).
166-
Use `OIDC_ATLAS_URI_SINGLE` for `MONGODB_URI_SINGLE` and `OIDC_ATLAS_URI_MULTI` for `MONGODB_URI_MULTI`. Currently the
167-
`OIDC_ATLAS_URI_MULTI` cluster does not work correctly with fail points, so all prose tests that use fail points SHOULD
168-
use `OIDC_ATLAS_URI_SINGLE`.
152+
Unless otherwise specified, use `MONGODB_URI_SINGLE` and the `test_user1` token in the `OIDC_TOKEN_DIR` as the
153+
"access_token", and a dummy "refresh_token" for all tests.
169154

170-
If using local servers is preferred, using the
171-
[Local Testing](https://github.com/mongodb-labs/drivers-evergreen-tools/blob/master/.evergreen/auth_oidc/README.md#local-testing)
172-
method, use `mongodb://localhost/?authMechanism=MONGODB-OIDC` for `MONGODB_URI_SINGLE` and
173-
`mongodb://localhost:27018/?authMechanism=MONGODB-OIDC&directConnection=true&readPreference=secondaryPreferred` for
174-
`MONGODB_URI_MULTI` because the other server is a secondary on a replica set, on port `27018`.
175-
176-
The default OIDC client used in the tests is configured with `MONGODB_URI_SINGLE` and a valid human callback handler
177-
that returns the `test_user1` local token in `OIDC_TOKEN_DIR` as the "access_token", and a dummy "refresh_token".
155+
When using an explicit username for the client, we use the token name and the domain name given by `OIDC_DOMAIN`, e.g.
156+
`test_user1@${OIDC_DOMAIN}`.
178157

179158
### (1) OIDC Human Callback Authentication
180159

181160
Drivers MUST be able to authenticate using OIDC callback(s) when there is one principal configured.
182161

183162
**1.1 Single Principal Implicit Username**
184163

185-
- Create default OIDC client with `authMechanism=MONGODB-OIDC`.
164+
- Create an OIDC configured client.
186165
- Perform a `find` operation that succeeds.
187166
- Close the client.
188167

189168
**1.2 Single Principal Explicit Username**
190169

191-
- Create a client with `MONGODB_URI_SINGLE`, a username of `test_user1`, `authMechanism=MONGODB-OIDC`, and the OIDC
192-
human callback.
170+
- Create an OIDC configured client with `MONGODB_URI_SINGLE` and a username of `test_user1@${OIDC_DOMAIN}`.
193171
- Perform a `find` operation that succeeds.
194172
- Close the client.
195173

196174
**1.3 Multiple Principal User 1**
197175

198-
- Create a client with `MONGODB_URI_MULTI`, a username of `test_user1`, `authMechanism=MONGODB-OIDC`, and the OIDC human
199-
callback.
176+
- Create an OIDC configured client with `MONGODB_URI_MULTI` and username of `test_user1@${OIDC_DOMAIN}`.
200177
- Perform a `find` operation that succeeds.
201178
- Close the client.
202179

203180
**1.4 Multiple Principal User 2**
204181

205-
- Create a human callback that reads in the generated `test_user2` token file.
206-
- Create a client with `MONGODB_URI_MULTI`, a username of `test_user2`, `authMechanism=MONGODB-OIDC`, and the OIDC human
207-
callback.
182+
- Create an OIDC configured client with `MONGODB_URI_MULTI` and username of `test_user2@${OIDC_DOMAIN}`. that reads the
183+
`test_user2` token file.
208184
- Perform a `find` operation that succeeds.
209185
- Close the client.
210186

211187
**1.5 Multiple Principal No User**
212188

213-
- Create a client with `MONGODB_URI_MULTI`, no username, `authMechanism=MONGODB-OIDC`, and the OIDC human callback.
189+
- Create an OIDC configured client with `MONGODB_URI_MULTI` and no username.
214190
- Assert that a `find` operation fails.
215191
- Close the client.
216192

217193
**1.6 Allowed Hosts Blocked**
218194

219-
- Create a default OIDC client, with an `ALLOWED_HOSTS` that is an empty list.
195+
- Create an OIDC configured client with an `ALLOWED_HOSTS` that is an empty list.
220196
- Assert that a `find` operation fails with a client-side error.
221197
- Close the client.
222198
- Create a client that uses the URL `mongodb://localhost/?authMechanism=MONGODB-OIDC&ignored=example.com`, a human
@@ -228,23 +204,23 @@ Drivers MUST be able to authenticate using OIDC callback(s) when there is one pr
228204

229205
**2.1 Valid Callback Inputs**
230206

231-
- Create a `MongoClient` with a human callback that validates its inputs and returns a valid access token.
207+
- Create an OIDC configured client with a human callback that validates its inputs and returns a valid access token.
232208
- Perform a `find` operation that succeeds. Verify that the human callback was called with the appropriate inputs,
233209
including the timeout parameter if possible.
234210
- Close the client.
235211

236212
**2.3 Human Callback Returns Missing Data**
237213

238-
- Create a `MongoClient` with a human callback that returns data not conforming to the `OIDCCredential` with missing
239-
fields.
214+
- Create an OIDC configured client with a human callback that returns data not conforming to the `OIDCCredential` with
215+
missing fields.
240216
- Perform a `find` operation that fails.
241217
- Close the client.
242218

243219
### (3) Speculative Authentication
244220

245221
**3.1 Uses speculative authentication if there is a cached token**
246222

247-
- Create a `MongoClient` with a human callback that returns a valid token.
223+
- Create an OIDC configured client with a human callback that returns a valid token.
248224
- Set a fail point for `find` commands of the form:
249225

250226
```javascript
@@ -283,7 +259,7 @@ Drivers MUST be able to authenticate using OIDC callback(s) when there is one pr
283259

284260
**3.2 Does not use speculative authentication if there is no cached token**
285261

286-
- Create a `MongoClient` with a human callback that returns a valid token.
262+
- Create an OIDC configured client with a human callback that returns a valid token.
287263
- Set a fail point for `saslStart` commands of the form:
288264

289265
```javascript
@@ -306,7 +282,7 @@ Drivers MUST be able to authenticate using OIDC callback(s) when there is one pr
306282

307283
**4.1 Succeeds**
308284

309-
- Create a default OIDC client and add an event listener. The following assumes that the driver does not emit
285+
- Create an OIDC configured client and add an event listener. The following assumes that the driver does not emit
310286
`saslStart` or `saslContinue` events. If the driver does emit those events, ignore/filter them for the purposes of
311287
this test.
312288
- Perform a `find` operation that succeeds.
@@ -339,7 +315,7 @@ Drivers MUST be able to authenticate using OIDC callback(s) when there is one pr
339315

340316
**4.2 Succeeds no refresh**
341317

342-
- Create a default OIDC client with a human callback that does not return a refresh token.
318+
- Create an OIDC configured client with a human callback that does not return a refresh token.
343319
- Perform a `find` operation that succeeds.
344320
- Assert that the human callback has been called once.
345321
- Force a reauthenication using a fail point of the form:
@@ -365,7 +341,7 @@ Drivers MUST be able to authenticate using OIDC callback(s) when there is one pr
365341

366342
**4.3 Succeeds after refresh fails**
367343

368-
- Create a default OIDC client.
344+
- Create an OIDC configured client.
369345
- Perform a `find` operation that succeeds.
370346
- Assert that the human callback has been called once.
371347
- Force a reauthenication using a fail point of the form:
@@ -391,7 +367,7 @@ Drivers MUST be able to authenticate using OIDC callback(s) when there is one pr
391367

392368
**4.4 Fails**
393369

394-
- Create a default OIDC client.
370+
- Create an OIDC configured client.
395371
- Perform a find operation that succeeds (to force a speculative auth).
396372
- Assert that the human callback has been called once.
397373
- Force a reauthenication using a failCommand of the form:

0 commit comments

Comments
 (0)