Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I use the credentials in ~/.azure folder? #1310

Closed
apengwin opened this issue Jul 19, 2017 · 4 comments
Closed

How do I use the credentials in ~/.azure folder? #1310

apengwin opened this issue Jul 19, 2017 · 4 comments
Labels
question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@apengwin
Copy link

apengwin commented Jul 19, 2017

I'm playing around with Azure blob storage, and I currently pass in my authentication info manually in my python code.

from azure.storage.blob import BlockBlobService
foo = BlockBlobService(account_name, access_key)

I was wondering if there was to use the access tokens or credentials stored in the ~/.azure folder to automatically populate the authentication credentials, similar to how boto3 searches in ~/.aws/credentials?

For reference, this is the contents of the ~/.azure folder

(venv) airbears2-10-142-32-217:~ allanpeng$ ls ~/.azure
accessTokens.json	az.json			az.sess			azureProfile.json	clouds.config		config
@lmazuel
Copy link
Member

lmazuel commented Jul 19, 2017

Hi @apengwin

This is an excellent question, and this has moved a lot recently. Today, my response would be:

In a few days, you will be able to save a authentication file and load it in the SDK like:

        from azure.common.client_factory import get_client_from_auth_file
        from azure.mgmt.compute import ComputeManagementClient
        client = get_client_from_auth_file(ComputeManagementClient)

I will release that probably tomorrow, it's nothing but updating release notes and pushing to PyPI.

However, this is not working for client not based on Service Principal authentication, like Storage. What you can do with Storage, is to use a service principal credentials to get the Storage credentials:

client = get_client_from_auth_file(StorageManagementClient)
storage_keys = storage_client.storage_accounts.list_keys(resource_group_name, storage_account_name)
storage_keys = {v.key_name: v.value for v in storage_keys.keys}

storage_client = CloudStorageAccount(storage_account_name, storage_keys['key1'])
blob_service = storage_client.create_block_blob_service()

FYI @yugangw-msft

@lmazuel lmazuel added the question The issue doesn't require a change to the product in order to be resolved. Most issues start as that label Jul 19, 2017
@lmazuel
Copy link
Member

lmazuel commented Aug 24, 2017

@apengwin can we close this issue or you think it does not respond correctly to it?
Thanks!

@apengwin
Copy link
Author

@lmazuel yup. thanks!

@zeelot
Copy link

zeelot commented Oct 24, 2019

Hello! So I'm still pretty confused about this a few years later…
I am trying to create a blob client with the credentials generated by az login but have the blob calls be traceable back to my user (through the monitoring logs).

I don't know where to ask the question but this issue seemed like the best lead I had but using the storage account keys directly is not what I want :(

Can someone help me find the right approach?

@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

3 participants