Hi @Samuel Wederell ,
Thanks for reaching out to Microsoft Q&A.
DefaultAzureCredential and its ChainedTokenCredential under the covers will try a bunch of mechanisms in order environment variables, Azure CLI creds, managed identity, etc. but in your pipeline container there is no managed identity endpoint to hit unless you explicitly wire one up.
Here are a few patterns you can try:
- Use Azure DevOps’ built-in Key Vault task
- Add the AzureKeyVault@2 task to your pipeline to fetch secrets into pipeline variables (or files).
- Then pass those values into your Docker container as environment variables or mounted files.
- Docs
Authenticate via Workload Identity Federation (OIDC)
- In Azure AD, create a Federated credential for your DevOps service connection (in your App Registration’s “Certificates & secrets” → “Federated credentials”).
- Configure your pipeline’s AzureRM or Service Principal connection to emit an OIDC token.
- In your container, DefaultAzureCredential will detect the OIDC token via the
AZURE_FEDERATED_TOKEN_FILEenvironment variable and exchange it for an Azure AD token.
Use Azure CLI or Service Principal environment auth
- Before you spin up the container, run
az login --identity(if you’re on a VM/ACI with MI) oraz login --service-principal -u <id> -p <secret> --tenant <tid>. - Mount the Azure CLI token cache and/or set the standard env vars (
AZURE_CLIENT_ID,AZURE_CLIENT_SECRET,AZURE_TENANT_ID) into the container. - DefaultAzureCredential will pick up the CLI credential first.
Move to a runtime that supports Managed Identity natively
- If you run your container in an Azure Container Instance, Web App for Containers, Azure Kubernetes Service, etc., you can enable a system- or user-assigned MI at the host level.
- Inside your container DefaultAzureCredential will then find the IMDS endpoint and work as it does locally when your VM has a MI.
Fetch secrets with AzureKeyVault@2
Federated credentials for Azure DevOps OIDC
ChainedTokenCredential / DefaultAzureCredential overview
Hope this helps!
If the resolution was helpful, kindly take a moment to click on and click on Yes for was this answer helpful. And, if you have any further query do let us know.