Skip to content

[BUG] DefaultAzureCredential throws exception when ManagedIdentityCredential failed #45808

@Yao725

Description

@Yao725

Library name and version

Azure.Identity 1.13.0-beta.1

Describe the bug

When upgrading the package from 1.12.0 to 1.13.0-beta.1, if DefaultAzureCredential is used and the ManagedIdentityCredential failed, the exception will be directly thrown instead of trying using next credential type.

Expected behavior

This exception can be well handled and the auth should finally succeed just like Azure.Identity 1.12.0.

Actual behavior

Below exception is thrown.

System.AggregateException: One or more errors occurred. ---> Azure.Identity.AuthenticationFailedException: ManagedIdentityCredential authentication failed: [Managed Identity] Authentication unavailable. Either the requested identity has not been assigned to this resource, or other errors could be present. Ensure the identity is correctly assigned and check the inner exception for more details. For more information, visit https://aka.ms/msal-managed-identity.
Status: BadRequest
Content:
{"error":"invalid_request","error_description":"Identity not found"}

Headers:
Date: Thu, 05 Sep 2024 04:25:15 GMT
Server: IMDS/150.870.65.1391

[Managed Identity] Error Code: invalid_request Error Description: Identity not found 
See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/managedidentitycredential/troubleshoot ---> Microsoft.Identity.Client.MsalServiceException: [Managed Identity] Authentication unavailable. Either the requested identity has not been assigned to this resource, or other errors could be present. Ensure the identity is correctly assigned and check the inner exception for more details. For more information, visit https://aka.ms/msal-managed-identity.
Status: BadRequest
Content:
{"error":"invalid_request","error_description":"Identity not found"}

Headers:
Date: Thu, 05 Sep 2024 04:25:15 GMT
Server: IMDS/150.870.65.1391

[Managed Identity] Error Code: invalid_request Error Description: Identity not found

Reproduction Steps

Use Azure.Identity 1.13.0-beta.1 and DefaultAzureCredential
Sample code:

var credential = new DefaultAzureCredential();
var secretClient = new SecretClient(new Uri(keyVaultUri), credential);

Environment

OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows

Metadata

Metadata

Assignees

Labels

Azure.IdentityClientThis issue is related to a non-management packageneeds-author-feedbackWorkflow: More information is needed from author to address the issue.no-recent-activityThere has been no recent activity on this issue.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions