@@ -230,16 +230,19 @@ func (c *managedIdentityClient) authenticate(ctx context.Context, id ManagedIDKi
230
230
}
231
231
return azcore.AccessToken {}, newCredentialUnavailableError (credNameManagedIdentity , msg )
232
232
}
233
- // because IMDS always responds with JSON, assume a non-JSON response is from something else, such
234
- // as a proxy, and return credentialUnavailableError so DefaultAzureCredential continues iterating
233
+ // Determine whether the response is from IMDS, a service whose managed identity API imitates IMDS such as Azure
234
+ // Container Instances (ACI), or something other than a managed identity API. Assume a JSON response is from IMDS.
235
+ // If the response is not JSON, check for a known ACI error message. If the response is neither JSON nor an ACI
236
+ // error, assume it's from something like a proxy and return credentialUnavailableError so DefaultAzureCredential
237
+ // continues to its next credential.
235
238
b , err := azruntime .Payload (res )
236
239
if err != nil {
237
240
return azcore.AccessToken {}, newCredentialUnavailableError (credNameManagedIdentity , fmt .Sprintf ("failed to read IMDS probe response: %s" , err ))
238
241
}
239
- if ! json .Valid (b ) {
242
+ if ! json .Valid (b ) && ! strings . HasPrefix ( string ( b ), "Required metadata header" ) {
240
243
return azcore.AccessToken {}, newCredentialUnavailableError (credNameManagedIdentity , "unexpected response to IMDS probe" )
241
244
}
242
- // send normal token requests from now on because IMDS responded
245
+ // send normal token requests from now on because IMDS, or something imitating it, responded
243
246
c .probeIMDS = false
244
247
}
245
248
0 commit comments