6

I was trying to accessing my key vault, but I got always the same error:

AppServiceCredential.get_token failed: request() got an unexpected keyword argument 'tenant_id'
ManagedIdentityCredential.get_token failed: request() got an unexpected keyword argument 'tenant_id'

This was the code I used in an Azure Machine Learning notebook, copied from the docs:

from azure.identity import ManagedIdentityCredential
from azure.keyvault.secrets import SecretClient

credential = ManagedIdentityCredential()
secret_client = SecretClient(vault_url="https://XXXX.vault.azure.net/", credential=credential)

secretName = 'test'
retrieved_secret = secret_client.get_secret(secretName) # here's the error
retrieved_secret

What is wrong? Could you help me? Thank you in advance.

SDG6
  • 91
  • 1
  • 8

2 Answers2

7

This error is because of a bug that has since been fixed in azure-identity's ManagedIdentityCredential. Key Vault clients in recent packages include a tenant ID in token requests to support cross-tenant authentication, but some azure-identity credentials didn't correctly handle this keyword argument until the bug was fixed in version 1.8.0. Installing azure-identity>=1.8.0 should fix the error you're getting.

(Disclaimer: I work for the Azure SDK for Python)

mccoyp
  • 252
  • 1
  • 7
  • I am seeing this issue in azure-identity==1.11.0. All of a sudden it appeared. It used to work earlier with the same version. Is there a known issue? – kishore Dec 08 '22 at 03:37
  • Multi-tenant authentication was modified in `azure-identity` 1.11.0 ([changelog](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/CHANGELOG.md#1110-2022-09-19)), so that could be the cause of new `ClientAuthenticationError`s. Are you specifically seeing the unexpected keyword argument error, or something else? Also, which Key Vault package/version (or other client package) are you using? – mccoyp Dec 09 '22 at 18:43
  • Thank you for reverting. After some debugging another library is overriding the library version 1.11.0 and setting it as 1.7.0 which is causing the issue. I was able to resolve the issue by figuring out the dependencies. – kishore Dec 12 '22 at 02:14
  • can I know which lib overrides the version – Fangda Han Feb 15 '23 at 22:43
  • This does not work and should not be the accepted answer. Alex M's answer below works and is reproducible. – John Stud Jun 29 '23 at 13:01
  • @JohnStud, which package versions did you have installed? Were you still seeing the same unexpected keyword argument error, or something else related to the tenant? – mccoyp Jun 30 '23 at 21:24
1

Having the same issue right now (also working with Azure ML Compute Instance), and only downgrading the packages worked for me.

  • azure-identity==1.11.0
  • azure-keyvault-secrets==4.6.0

@mccoyp: Maybe you can give this feedback to the team

Alex M
  • 11
  • 2
  • Confirmed to fix the issue; pretty sloppy that this is still an issue 1.3 years later. – John Stud Jun 29 '23 at 13:00
  • Hi @Alex M, can you share which package versions were causing you to see this error? And just to confirm, was it the same unexpected keyword argument error? – mccoyp Jul 07 '23 at 22:52