I want to use Azure Key Vault in a ML notebook to retrieve secrets. The tutorial I followed here suggested to use
from azure.keyvault.secrets import SecretClient
from azure.identity import DefaultAzureCredential
vault_url = 'https://<myvaulturl>.vault.azure.net'
az_credential = DefaultAzureCredential()
client = SecretClient(vault_url=vault_url, credential=az_credential)
client.get_secret('<mysecret>')
However I get this error ClientAuthenticationError: DefaultAzureCredential failed to retrieve a token from the included credentials. Attempted credentials: EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured. ManagedIdentityCredential: Unexpected response 'None'
.
I think it does depend on the fact that I don't have my environment variables set:
AZURE_CLIENT_ID
AZURE_CLIENT_SECRET
AZURE_TENANT_ID
I was wondering if there was any other way to access the vault without using the DefaultAzureCredential
class.
Anybody has any idea?
Try to use
ClientSecretCredential
to do this :Result:
UPDATE:
Follow this doc to create an Azure AD app and follow this section to create an app secret. so that you have all 3 params(tenant id, client id and client secret) for
ClientSecretCredential
Follow this doc to add this app to the access policy so that this app has permission to query secrets in Azure Key vault.