Skip to content

CredentialUnavailableError raised from ImdsCredential with no real connection issue #19091

@bonsairobo

Description

@bonsairobo
  • Package Name: azure.identity
  • Package Version: master
  • Operating System: Linux
  • Python Version: 3

Describe the bug

Here:

def _request_token(self, *scopes, **kwargs): # pylint:disable=unused-argument

The code assumes that if gets an Exception other than HttpResponseError, then it must be some connectivity issue. This is probably not valid, as we have tested our connection to 169.254.169.254 immediately after getting the "no managed identity endpoint found" error, and there was no connection problem.

The larger issue is that the original exception is dropped, so the user can't even know what went wrong. Rather, they get a useless CredentialUnavailableError. It would be much nicer if you wrapped the original error so the user knows what happened.

Furthermore, after the first presumed connection failure with IMDS, the _request_token method will set _endpoint_available to False, which makes it always raise CredentialUnavailableError on further calls; there is no hope for recovering.

To Reproduce
Steps to reproduce the behavior:

  1. Create a SecretClient with a ManagedIdentity credential.
  2. We use azure.keyvault.secrets.SecretClient.get_secret and occasionally we get:
azure.identity._exceptions.CredentialUnavailableError: ManagedIdentityCredential authentication unavailable, no managed identity endpoint found.

We retry on this error, but it never recovers, and we eventually timeout at a higher layer.

Expected behavior

I think you have a few options:

  1. Actually test TCP connections with IMDS instead of relying on exception handling at the HTTP layer.
  2. Wrap the exception into the CredentialUnavailableError instead of dropping it so users can see what happened.

Metadata

Metadata

Assignees

Labels

Azure.Identitycustomer-reportedIssues that are reported by GitHub users external to the Azure organization.feature-requestThis issue requires a new behavior in the product in order be resolved.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK team

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions