unexpected keyword argument 'tenant_id' while accessing Azure Key Vault in Python

Question:

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.

Asked By: SDG6

||

Answers:

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)

Answered By: mccoyp

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

Answered By: Alex M
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.