Skip to content

Commit

Permalink
test: azure oidc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Jan 29, 2024
1 parent e13afba commit 24dc578
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .evergreen/prepare-shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export PATH="$MONGODB_BINARIES:$PATH"

if [ ! -d "$DRIVERS_TOOLS" ]; then
# Only clone driver tools if it does not exist
git clone --depth=1 "https://github.com/mongodb-labs/drivers-evergreen-tools.git" "${DRIVERS_TOOLS}"
git clone --depth=1 --branch DRIVERS-2416-5 "https://github.com/blink1073/drivers-evergreen-tools.git" "${DRIVERS_TOOLS}"
fi

echo "installed DRIVERS_EVERGREEN_TOOLS from commit $(git -C $DRIVERS_EVERGREEN_TOOLS rev-parse HEAD)"
Expand Down
5 changes: 2 additions & 3 deletions .evergreen/run-oidc-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ if [ "$PROVIDER_NAME" = "azure" ]; then
echo "Must specify an AZUREOIDC_CLIENTID"
exit 1
fi
MONGODB_URI="${MONGODB_URI}/?authMechanism=MONGODB-OIDC"
MONGODB_URI="mongodb://${AZUREOIDC_USERNAME}@127.0.0.1:27017/?authMechanism=MONGODB-OIDC"
MONGODB_URI="${MONGODB_URI}&authMechanismProperties=PROVIDER_NAME:azure"
MONGODB_URI="${MONGODB_URI},TOKEN_AUDIENCE:api%3A%2F%2F${AZUREOIDC_CLIENTID}"
export MONGODB_URI="${MONGODB_URI},TOKEN_CLIENT_ID:${AZUREOIDC_TOKENCLIENT}"
export MONGODB_URI="${MONGODB_URI},TOKEN_AUDIENCE:api%3A%2F%2F${AZUREOIDC_CLIENTID}"
npm run check:oidc-azure
else
echo $OIDC_ATLAS_URI_SINGLE
Expand Down
18 changes: 10 additions & 8 deletions src/cmap/auth/mongodb_oidc/azure_machine_workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MachineWorkflow } from './machine_workflow';

/** Base URL for getting Azure tokens. */
const AZURE_BASE_URL =
'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01';
'http://169.254.169.254/metadata/identity/oauth2/token?';

/** Azure request headers. */
const AZURE_HEADERS = Object.freeze({ Metadata: 'true', Accept: 'application/json' });
Expand Down Expand Up @@ -41,7 +41,7 @@ export class AzureMachineWorkflow extends MachineWorkflow {
*/
async getToken(credentials?: MongoCredentials): Promise<string> {
const tokenAudience = credentials?.mechanismProperties.TOKEN_AUDIENCE;
const tokenClientId = credentials?.mechanismProperties.TOKEN_CLIENT_ID;
const username = credentials?.username;
if (!tokenAudience) {
throw new MongoAzureError(TOKEN_AUDIENCE_MISSING_ERROR);
}
Expand All @@ -51,7 +51,7 @@ export class AzureMachineWorkflow extends MachineWorkflow {
token = entry.token;
} else {
this.cache.deleteEntry(tokenAudience);
const response = await getAzureTokenData(tokenAudience, tokenClientId);
const response = await getAzureTokenData(tokenAudience, username);
if (!isEndpointResultValid(response)) {
throw new MongoAzureError(ENDPOINT_RESULT_ERROR);
}
Expand All @@ -67,13 +67,15 @@ export class AzureMachineWorkflow extends MachineWorkflow {
*/
async function getAzureTokenData(
tokenAudience: string,
tokenClientId?: string
username?: string
): Promise<AzureAccessToken> {
let url = `${AZURE_BASE_URL}&resource=${tokenAudience}`;
if (tokenClientId) {
url += `&client_id=${tokenClientId}`;
const url = new URL(AZURE_BASE_URL);
url.searchParams.append('api-version', '2018-02-01');
url.searchParams.append('resource', tokenAudience);
if (username) {
url.searchParams.append('object_id', username);
}
const data = await request(url, {
const data = await request(url.toString(), {
json: true,
headers: AZURE_HEADERS
});
Expand Down

0 comments on commit 24dc578

Please sign in to comment.