Storage Access
Access keys · SAS · stored access policies · firewalls and virtual networks · anonymous access
By the tools4free.dev team · Last reviewed November 13, 2026
Practice questions for this topic →
Access keys
- Every account has two 512-bit keys (key1 and key2). They give full access through Shared Key and can sign SAS tokens.
- Use one key in apps at a time. Keep the other for rotation.
- Viewing keys needs
Microsoft.Storage/storageAccounts/listkeys/action. Rotating needs.../regeneratekey/action. Roles with both: Owner, Contributor, Storage Account Key Operator Service Role. - Regenerating a key revokes every account SAS and service SAS signed with it. A user delegation SAS isn't affected.
- Key expiration policy is a rotation reminder (portal Set rotation reminder). You may need to rotate both keys once before you can set it. Azure Policy built-in: Storage account keys should not be expired.
- Microsoft recommends Microsoft Entra ID with managed identities over keys, and Key Vault to hold any keys you keep.
| Rotation step | Action |
|---|---|
| 1 | Point apps at key2 |
| 2 | Regenerate key1 |
| 3 | Point apps at the new key1 |
| 4 | Regenerate key2 |
| 5 | Verify the apps |
Disallow Shared Key
- Set Allow storage account key access to Disabled (
AllowSharedKeyAccess=false). The property is null by default, which means allowed. - Requests authorized with an account key get 403. Service SAS and account SAS are denied because they are Shared Key signed. User delegation SAS still works.
- You must disallow Shared Key to apply Conditional Access to storage requests.
- Needs
Microsoft.Storage/storageAccounts/write(Owner, Contributor, Storage Account Contributor). - Side effects: portal browsing of file shares and Cloud Shell's file share need Entra authorization. Storage Explorer and Entra for file shares: Microsoft's pages differ. The Shared Key page says Entra access to File storage isn't supported in Storage Explorer, while the Storage Explorer page lists file shares as supporting Entra ID. Entra for Blob, Queue, Table and Data Lake is supported on both. Don't rely on Entra for Azure Files in Storage Explorer.
SAS types
| Type | Signed with | Scope | Stored access policy? |
|---|---|---|---|
| User delegation SAS | Entra credentials (user delegation key) | Blob, Data Lake, Queue, Table, Azure Files (the Shared Key page lists Blob Storage only) | No |
| Service SAS | Account key | One storage service | Yes |
| Account SAS | Account key | One or more services, plus service-level operations | No |
- Microsoft recommends the user delegation SAS for best security.
- To create one, the principal needs a role with
Microsoft.Storage/storageAccounts/blobServices/generateUserDelegationKey, such as Storage Blob Data Contributor, at account, resource group or subscription scope. - The user delegation key and the SAS are valid for at most 7 days. Revoke with
az storage account revoke-delegation-keys(caching can delay it). - A SAS is a token appended to the URI. An invalid or expired SAS returns 403. Azure doesn't track a SAS, so you can't audit its creation.
- A SAS is required to authorize the source of a copy in some scenarios, such as blob to blob or file to file across accounts.
- Best practice: HTTPS only, least privilege, short expiry for ad hoc SAS, and a stored access policy for service SAS. Set the start time at least 15 minutes in the past, or omit it, to avoid clock skew.
Stored access policies
- Defined on a blob container, file share, queue or table. Maximum 5 per resource. A sixth returns 400.
- The signed identifier is up to 64 characters. The policy sets start, expiry and permissions. You can't give the same parameter on both the SAS and the policy.
- Changes can take up to 30 seconds to take effect.
- Revoke a SAS tied to a policy by deleting the policy, renaming its identifier, or setting its expiry in the past. This doesn't touch the account keys.
- Order: create the policy on the container, then generate a service SAS that references the policy identifier.
SAS expiration policy is different. It's an account setting that sets the upper limit on SAS validity (format <days>.<hours>:<minutes>:<seconds>, for example 1.12:05:06). The action is Log (default, audit only) or Block. A signed start field becomes required. Azure File Sync needs at least 3 days.
Firewalls and virtual networks
- By default the account accepts connections from any network. Rules apply only once the default action is Deny.
- Four rule types: virtual network rules, IP network rules, resource instance rules, trusted service exceptions.
- VNet rules need a service endpoint on the subnet:
Microsoft.Storage(same-region accounts) orMicrosoft.Storage.Global(any region), one per subnet. The portal creates the endpoint for you. CLI and PowerShell don't. - Adding a VNet rule needs Storage Account Contributor, or a custom role with
Microsoft.Network/virtualNetworks/subnets/joinViaServiceEndpoint/action. For a subnet in another tenant, use CLI or PowerShell with the full subnet ID. - Deleting a subnet removes its rule. A new subnet with the same name has no access until you add it again.
- IP rules accept public IPv4 only, as single IPs or CIDR such as
16.17.18.0/24. Private ranges (10.x, 172.16-31.x, 192.168.x) aren't allowed, and /31 and /32 aren't supported. They have no effect on requests from the account's own region: use VNet rules. - Once a subnet has a service endpoint, its traffic uses private IPs, so IP rules for that subnet stop applying.
- For ExpressRoute, allow the NAT public IPs used for Microsoft peering.
- The firewall governs the data plane only, not Azure Resource Manager management operations. Portal, Storage Explorer and AzCopy data access must come from inside the allowed boundary.
- Exceptions (
--bypass AzureServices Logging Metrics;Noneremoves them) let trusted services and logging through. Trusted service access takes highest precedence. - Network rules have no effect until the default action is Deny, so Microsoft says to grant access to the networks your apps use (or set up a private endpoint) before you set Deny.
Anonymous access
| Level | Anonymous clients can |
|---|---|
| Private (default) | Nothing |
| Blob | Read a blob if they know its URL; can't list |
| Container | List and read |
- Anonymous access is never allowed by default. The account property Allow Blob anonymous access set to Disabled overrides every container level.
- The level is set per container, not per blob. Setting it needs the key, a connection string or a SAS (Entra isn't supported for Set Container ACL).
- The
$webcontainer stays public. Changes take up to 30 seconds.
CLI and PowerShell
| Task | Azure CLI | PowerShell |
|---|---|---|
| List keys | az storage account keys list --resource-group <rg> --account-name <n> | Get-AzStorageAccountKey -ResourceGroupName <rg> -Name <n> |
| Regenerate a key | az storage account keys renew --resource-group <rg> --account-name <n> --key primary | New-AzStorageAccountKey -ResourceGroupName <rg> -Name <n> -KeyName key1 |
| Disallow Shared Key | az storage account update --name <n> --resource-group <rg> --allow-shared-key-access false | Set-AzStorageAccount -ResourceGroupName <rg> -AccountName <n> -AllowSharedKeyAccess $false |
| User delegation SAS (blob) | az storage blob generate-sas --account-name <n> --container-name <c> --name <b> --permissions acdrw --expiry <dt> --auth-mode login --as-user --full-uri | - |
| Revoke user delegation keys | az storage account revoke-delegation-keys --name <n> --resource-group <rg> | - |
| Stored access policy | az storage container policy create --container-name <c> --name <p> --permissions <rwdl> --start <dt> --expiry <dt> --account-name <n> | - |
| SAS expiration policy | az storage account update --name <n> --resource-group <rg> --sas-exp 1.12:05:06 --sas-expiration-action Block | Set-AzStorageAccount ... -SasExpirationPeriod 1.12:05:06 -SasExpirationAction Block |
| Default action Deny | az storage account update -g <rg> -n <n> --default-action Deny | Update-AzStorageAccountNetworkRuleSet -ResourceGroupName <rg> -Name <n> -DefaultAction Deny |
| Service endpoint on a subnet | az network vnet subnet update -g <rg> --vnet-name <v> --name <s> --service-endpoints "Microsoft.Storage.Global" | Set-AzVirtualNetworkSubnetConfig ... -ServiceEndpoint "Microsoft.Storage.Global", then Set-AzVirtualNetwork |
| Add a VNet rule | az storage account network-rule add -g <rg> --account-name <n> --subnet <subnetId> | Add-AzStorageAccountNetworkRule -ResourceGroupName <rg> -Name <n> -VirtualNetworkResourceId $subnet.Id |
| Add an IP rule | az storage account network-rule add -g <rg> --account-name <n> --ip-address "16.17.18.0/24" | Add-AzStorageAccountNetworkRule -ResourceGroupName <rg> -AccountName <n> -IPAddressOrRange "16.17.18.0/24" |
| Set exceptions | az storage account update -g <rg> -n <n> --bypass Logging Metrics AzureServices | Update-AzStorageAccountNetworkRuleSet -ResourceGroupName <rg> -Name <n> -Bypass AzureServices,Metrics,Logging |
| Block anonymous access | az storage account update ... --allow-blob-public-access false | -AllowBlobPublicAccess $false |
| Container access level | az storage container set-permission --name <c> --account-name <n> --public-access container|blob|off --auth-mode key | Set-AzStorageContainerAcl -Container <c> -Permission Container -Context $ctx |
Exam Tips
Tick each tip once you can answer it without looking.
“Revoke a service SAS without regenerating account keys” → Delete or modify the stored access policy it references. Trap: regenerating keys works but breaks everything signed with the key.
“Six different SAS scenarios, six stored access policies on one container” → Not possible: the maximum is 5 per container (a sixth returns 400). Trap: unlimited policies.
“Rotate keys without app downtime” → Switch apps to key2, regenerate key1, switch to key1, regenerate key2. Trap: regenerating both at once.
“Let a user view and regenerate keys without full Contributor” → Storage Account Key Operator Service Role. Trap: Storage Blob Data Contributor is data plane only.
“Most secure SAS, no account key” → User delegation SAS (Entra ID). Trap: account SAS.
“Shared Key is disallowed: which SAS still works?” → User delegation SAS. Trap: service SAS and account SAS are key-signed.
“Require Conditional Access for storage requests” → Disallow Shared Key authorization. Trap: firewall rules don't apply Conditional Access.
“Principal must create a user delegation SAS” → A role with generateUserDelegationKey, such as Storage Blob Data Contributor. Trap: Reader has no such action.
“User delegation SAS set to expire in 30 days” → Not possible: 7 days at most.
“SAS fails intermittently in the first minutes after creation” → Clock skew: start the SAS at least 15 minutes in the past, or omit the start time. Trap: wrong permissions.
“Firewall rules configured but the account is still open to all networks” → Set the default action to Deny. Trap: adding more IP rules.
“Allow a VM subnet in the same region through the firewall” → Enable the Microsoft.Storage service endpoint and add a VNet rule. Trap: an IP rule with the VM's private IP: private ranges aren't allowed.
“Add the on-premises range 10.0.0.0/8 to IP rules” → Not allowed: private ranges can't be used.
“Azure Monitor or another trusted service must reach the account behind the firewall” → Network exceptions (AzureServices, Logging, Metrics). Trap: adding its public IP when it runs in the same region.
“Add a subnet from a VNet in another Entra tenant” → Use CLI or PowerShell with the full subnet resource ID. Trap: the portal doesn't list cross-tenant subnets.
“Storage Explorer can't read blobs behind the firewall but the portal shows the account” → The firewall is data plane: the client must be inside the allowed boundary. Trap: a control-plane permission problem.
“Stop all SAS tokens that outlive the policy limit” → SAS expiration policy with the Block action. Trap: the Log action only records violations.
“Subnet deleted and recreated with the same name; access lost” → Its rule was removed: add the new subnet again. Trap: the rule restoring itself by name.
“Account disallows anonymous access; a container is set to Container” → Still no anonymous access: the account setting wins. Trap: the container level wins.
“Anonymous users must read a blob by URL but not list the container” → Container access level Blob. Trap: Container also allows listing.
Sources
- Manage account access keys
- Grant limited access with SAS
- Define a stored access policy
- Prevent Shared Key authorization
- Create a user delegation SAS (CLI)
- SAS expiration policy
- Firewall rules and network access
- Firewall guidelines and limitations
- Create a virtual network rule
- Create an IP network rule
- Manage network security exceptions
- Configure anonymous read access
Checked against Microsoft Learn on November 13, 2026.