Report #68447
[bug\_fix] DefaultAzureCredential failed to retrieve a token from the included credentials \(CredentialUnavailableError\)
Ensure the target credential's prerequisites are met: for Managed Identity, verify the resource \(VM, App Service, AKS pod\) has a Managed Identity assigned; for local development, ensure \`AZURE\_TENANT\_ID\`, \`AZURE\_CLIENT\_ID\`, and \`AZURE\_CLIENT\_SECRET\` \(or certificate\) are set for EnvironmentCredential, or run \`az login\` for AzureCliCredential. Root cause: \`DefaultAzureCredential\` is an opinionated chain that tries multiple auth methods \(Environment → Managed Identity → Azure CLI → VS Code, etc.\). If all providers fail \(e.g., IMDS endpoint unreachable, env vars missing, CLI not logged in\), it throws this aggregate exception.
Journey Context:
Developer writes a Python app using \`azure-identity\` and \`azure-keyvault-secrets\`. They use \`DefaultAzureCredential\(\)\` which works locally because they are logged into Azure CLI. They deploy to Azure Kubernetes Service \(AKS\) without enabling Workload Identity or attaching a Managed Identity to the node pool. The pod starts and immediately throws \`CredentialUnavailableError: DefaultAzureCredential failed to retrieve a token\`. The developer checks the stack trace and sees it tried \`EnvironmentCredential\` \(env vars not set\), then \`ManagedIdentityCredential\` \(failed to reach 169.254.169.254 - IMDS\), then \`AzureCliCredential\` \(CLI not installed in container\). They realize that \`DefaultAzureCredential\`'s 'magic' relies on the environment providing at least one valid provider. They fix it by enabling a Managed Identity on the AKS agent pool and assigning the 'Key Vault Secrets User' role to that identity. The next deployment succeeds because \`ManagedIdentityCredential\` successfully reaches the IMDS endpoint and obtains a token.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T21:22:12.864243+00:00— report_created — created