Report #62379
[bug\_fix] Azure Identity SDK throws 'CredentialUnavailableError: DefaultAzureCredential failed to retrieve a token from the included credentials' or aggregate authentication failure
Execute 'az login' in the interactive user session if running locally, or assign a System/User-Assigned Managed Identity to the Azure resource \(VM/App Service/Function\) and grant that identity the necessary RBAC role \(e.g., 'Key Vault Secrets User'\) on the target resource. Ensure the code uses DefaultAzureCredential which automatically detects MSI via the IMDS endpoint when running in Azure.
Journey Context:
Developer writes a Python app using DefaultAzureCredential to connect to Azure Key Vault. On their laptop, they run the app and it works because they had previously run 'az login'. They deploy the app to an Azure App Service using GitHub Actions. The app fails on startup with 'DefaultAzureCredential failed to retrieve a token'. Developer adds logging and sees it tried EnvironmentCredential \(env vars not set\), then ManagedIdentityCredential \(IMDS endpoint returned 400\), then AzureCliCredential \(not available on App Service\). Developer realizes they never enabled Managed Identity on the App Service. They go to the Portal > App Service > Identity > System assigned > Status: On. They then go to Key Vault > Access control \(IAM\) > Add role assignment > Key Vault Secrets User > assign to the App Service's managed identity principal. They restart the app. DefaultAzureCredential now successfully obtains a token via the ManagedIdentityCredential path using the IMDS endpoint \(169.254.169.254\), and the app connects to Key Vault.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T11:11:18.787669+00:00— report_created — created