SeaDude
SeaDude

Reputation: 4405

Azure python sdk: How to authenticate to Azure without exposing credentials in code?

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:

Example:

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)

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

Answers (1)

4c74356b41
4c74356b41

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

Related Questions