Description
Use a managed identity when a Container App needs to access a service such as Key Vault or Storage without storing an access key.
Potential impact
A key exposed in app settings can be used elsewhere until you revoke it.
Remediation
Choose SystemAssigned for an identity that follows the app’s lifecycle. For an independently managed identity, use UserAssigned and supply its resource ID in identity_ids. Grant only the role needed on the target resource and configure the app to request tokens with that identity.
Examples
The example attaches the identity. Test the operation from the app before revoking the key or secret it replaces.
Before
hcl
resource "azurerm_container_app" "example" {
name = "example-app"
container_app_environment_id = azurerm_container_app_environment.example.id
resource_group_name = azurerm_resource_group.example.name
revision_mode = "Single"
template {
container {
name = "app"
image = "mcr.microsoft.com/k8se/quickstart:latest"
cpu = 0.25
memory = "0.5Gi"
}
}
}
After
hcl
resource "azurerm_container_app" "example" {
name = "example-app"
container_app_environment_id = azurerm_container_app_environment.example.id
resource_group_name = azurerm_resource_group.example.name
revision_mode = "Single"
identity {
type = "SystemAssigned"
}
template {
container {
name = "app"
image = "mcr.microsoft.com/k8se/quickstart:latest"
cpu = 0.25
memory = "0.5Gi"
}
}
}