An enterprise ASP.NET Core application is hosted on an Azure Virtual Machine. The virtual machine has been assigned two user-assigned managed identities: IdentityA (authorized to read secrets from Azure Key Vault) and IdentityB (authorized to write to Azure Storage). To retrieve secrets, the application uses the following C# code:
csharp
var client = new SecretClient(
new Uri("https://myvault.vault.azure.net/"),
new DefaultAzureCredential()
);
When execution occurs on the virtual machine, authentication fails with a CredentialUnavailableException.
Which action must you perform to resolve the authentication failure?
- Configure the DefaultAzureCredential to target IdentityA by passing DefaultAzureCredentialOptions with the ManagedIdentityClientId property set to the client ID of IdentityA.Cevap
- BEnable the system-assigned managed identity on the virtual machine and assign it the same permissions as IdentityA, since DefaultAzureCredential does not support user-assigned managed identities.
- CAssign the 'Key Vault Secrets User' RBAC role to the virtual machine's resource ID instead of the managed identity, because Key Vault access policies do not support user-assigned identities.
- DUpdate the virtual machine's identity block in the Resource Manager template to set the identityType property to systemAssignedUserAssigned to allow automatic resolution.
Cevap
Configure the DefaultAzureCredential to target IdentityA by passing DefaultAzureCredentialOptions with the ManagedIdentityClientId property set to the client ID of IdentityA.
The correct action is to configure the DefaultAzureCredential to target IdentityA by passing DefaultAzureCredentialOptions with the ManagedIdentityClientId property set to the client ID of IdentityA. When multiple user-assigned managed identities are assigned to a single Azure resource, the IMDS endpoint requires the client ID to resolve the ambiguity and issue the correct token.
Adım Adım Çözüm
Anahtar Kavram
Handling multiple user-assigned managed identities with DefaultAzureCredential in the Azure SDK