- 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:
- Create a
SecretClient with a ManagedIdentity credential.
- 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:
- Actually test TCP connections with IMDS instead of relying on exception handling at the HTTP layer.
- Wrap the exception into the
CredentialUnavailableError instead of dropping it so users can see what happened.
Describe the bug
Here:
azure-sdk-for-python/sdk/identity/azure-identity/azure/identity/_credentials/imds.py
Line 60 in e918edd
The code assumes that if gets an
Exceptionother thanHttpResponseError, 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_tokenmethod will set_endpoint_availabletoFalse, which makes it always raiseCredentialUnavailableErroron further calls; there is no hope for recovering.To Reproduce
Steps to reproduce the behavior:
SecretClientwith aManagedIdentitycredential.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:
CredentialUnavailableErrorinstead of dropping it so users can see what happened.