You are deploying an Azure Container App named `payment-processor` that needs to securely access a database connection string stored in an Azure Key Vault named `kv-vault`.
You want the Container App to authenticate to the Key Vault using a system-assigned managed identity and expose the secret to the application container as an environment variable named `DB_CONNECTION`.
Which four actions should you perform in sequence? To answer, move the appropriate actions from the list of actions to the answer area and arrange them in the correct order.
- 1Enable a system-assigned managed identity on the `payment-processor` Container App.
- 2In the Azure Key Vault `kv-vault`, assign the Key Vault Secrets User role to the Container App's managed identity principal.
- 3Add a secret named `db-secret` to the Container App that references the Azure Key Vault secret URI.
- 4Update the container configuration of the Container App to map the environment variable `DB_CONNECTION` to the `db-secret` secret.
Answer
First, enable a system-assigned managed identity on the `payment-processor` Container App. Second, in the Azure Key Vault `kv-vault`, assign the Key Vault Secrets User role to the Container App's managed identity principal. Third, add a secret named `db-secret` to the Container App that references the Azure Key Vault secret URI. Fourth, update the container configuration of the Container App to map the environment variable `DB_CONNECTION` to the `db-secret` secret.
To secure secrets in an Azure Container App using Key Vault, the application must first have an identity. Enabling the system-assigned managed identity creates a principal in Microsoft Entra ID. Next, this identity must be granted the Key Vault Secrets User role so that the Container App is authorized to read the secret. Once authorized, the secret is mapped at the Container App resource level using the Key Vault secret URI. Finally, the container template within the Container App references this App-level secret to expose it as an environment variable to the application code.
Step-by-Step Solution
Key Concept
Configuring Key Vault Secret References in Azure Container Apps using Managed Identities
Alternative Method
You can also perform this configuration using a Bicep template by defining the identity block, setting up the Microsoft.Authorization/roleAssignments resource, defining the secrets array in the container app resource, and referencing the secret in the env block of the container definition.
Estimated Time:2m 0s