Description
Check how the Function App connects to other Azure services. Where supported, a managed identity can replace a long-lived key in a connection string. Authentication for callers of the function is separate.
Potential impact
Keys in code or app settings can be exposed or missed during rotation and revocation.
Remediation
Choose SystemAssigned in the identity block or select UserAssigned and list the managed identity’s Azure resource ID in identity_ids. Grant the identity only the permissions it needs at the target. Update the connection configuration or code to use managed identity tokens. Run the function and check that the intended operation succeeds with the identity, then remove and revoke credentials no longer needed by any connection.
Examples
The AzureRM 3.x azurerm_function_app example adds a system-assigned identity. Supply the required storage settings, target permissions and token-using code separately.
Before
resource "azurerm_function_app" "example" {
name = "test-azure-functions"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
app_service_plan_id = azurerm_app_service_plan.example.id
}
After
resource "azurerm_function_app" "example" {
name = "test-azure-functions"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
app_service_plan_id = azurerm_app_service_plan.example.id
identity {
type = "SystemAssigned"
}
}