azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

How to acquire BlockBlobService with RBAC (without using storage account keys)

Open kattelus opened this issue 8 years ago • 4 comments

It seem that RBAC support is available (preview) https://docs.microsoft.com/en-us/azure/storage/common/storage-auth-aad-rbac

But is is possible to use it in python sdk?

E.g. to get BlockBlobService in similar way that you can acquire access to management clients. Or get BlockBlobService from StorageManagementClient directly?

kattelus avatar Aug 09 '18 11:08 kattelus

Yes, totally possible. We probably lack samples however.

There is two parts here:

  • Assigning role to a AD account using the azure-mgmt-authorization package. This will look close to this (not tested explicitly):
role_id = "ba92f5b4-2d11-453d-a403-e96b0029c9fe" # Storage Blob Data Contributor (Preview)
role_assignment = authorization_client.role_assignments.create(
    resource_group.id,  # Scoped to resource group
    uuid.uuid4(), # Role assignment random name
    {
        'role_definition_id': role_id,  # Storage Blob Data Contributor (Preview)
        'principal_id': ad_id           # Your AD account id
    }
)

https://docs.microsoft.com/python/api/overview/azure/authorization

  • Usage in Storage, will still be azure-storage-blob package, at least version 1.3.0. I refer you to the Storage repo for more details on this part: https://github.com/Azure/azure-storage-python/tree/master/samples

@zezha-msft FYI

lmazuel avatar Aug 09 '18 21:08 lmazuel

Hi @kattelus, here is a working sample.

zezha-msft avatar Aug 09 '18 22:08 zezha-msft

Ok thanks. Need to test but seems exactly what I need.

kattelus avatar Aug 10 '18 08:08 kattelus

Worked well. Anyway interesting issue is that it seems that owner is not capable to do same think directly. E.g. also for the owner you need to give same preview read permission to make possible to authenticate with token and get read access? This probably is not issues of python SDK just caused some confusion :)

kattelus avatar Aug 15 '18 05:08 kattelus