A containerized API on App Service reads its database password from the DB_PASSWORD environment variable. Security wants the password kept in Key Vault, with no code change. What do you configure?
- Exam domain
- Develop containerized solutions on Azure20–25% of the exam
- Difficulty
- Medium
- In this mock
- 14 questions on this domainPractise this domain
Why the exam asks this
Develop containerized solutions on Azure: Implement container application hosting.
Objective in the exam guide: Deploy containers to Azure App Service, including configuring App Service to supply environment variables and secrets.
Moving secrets out of configuration without touching code is a very common task. The exam checks the exact App Service mechanism.
Why B is the answer
An app setting DB_PASSWORD whose value is @Microsoft.KeyVault(SecretUri=...), and a managed identity with access to the vault
App settings reach the container as environment variables, and a Key Vault reference as the value makes App Service fetch the secret with the app's identity. The code still reads DB_PASSWORD.
Remember: Secrets as env vars without code changes: Key Vault reference in an app setting.
How it works
App Service passes app settings to a custom container as environment variables.
When an app setting's value is a Key Vault reference, App Service resolves it with the app's managed identity and the code sees the secret value.
Mark such settings as slot settings when each environment has its own vault.
Clues in the question
The words that point to the answer, and what each one tells you.
- Reads from an environment variable
- App settings supply it.
- Kept in Key Vault, no code change
- Key Vault reference.
In detail
- The reference form is @Microsoft.KeyVault(SecretUri=...) or @Microsoft.KeyVault(VaultName=...;SecretName=...).
- If the reference cannot resolve, the app sees the literal reference string; check the status in the portal.
Side by side with look-alikes
| Option | Secret location | Code change? |
|---|---|---|
| Key Vault reference in app setting | Key Vault | No |
| ENV in Dockerfile | Image layers | No, but leaked |
| Plain app setting | App settings | No, less protected |
Every option, checked
Knowing why each wrong option fails is how you rule it out on exam day.
A. An Azure Policy that blocks plain-text passwordsWrong
A policy can audit resources but does not supply the secret.
B. An app setting DB_PASSWORD whose value is @Microsoft.KeyVault(SecretUri=...), and a managed identity with access to the vaultRight
Secrets as env vars without code changes: Key Vault reference in an app setting.
C. The password written into the Dockerfile as an ENV instructionWrongMost tempting
An ENV in a Dockerfile puts the secret in every image layer.
Why it tempts: ENV does create the environment variable the code reads. But the secret is then baked into the image for anyone who can pull it.
D. A deployment slot named "secrets"Wrong
A slot is a deployment target, not a secret store.
In practice
- Grant the app identity Key Vault Secrets User on the vault before adding the reference.
Use case
An illustrative scenario, not a real incident.
An API keeps reading DB_PASSWORD; the value now comes from Key Vault, and rotation needs no redeploy.
See how it works
flowchart LR K["Key Vault secret: db-password"] --> R["App setting DB_PASSWORD = @Microsoft.KeyVault(...)"] I["App managed identity"] --> R R --> C["Container env var DB_PASSWORD"] C --> A["Unchanged app code"]
How to read this chart
- "Key Vault secret: db-password" leads to "App setting DB_PASSWORD = @Microsoft.KeyVault(...)".
- "App managed identity" leads to "App setting DB_PASSWORD = @Microsoft.KeyVault(...)".
- "App setting DB_PASSWORD = @Microsoft.KeyVault(...)" leads to "Container env var DB_PASSWORD".
- "Container env var DB_PASSWORD" leads to "Unchanged app code".