question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`ManagedIdentityCredential` hangs indefinity when using keyvault

See original GitHub issue

Describe the bug Using ManagedIdentityCredential with @azure/keyvault-secrets hangs when managed identity not available.
I want to use DefaultAzureCredential because my laptop uses AzureCliCredential and our cloud environments use ManagedIdentityCredential However, I can not use DefaultAzureCredential because it tries to use ManagedIdentityCredential first which hangs.

To Reproduce Steps to reproduce the behavior:

  1. Ensure your laptop does not have any ManagedIdentityCredential: rm ~/.azure
  2. Use the example found in the documentation here to try out keyvault.
  3. Notice process hangs when trying to run the script.

Expected behavior The script should run correctly.

Additional context I opened up Wireshark and the socket remains open with keep-alives Screen Shot 2022-08-17 at 2 44 19 PM

Workaround My current workaround is to create my own ChainedTokenCredential which has AzureCliCredential listed before ManagedIdentityCredential

const providers = [AzureCliCredential, ManagedIdentityCredential]

class Credentials extends ChainedTokenCredential {
  constructor(options) {
    super(...providers.map(ctor => new ctor(options)))
    this.UnavailableMessage =
      'Credentials => failed to retrieve a token from the included credentials. To troubleshoot, visit https://aka.ms/azsdk/js/identity/defaultazurecredential/troubleshoot.'
  }
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cveldcommented, Nov 18, 2022

Out of curiosity, from a node module library engineering perspective, how did you manage to support two versions of @azure/identity from within 4.6.0? Is it as simple as that the interface between the two versions are compatible? And you set the dependency version range accordingly; allowing for two major version ranges?

With 3.0.0 our local experience runs smooth again. With version 2.1.0, ManagedIdentityCredential was trying to reach out to the token endpoint but failed with a timeout: ManagedIdentityCredential: Authentication failed. Message connect ETIMEDOUT 169.254.169.254:80

With 3.0.0 it is apparently able to detect way quicker that the endpoint is not there and fails way more quickly. I wonder how this logic goes.

1reaction
timovvcommented, Sep 22, 2022

Hi @anandkumarpatel. It looks like this issue slipped through the cracks, sorry about that! I think you might be running into the same problem described in #23017. Are you able to upgrade to the new @azure/identity 3.0.0 (and the 4.6.0 version of @azure/keyvault-secrets for good measure) and see if the problem persists? The new release of Identity includes a fix which will hopefully fix the hang.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Occassional error authenticating to KeyVault
The images should be using the ManagedIdentityCredential, but as the error says, the "IMDS endpoint" is unavailable. I build in some checks that ......
Read more >
Retrieving Azure Key Vault secrets with PowerShell in Azure ...
When trying to link the KeyVault in the Variable Group, the authentication process can hang indefinitely. It can be solved in KeyVault, by...
Read more >
Key Vault returns 401 using ManagedIdentityCredential for ...
I am using Access Control on the key vault and it my Managed Identity is a Key Vault Administrator. What could be going...
Read more >
The danger of using config.AddAzureKeyVault() in .NET Core
NET Core is great to define where your configuration is located. However, the provider for Azure Key Vault is a bit tricky and...
Read more >
Azure Python SDK Authentication - Cloud Journey - Medium
In this article, I will install PyCharm, create a project from scratch, authenticate to Azure and work with keyvault. The goal is to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found