Question

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

You are developing a C# ASP.NET Core web application hosted on an Azure App Service. The App Service is already configured with a system-assigned managed identity to access an Azure SQL Database. You need to configure the App Service to access secrets in an Azure Key Vault. The Key Vault uses Azure Role-Based Access Control (Azure RBAC) for its data plane authorization. To minimize the security blast radius, you must use a user-assigned managed identity for Key Vault access. You must implement the solution using the Azure.Identity SDK and the DefaultAzureCredential class without modifying the initialization parameters of DefaultAzureCredential in your application code. Which sequence of steps should you perform to successfully retrieve the secrets?

  1. 1Run the `az identity create` command to provision the user-assigned managed identity and output its client ID and principal ID.
  2. 2Run the `az role assignment create` command to assign the 'Key Vault Secrets User' role to the identity's principal ID at the Key Vault scope.
  3. 3Run the `az webapp identity assign` command to associate the newly created user-assigned managed identity with the Azure App Service.
  4. 4Run the `az webapp config appsettings set` command to add the `AZURE_CLIENT_ID` app setting, setting its value to the client ID of the user-assigned managed identity.
  5. 5Deploy the ASP.NET Core application code that instantiates the `SecretClient` using `new DefaultAzureCredential()`.

Answer

The correct sequence of steps starts with creating the user-assigned managed identity, followed by assigning the Key Vault Secrets User RBAC role to the identity, associating the identity with the App Service, configuring the AZURE_CLIENT_ID app setting with the identity's client ID, and finally deploying the application code that instantiates the SecretClient using DefaultAzureCredential.
The correct sequence ensures that the user-assigned managed identity is first created to obtain its Client ID and Principal ID. Then, the identity is granted the Key Vault Secrets User role on the Key Vault. Next, the identity is linked to the App Service. After linking, the AZURE_CLIENT_ID app setting must be configured on the App Service to ensure that DefaultAzureCredential selects the user-assigned identity instead of the system-assigned identity. Finally, the application code is deployed, using DefaultAzureCredential to retrieve the secrets.

Step-by-Step Solution

1
Provision the user-assigned managed identity.
A Microsoft Entra ID security principal is created, returning a unique Client ID and Principal ID.
The identity must exist before any configuration or permission assignment can refer to it.
2
Assign the Key Vault Secrets User RBAC role to the identity.
The identity is authorized to read secrets from the Key Vault.
Since the Key Vault uses Azure RBAC, the identity requires data plane permissions before code execution.
3
Associate the identity with the App Service.
The App Service is configured to host the user-assigned managed identity.
This allows the App Service's identity endpoint to authenticate requests on behalf of this identity.
4
Configure the AZURE_CLIENT_ID app setting.
The AZURE_CLIENT_ID environment variable is populated on the host container.
Since the App Service has both system-assigned and user-assigned identities, DefaultAzureCredential requires the AZURE_CLIENT_ID environment variable to select the correct user-assigned identity.
5
Instantiate SecretClient with DefaultAzureCredential and deploy the code.
The application successfully authenticates and retrieves the secrets.
The code relies on all previous configuration steps to successfully acquire a token and query the Key Vault.

Key Concept

Configuring user-assigned managed identities alongside system-assigned managed identities using DefaultAzureCredential and Azure RBAC in Azure App Service.
Estimated Time:3m 0s
Rate this question