Reputation: 4405
Is there a way authenticate a python app to Azure without adding secrets to my code? Because I'm on untrusted computing resources I can't save my secrets as environment variables nor store "config" files locally.
Given:
python-sp
)Contributor
role to Azure Key VaultExample:
clientSecret
to be added to the code is to use az login
...sp_name = 'python-sp'
sp_file = 'sp_creds.json'
!az login
!az ad sp create-for-rbac -n $sp_name --sdk-auth > $sp_file
!export AZURE_AUTH_LOCATION=$sp_file
with open(sp_file) as data_file:
sp_details = json.load(data_file)
os.remove(sp_file)
Unfortunately this requires interaction so the code isn't really headless. Aside from that, the credentials are in a json file in memory, even if only for a few moments.
How do I instead access Azure Key Vault to retrieve authentication keys/secrets?
The methods listed here all seem to require a credential be stored and accessed in some file or hardcoded.
Chicken and egg! But I guess it makes sense. Any ideas?
Upvotes: 0
Views: 514
Reputation: 72191
well, this question is not specific to Azure Python SDK. and the answer would be the same regardless of what type of SDK (or platform, even) you are using. So pass in credentials as environment variables, use certificates, use vaults, use managed identities, etc. All of these approaches allow for headless auth.
Upvotes: 1