How to acquire BlockBlobService with RBAC (without using storage account keys)
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?
Yes, totally possible. We probably lack samples however.
There is two parts here:
- Assigning role to a AD account using the
azure-mgmt-authorizationpackage. 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-blobpackage, 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
Hi @kattelus, here is a working sample.
Ok thanks. Need to test but seems exactly what I need.
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 :)