File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -340,8 +340,17 @@ _azure_getaccess_token() {
340
340
341
341
if [ " $managedIdentity " = true ]; then
342
342
# https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/how-to-use-vm-token#get-a-token-using-http
343
- export _H1=" Metadata: true"
344
- response=" $( _get http://169.254.169.254/metadata/identity/oauth2/token\? api-version=2018-02-01\& resource=https://management.azure.com/) "
343
+ if [ -n " $IDENTITY_ENDPOINT " ]; then
344
+ # Some Azure environments may set IDENTITY_ENDPOINT (formerly MSI_ENDPOINT) to have an alternative metadata endpoint
345
+ url=" $IDENTITY_ENDPOINT ?api-version=2019-08-01&resource=https://management.azure.com/"
346
+ headers=" X-IDENTITY-HEADER: $IDENTITY_HEADER "
347
+ else
348
+ url=" http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/"
349
+ headers=" Metadata: true"
350
+ fi
351
+
352
+ export _H1=" $headers "
353
+ response=" $( _get " $url " ) "
345
354
response=" $( echo " $response " | _normalizeJson) "
346
355
accesstoken=$( echo " $response " | _egrep_o " \" access_token\" :\" [^\" ]*\" " | _head_n 1 | cut -d : -f 2 | tr -d \" )
347
356
expires_on=$( echo " $response " | _egrep_o " \" expires_on\" :\" [^\" ]*\" " | _head_n 1 | cut -d : -f 2 | tr -d \" )
You can’t perform that action at this time.
0 commit comments