Question

Difficulty: Very hardSystem-Assigned and User-Assigned Managed Identities

You are developing a C# ASP.NET Core web application deployed to Azure App Service. The application is deployed as two regional instances: app-us-east and app-us-west. Both instances must retrieve shared secrets from a central Azure Key Vault named kv-shared. Additionally, app-us-east must write data to a regional Azure Storage account named sa-east-logs, while app-us-west must write data to sa-west-logs. To configure the managed identities, you perform the following steps:

1. Create a single user-assigned managed identity named uami-shared and assign it to both App Services, granting it Get and List secrets permissions on kv-shared.
2. Enable a system-assigned managed identity on both app-us-east and app-us-west, and grant each regional identity Contributor access to its corresponding regional storage account (sa-east-logs or sa-west-logs).

In your C# code, you instantiate the SDK clients as follows:

csharp
// Accessing the shared Key Vault
var kvClient = new SecretClient(
new Uri("https://kv-shared.vault.azure.net/"),
new DefaultAzureCredential()
);

// Accessing the regional storage account
var blobClient = new BlobServiceClient(
new Uri("https://sa-east-logs.blob.core.windows.net/"),
new DefaultAzureCredential()
);

What is the authentication outcome when the app-us-east instance attempts to run this code and connect to both services?

  1. A
    The application fails to connect to both resources because Azure App Service does not support configuring both a system-assigned managed identity and a user-assigned managed identity on the same resource instance simultaneously.
  2. The application successfully connects to the regional storage account, but fails to authenticate to the shared Key Vault because DefaultAzureCredential defaults to the system-assigned managed identity when both identity types are enabled, causing token requests without a specified client ID to use the system-assigned identity.Answer
  3. C
    The application successfully connects to both the shared Key Vault and the regional storage account because DefaultAzureCredential automatically queries the Azure Instance Metadata Service to retrieve and attempt tokens for all assigned identities until one succeeds.
  4. D
    The application successfully connects to the shared Key Vault, but fails to authenticate to the regional storage account because user-assigned managed identities take precedence in the DefaultAzureCredential resolution order.

Answer

The application successfully connects to the regional storage account, but fails to authenticate to the shared Key Vault because DefaultAzureCredential defaults to the system-assigned managed identity when both identity types are enabled, causing token requests without a specified client ID to use the system-assigned identity.
The correct option is correct because when an Azure App Service has both a system-assigned managed identity and a user-assigned managed identity, the metadata service defaults to issuing tokens for the system-assigned managed identity. Because DefaultAzureCredential is initialized without parameters, it requests a default token, which will represent the system-assigned identity. Consequently, the call to the regional storage account succeeds (authorized for the system-assigned identity), while the call to the shared Key Vault fails (authorized only for the user-assigned identity). To fix this, DefaultAzureCredential must be configured with DefaultAzureCredentialOptions specifying the ManagedIdentityClientId for the user-assigned identity.

Step-by-Step Solution

1
Determine the identities assigned to the App Service host.
The host app-us-east has both a system-assigned managed identity (with permissions to sa-east-logs) and a user-assigned managed identity (uami-shared with permissions to kv-shared).
This establishes the authorization scope for each identity type on the resource.
2
Analyze how DefaultAzureCredential resolves tokens when multiple managed identities are present.
Without specifying a client ID, DefaultAzureCredential calls the IMDS token endpoint without parameters, which causes Azure to default to using the system-assigned managed identity.
This identifies which security principal's token is returned during execution.
3
Evaluate the authentication outcome for each service request.
The token for the system-assigned identity successfully accesses sa-east-logs (due to Contributor RBAC) but fails to access kv-shared (as only uami-shared has permissions there).
This determines the final success/failure behavior of the C# code.

Key Concept

Understanding the default resolution behavior of DefaultAzureCredential and the Azure Instance Metadata Service (IMDS) when both system-assigned and user-assigned managed identities are assigned to a single resource.
Rate this question