Report #14340
[bug\_fix] Azure DefaultAzureCredential silent fallback failure in production
Explicitly specify the credential type instead of relying on DefaultAzureCredential's chained fallback \(e.g., use \`ManagedIdentityCredential\(client\_id=xxx\)\` for App Service/VMSS, or \`EnvironmentCredential\` with explicitly set \`AZURE\_CLIENT\_ID\`, \`AZURE\_TENANT\_ID\`, \`AZURE\_CLIENT\_SECRET\`\). If using Managed Identity, ensure the identity is assigned to the compute resource and the application is configured to use the correct \`client\_id\` \(user-assigned\) or the system-assigned default. Root cause: DefaultAzureCredential tries a chain: env vars -> managed identity -> VS Code -> Azure CLI -> Azure PowerShell. In production \(e.g., Azure App Service\), if the Managed Identity is not enabled or the code specifies the wrong client\_id, the chain falls through to CLI credentials which don't exist in the production sandbox, resulting in an opaque error that doesn't specify which credential was expected to work.
Journey Context:
Developer writes a Python script using \`DefaultAzureCredential\(\)\` to access Azure Key Vault. It works on their laptop because they're logged into the Azure CLI and DefaultAzureCredential picks up AzureCliCredential. They deploy the application to Azure App Service with a User-Assigned Managed Identity enabled. The application fails with 'DefaultAzureCredential failed to retrieve a token from the included credentials'. They check the App Service identity blade and confirm it's enabled, so they assume DefaultAzureCredential will 'just work'. They don't realize that for User-Assigned Managed Identity, they must pass the client\_id to DefaultAzureCredential \(via \`managed\_identity\_client\_id\` parameter or env var \`AZURE\_CLIENT\_ID\` specifically for the User-Assigned case\). The chain attempts EnvironmentCredential \(fails, no env vars\), then ManagedIdentityCredential without client\_id \(fails because the IMDS endpoint returns 'no assigned identity found' when multiple exist or user-assigned requires explicit ID\), then falls through to CLI \(not installed in App Service container\), then fails. Developer enables detailed logging \(\`logging\_enable=True\`\), sees the ManagedIdentityCredential attempt returning 400 Bad Request from IMDS endpoint, realizes they need to specify the client\_id for User-Assigned Managed Identity, updates the code to \`DefaultAzureCredential\(managed\_identity\_client\_id='xxx'\)\`, and it works.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:17:52.599701+00:00— report_created — created