[BUG] Azure.Identity 1.5.0 freezes up ChainedTokenCredential with ManagedIdentityCredential listed first in local dev
See original GitHub issueDescribe the bug
Immediately after upgrading Azure.Identity
from 1.4.1 to 1.5.0, I noticed all my web projects freeze up at startup in local dev (VS Kestrel).
In my host builder inside Program.cs, I have
var tokenCred = new ChainedTokenCredential(new ManagedIdentityCredential(), new AzureCliCredential());
var secretClient = new SecretClient(
new Uri($"https://my-keyvault.vault.azure.net/"),
tokenCred);
var certificatesClient = new CertificateClient(
new Uri($"https://my-keyvault.vault.azure.net/"),
tokenCred);
config.AddAzureKeyVault(secretClient, new KeyVaultSecretManager());
...//load some necessary secret/certs etc
Note that I use ChainedTokenCredential
with ManagedIdentityCredential
listed first, followed by AzureCliCredential
. This would ensure that when the project runs in Azure, managed identity is immediately used. In local dev, managed identity is attempted first which would fail quickly, then AzureCliCredential
is successfully used next.
Expected behavior
Normally, the ManagedIdentityCredential
should fail quickly (within a second or so) when running in local dev environment, which allows the chained credential to fall through to the next available credential.
Actual behavior
Something changed in Azure.Identity
1.5.0, which makes the program freeze up at ManagedIdentityCredential
in local dev for a minute+. No exception/error messages (except Kestrel would time out, saying host is unable to start). But eventually, AzureCliCredential
hits and code flows through. Maybe the timetout on ManagedIdentityCredential
was misconfigured in the newer package.
Environment:
- Azure.Identity 1.5.0
- Visual Studio 2022 RC1
- ASP.NET Core Web API and Razor projects set to start up via Kestrel
Issue Analytics
- State:
- Created 2 years ago
- Comments:22 (10 by maintainers)
Top GitHub Comments
Hi @christothes
I can provide my details.
My service is using
DefaultAzureCredential
without any other options and running the code on my laptop (local development), using VS 2022.I’ve done
az login
in the command line to cache my personal credentials to access Azure Resources. If I run it from the command line usingdotnet run
(not using VS 2022 at all), I get the same behaviour.I observed the delay with connections to Azure Key Vault and Azure Service Bus.
Following is sample code connecting to KeyVault. You can see from the logs that it takes 10 seconds when
ManagedIdentityCredential
is not excluded vs 3 seconds whenManagedIdentityCredential
is excluded.Sample code 1
Logs (10 seconds to get the first key)::
Sample code 2 (
ExcludeManagedIdentityCredential = true
)Logs (3 seconds to get first key):
Packages in my project (same behaviour with Azure.Identity 1.8.0-beta.1 and 1.9.0-beta.1):
System Info
Hi @heldersousa-planetpayment - I think the reason that the distinct
DefaultAzureCredential
works relatively the same as the reused example is that, under the covers, when you don’t pass any options toDefaultAzureCredential
you actually get a static singleton each time.