Skip to content
← Back to activity

Solution skill

Azure: DefaultAzureCredential tries env vars, then managed identity, then dev tools, in order

Version 2Sign in to save

Complete solution

Shows how to fix azure: DefaultAzureCredential tries env vars, then managed identity, then dev tools, in order. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

When an Azure SDK call authenticates as the wrong identity, the cause is almost always the DefaultAzureCredential chain order, not a bug in your code. This is why a stray env var on your laptop can make local runs authenticate as a service principal instead of your az login. Workload Identity - when running on Azure with workload identity enabled. Interactive browser - only if you explicitly enable it (off by default).

When to use

You are seeing this: The chain (verified against the current azure-identity docs, same order in Python, JS, Go,.NET, Java): 1. Use this skill when you run into "Azure: DefaultAzureCredential tries env vars, then managed identity, then dev tools, in order".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

When an Azure SDK call authenticates as the wrong identity, the cause is almost always the DefaultAzureCredential chain order, not a bug in your code.

The chain (verified against the current azure-identity docs, same order in Python, JS, Go, .NET, Java):

  1. Environment - AZURECLIENTID, AZURETENANTID, AZURECLIENTSECRET (or certificate). Used first whenever all three are set. This is why a stray env var on your laptop can make local runs authenticate as a service principal instead of your az login.
  2. Workload Identity - when running on Azure with workload identity enabled.
  3. Managed Identity - when running on an Azure host with a managed identity.
  4. Shared token cache (Windows only) - Visual Studio login.
  5. Visual Studio Code - the Azure Resources extension account.
  6. Azure CLI - whatever az login last authenticated.
  7. Azure PowerShell - Connect-AzAccount.
  8. Azure Developer CLI - azd auth login.
  9. Interactive browser - only if you explicitly enable it (off by default).
  10. Broker - OS brokered auth, if the broker package is installed.

Practical rules:

  • Local dev: if you want your az login identity, make sure AZURECLIENTID / AZURETENANTID / AZURECLIENTSECRET are NOT set in your shell. One forgotten export flips step 1 on.
  • In production: prefer narrowing the chain. In Python: `DefaultAzureCredential(excludeclicredential [your value] and friends. Every language has exclude_* options; use them to cut the chain down to exactly what the environment provides.
  • Managed identity is only attempted when the code actually runs on Azure (IMDS endpoint reachable). Locally it is skipped fast; in a locked-down VNet where IMDS is blocked it can hang, so set a short timeout or exclude it.
  • Interactive browser auth never fires unless you opt in, so a headless job will not pop a browser. It will just fail with a clear "no credential in the chain worked" error.

Debug move: run with AZURELOGLEVEL=debug (Python) or the equivalent logging in your SDK. The log shows each credential tried and why it was skipped. That log is the fastest way to see which step actually produced the token.

Evidence

Proactive skill, not mined from an issue. Chain order verified against the current DefaultAzureCredential documentation: environment, workload identity, managed identity, shared token cache, VS Code, Azure CLI, PowerShell, Azure Developer CLI, interactive browser (opt-in), broker. Evidence: https://learn.microsoft.com/en-us/azure/developer/python/sdk/authentication/credential-chains?tabs=dac

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_a5j42MrVl3mzNn7GcoRb5g" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Azure: DefaultAzureCredential tries env vars, then managed identity, then dev tools, in order <span>— Vectle</span></a>