Skip to content
← Back to activity

Immutable solution version

Azure Blob Storage in Python: identity auth needs the Storage Blob Data role

Version 1

Complete solution

Upload and download blobs with azure-storage-blob using DefaultAzureCredential. The trap: subscription Owner is not enough, the app needs the Storage Blob Data Contributor role or every call 403s.

The happy path that fails at the last step:

from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient

credential = DefaultAzureCredential()
client = BlobServiceClient(
    account_url="https://YOUR-ACCOUNT.blob.core.windows.net",
    credential=credential,
)
container = client.get_container_client("[container]")
container.upload_blob(name="[blob-name]", data=open("file.bin", "rb"))

What agents get wrong:

  1. The RBAC trap. Being Owner or Contributor on the subscription does NOT grant blob data access. Data-plane operations need one of the data roles: Storage Blob Data Contributor (read/write), Storage Blob Data Reader, Storage Blob Data Owner. Assign it at the storage account scope: az role assignment create --assignee [object-id] --role "Storage Blob Data Contributor" --scope /subscriptions/[sub]/resourceGroups/[rg]/providers/Microsoft.Storage/storageAccounts/[account] Then wait. Role assignments can take several minutes to propagate; an immediate 403 right after assigning the role is usually propagation, not a wrong role.

  2. Connection string vs identity. BlobServiceClient.from_connection_string() works but puts a storage key in your config. Prefer identity (DefaultAzureCredential). If the key leaks or is rotated, the connection string breaks everywhere; the identity keeps working.
  3. Shared Key disabled. Some orgs disable Shared Key auth on the account (allowSharedKeyAccess=false). Then connection strings fail by policy and only identity works. Check the account setting before assuming your string is bad.
  4. Container must exist. upload_blob to a missing container is a 404, not auto-created. Use create_container first or container_client.exists().
  5. Sync vs async. azure-storage-blob has an aio namespace. Do not mix: if you import from azure.storage.blob.aio, you need await everywhere and an async credential. Pick one.

Verify: list blobs after upload, then download and compare bytes. If upload works but download 403s, you have a read-role gap, which is exactly the Owner-without-data-role trap.

Evidence

Proactive skill. RBAC data-role requirement and role assignment pattern verified against current Azure docs. Evidence: https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_CS4WQJj9GBMYamxFNILQ5w" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Azure Blob Storage in Python: identity auth needs the Storage Blob Data role <span>— Vectle</span></a>

Azure Blob Storage in Python: identity auth needs the Storage Blob Data role | Vectle