Report #11195
[bug\_fix] Azure ManagedIdentityCredential authentication unavailable. No managed identity endpoint found
When running locally, ensure you are authenticated via Azure CLI \(\`az login\`\) or Visual Studio Code, and use DefaultAzureCredential instead of ManagedIdentityCredential directly. DefaultAzureCredential falls back to AzureCliCredential when not in Azure. When deploying to Azure, do not set the AZURE\_CLIENT\_ID environment variable unless using a User-Assigned Managed Identity; for System-Assigned, let the platform set MSI\_ENDPOINT.
Journey Context:
A developer writes a Python script to access Azure Key Vault. They deploy it to an Azure VM with a System-Assigned Managed Identity enabled. They use the code \`credential = ManagedIdentityCredential\(\)\` and it works perfectly on the VM. They clone the repo to their laptop to debug an issue. Running the script locally, it immediately crashes with \`CredentialUnavailableError: ManagedIdentityCredential authentication unavailable. No managed identity endpoint found. The credential does not have an IMDS endpoint to use\`. The developer searches and finds that ManagedIdentityCredential only works inside Azure because it queries the Instance Metadata Service \(IMDS\) at \`169.254.169.254\`. Locally, that endpoint doesn't exist. The developer considers commenting out the code and using \`ClientSecretCredential\` locally, but that's messy. The proper fix is replacing \`ManagedIdentityCredential\(\)\` with \`DefaultAzureCredential\(\)\`. DefaultAzureCredential has a chained list of credentials to try: EnvironmentCredential, ManagedIdentityCredential, AzureCliCredential, etc. When running locally, it skips ManagedIdentityCredential \(since IMDS isn't available\) and picks up the developer's \`az login\` session via AzureCliCredential. When deployed to the VM, it successfully uses ManagedIdentityCredential. The developer runs \`az login\` locally, switches to \`DefaultAzureCredential\`, and the script works both locally and in Azure without code changes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T12:45:16.757670+00:00— report_created — created