Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Prepare Azure environments for new workloads—subscriptions, networking, identity, and landing zones
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/services/storage/access.md
1# Storage - Access Patterns23## Prerequisites for Granting Storage Access45> ⚠️ **Important**: To assign storage roles to managed identities, you need:6> - **User Access Administrator** or **Owner** role on the Storage Account (or parent resource group/subscription)7> - The role must include the `Microsoft.Authorization/roleAssignments/write` permission89**Common scenarios**:10- Granting Storage Blob Data Owner to a Web App or Function App's managed identity (System Assigned or User Assigned)11- Adding read/write access to blobs, queues, and tables for application workloads12- Allowing user identities (developers, data admins) access in dev/test environments13- Allowing applications to access storage using managed identity instead of connection strings1415**Scope best practices**:16- Grant roles at the **smallest scope possible** (e.g., specific storage account, not resource group or subscription)17- Avoid broad scopes (Resource Group, Subscription, Tenant) unless absolutely necessary18- Prefer resource-level assignments for production workloads1920**Managed identity types**:21- **System Assigned**: Automatically created with the resource (Web App, Function). Default when using `DefaultAzureCredential`.22- **User Assigned**: Standalone identity that can be shared across resources. Requires additional configuration:23- Set `AZURE_CLIENT_ID` app setting to the User Assigned Managed Identity's client ID24- Configure identity in Bicep with both `type: 'SystemAssigned, UserAssigned'` and `userAssignedIdentities`2526If you encounter `AuthorizationFailed` errors when assigning roles, ensure you have User Access Administrator or Owner permissions at the target scope.2728## Managed Identity Role Assignment2930```bicep31resource storageRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {32name: guid(storageAccount.id, principalId, 'Storage Blob Data Contributor')33scope: storageAccount34properties: {35roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'ba92f5b4-2d11-453d-a403-e96b0029c9fe')36principalId: principalId37principalType: 'ServicePrincipal'38}39}40```4142## Storage Roles4344| Role | Permissions |45|------|-------------|46| Storage Blob Data Reader | Read blobs |47| Storage Blob Data Contributor | Read/write blobs |48| Storage Queue Data Contributor | Read/write queues |49| Storage Table Data Contributor | Read/write tables |5051## SDK Connection Patterns5253### Node.js5455```javascript56const { BlobServiceClient } = require("@azure/storage-blob");5758const blobServiceClient = BlobServiceClient.fromConnectionString(59process.env.AZURE_STORAGE_CONNECTION_STRING60);61const containerClient = blobServiceClient.getContainerClient("uploads");62```6364### Python6566```python67from azure.storage.blob import BlobServiceClient6869blob_service_client = BlobServiceClient.from_connection_string(70os.environ["AZURE_STORAGE_CONNECTION_STRING"]71)72container_client = blob_service_client.get_container_client("uploads")73```7475### .NET7677```csharp78var blobServiceClient = new BlobServiceClient(79Environment.GetEnvironmentVariable("AZURE_STORAGE_CONNECTION_STRING")80);81var containerClient = blobServiceClient.GetBlobContainerClient("uploads");82```8384## Managed Identity Access8586Use `DefaultAzureCredential` for local development (in production, use `ManagedIdentityCredential` — see [auth-best-practices.md](../../auth-best-practices.md)):8788```javascript89const { DefaultAzureCredential } = require("@azure/identity");90const { BlobServiceClient } = require("@azure/storage-blob");9192const client = new BlobServiceClient(93`https://${accountName}.blob.core.windows.net`,94new DefaultAzureCredential()95);96```97