Skip to content

Commit abe1db2

Browse files
committed
DRIVERS-2416 Add Azure built-in integration for OIDC.
1 parent 4e12c13 commit abe1db2

File tree

1 file changed

+63
-7
lines changed

1 file changed

+63
-7
lines changed

source/auth/auth.md

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,10 +1216,17 @@ in the MONGODB-OIDC specification, including sections or blocks that specificall
12161216
- mechanism_properties
12171217

12181218
- PROVIDER_NAME\
1219-
Drivers MUST allow the user to specify the name of a built-in OIDC provider integration to use to
1220-
obtain credentials. If provided, the value MUST be one of `["aws"]`. If both `PROVIDER_NAME` and an
1221-
[OIDC Callback](#oidc-callback) or [OIDC Human Callback](#oidc-human-callback) are provided for the same
1222-
`MongoClient`, the driver MUST raise an error.
1219+
Drivers MUST allow the user to specify the name of a built-in OIDC provider integration to use
1220+
to obtain credentials. If provided, the value MUST be one of `["aws", "azure"]`. If both
1221+
`PROVIDER_NAME` and an [OIDC Callback](#oidc-callback) or [OIDC Human
1222+
Callback](#oidc-human-callback) are provided for the same `MongoClient`, the driver MUST raise
1223+
an error.
1224+
1225+
- TOKEN_AUDIENCE\
1226+
The URI of the target resource. This property is currently only used and required by the Azure
1227+
built-in OIDC provider integration. If `TOKEN_AUDIENCE` is provided and `PROVIDER_NAME` is not
1228+
`azure` or `TOKEN_AUDIENCE` is not provided and `PROVIDER_NAME` is `azure`, the driver MUST
1229+
raise an error.
12231230

12241231
- OIDC_CALLBACK\
12251232
An [OIDC Callback](#oidc-callback) that returns OIDC credentials. Drivers MAY allow the user to
@@ -1250,9 +1257,9 @@ in the MONGODB-OIDC specification, including sections or blocks that specificall
12501257

12511258
Drivers MUST support all of the following built-in OIDC providers.
12521259

1253-
####### AWS
1260+
**AWS**
12541261

1255-
The AWS provider is enabled by setting auth mechanism property `PROVIDER_NAME:aws`.
1262+
The AWS provider integration is enabled by setting auth mechanism property `PROVIDER_NAME:aws`.
12561263

12571264
If enabled, drivers MUST read the file path from environment variable `AWS_WEB_IDENTITY_TOKEN_FILE` and then read the
12581265
OIDC access token from that file. The driver MUST use the contents of that file as value in the `jwt` field of the
@@ -1261,6 +1268,53 @@ OIDC access token from that file. The driver MUST use the contents of that file
12611268
Drivers MAY implement the AWS provider so that it conforms to the function signature of the
12621269
[OIDC Callback](#oidc-callback) to prevent having to re-implement the AWS provider logic in the OIDC prose tests.
12631270

1271+
**Azure**
1272+
1273+
The Azure provider integration is enabled by setting auth mechanism property `PROVIDER_NAME:azure`.
1274+
1275+
If enabled, drivers MUST call the [Azure Instance Metadata
1276+
Service](https://learn.microsoft.com/en-us/azure/virtual-machines/instance-metadata-service) and
1277+
parse the JSON response body.
1278+
1279+
Make an HTTP GET request to
1280+
```
1281+
http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=<resource>&object_id=<object_id>
1282+
```
1283+
with headers
1284+
```
1285+
Accept: application/json
1286+
Metadata: true
1287+
```
1288+
where `<resource>` is the value of the `TOKEN_AUDIENCE` mechanism property and `<object_id>` is the
1289+
username (omit `object_id` if no username is provided).
1290+
1291+
The curl recipe below demonstrates the above, where `$TOKEN_AUDIENCE` is the value of the
1292+
`TOKEN_AUDIENCE` mechanism property.
1293+
1294+
```bash
1295+
curl -X GET \
1296+
-H "Accept: application/json" \
1297+
-H "Metadata: true" \
1298+
"http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=$TOKEN_AUDIENCE"
1299+
```
1300+
1301+
The JSON response will be in this format:
1302+
```json
1303+
{
1304+
"access_token": "eyJ0eXAi...",
1305+
"refresh_token": "",
1306+
"expires_in": "3599",
1307+
"expires_on": "1506484173",
1308+
"not_before": "1506480273",
1309+
"resource": "https://management.azure.com/",
1310+
"token_type": "Bearer"
1311+
}
1312+
```
1313+
1314+
The driver MUST use the returned `"access_token"` value as the access token in a `JwtStepRequest`.
1315+
1316+
For more details, see [How to use managed identities for Azure resources on an Azure VM to acquire an access token](https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/how-to-use-vm-token).
1317+
12641318
#### OIDC Callback
12651319

12661320
Drivers MUST allow users to provide a callback that returns an OIDC access token. The purpose of the callback is to
@@ -1572,7 +1626,7 @@ def invalidate(access_token):
15721626
Drivers that support the [Human Authentication Flow](#human-authentication-flow) MUST also cache the `IdPInfo` and
15731627
refresh token in the *Client Cache* when a [OIDC Human Callback](#oidc-human-callback) is configured.
15741628

1575-
####### Authentication
1629+
**Authentication**
15761630

15771631
Use the following algorithm to authenticate a new connection:
15781632

@@ -1919,6 +1973,8 @@ to EC2 instance metadata in ECS, for security reasons, Amazon states it's best p
19191973

19201974
## Changelog
19211975

1976+
- 2024-02-21: Added Azure built-in OIDC provider integration.
1977+
19221978
- 2024-01-31: Migrated from reStructuredText to Markdown.
19231979

19241980
- 2024-01-17: Added MONGODB-OIDC machine auth flow spec and combine with human\

0 commit comments

Comments
 (0)