Description
Configure managed identity and access for each deployment slot. If the staging slot connects to an Azure resource, decide which permissions it needs separately from the production app.
Potential impact
Long-lived keys in staging settings can be exposed or overlooked during credential rotation.
Remediation
If the target supports managed identity, choose SystemAssigned or UserAssigned in the slot’s identity block. For UserAssigned, include the managed identity’s Azure resource ID in identity_ids. Grant the chosen identity only the access it needs and configure the app to obtain tokens with it. Test the required operation from the staging slot before removing the old secret.
Examples
The Windows Web App example attaches a system-assigned identity to staging. Configure the parent app and target-resource permissions separately.
Before
resource "azurerm_windows_web_app_slot" "example" {
name = "staging"
app_service_id = azurerm_windows_web_app.example.id
site_config {}
}
After
resource "azurerm_windows_web_app_slot" "example" {
name = "staging"
app_service_id = azurerm_windows_web_app.example.id
site_config {}
identity {
type = "SystemAssigned"
}
}