Manage and Rotate Storage Access Keys
30-second answer
Every storage account has two 512-bit access keys, key1 and key2. Either key gives full access to all data, so treat them like a root password. Two keys exist so you can rotate without downtime: move apps to key2, regenerate key1, then later do the reverse. A key expiration policy (rotation reminder) flags keys older than a set number of days, but doesn't rotate them. Regenerating a key also breaks every SAS signed with it. The safest end state is Microsoft Entra ID with Allow storage account key access set to Disabled.
Simulate it » No Azure account neededExam objective: 2.1.4 Manage access keys. (Skills measured as of April 17, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
Under <strong>Security + networking</strong> open <strong>Access keys</strong>. You need a role with the listKeys action (Owner, Contributor or Storage Account Key Operator Service Role). Reader can’t see them.
👆 Click the glowing item in the portal to continue
Read the steps as text
- Under Security + networking open Access keys. You need a role with the listKeys action (Owner, Contributor or Storage Account Key Operator Service Role). Reader can’t see them.
- Two keys, both 412 days old. Either one gives full control of every bit of data. Start with Set rotation reminder.
- Turn on reminders every 90 days. This sets the key expiration policy: Azure flags old keys, it doesn’t rotate them for you.
- Safe order: move apps to key2 first, then Rotate key on key1.
- key1 is new. Every connection string and SAS signed with the old key1 now fails. Next time, move apps back to key1 and rotate key2.
- The end goal: once every app uses Microsoft Entra ID, set Allow storage account key access to Disabled under Configuration. Then a leaked key is useless.
🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.
🖱️ Drag to rotate · scroll or pinch to zoom
Rotate access keys
Each account has two keys so you can rotate without downtime: move apps to key2, regenerate key1, and next time do the reverse. A key expiration policy flags old keys. Regenerating a key kills every SAS signed with it.
🤔 What happens if…
Read this tour as text
- The front door: the storage firewall. Every account has a public endpoint that accepts all networks by default. Set the default action to Deny and only what you list gets in: virtual network rules (subnets with the Microsoft.Storage service endpoint), IP rules (public addresses only) and trusted Azure services if you tick the exception.
- Three ways in, plus one for file shares. Callers prove who they are with an account key (full control), a SAS (limited rights for limited time) or a Microsoft Entra ID token checked against RBAC data roles. For SMB file shares, users bring a Kerberos ticket from AD DS, Microsoft Entra Domain Services or Microsoft Entra Kerberos.
- SAS tokens and stored access policies. A service SAS can point at a stored access policy on the container (up to 5 per container). The policy holds the permissions and expiry, so deleting or editing it revokes every SAS that names it. An ad hoc SAS can only be revoked by regenerating the key that signed it.
- Rotate access keys. Each account has two keys so you can rotate without downtime: move apps to key2, regenerate key1, and next time do the reverse. A key expiration policy flags old keys. Regenerating a key kills every SAS signed with it.
- Encryption at rest. Azure Storage always encrypts data with AES-256. By default Microsoft manages the key. With a customer-managed key in Key Vault (soft delete and purge protection on), the account’s managed identity wraps and unwraps its data key with your key, and you can revoke it.
- Redundancy and a region outage. LRS keeps 3 copies in one datacenter, ZRS spreads 3 across availability zones, GRS adds an async copy in the paired region and GZRS combines both. RA- versions let you read the secondary. A customer-managed failover promotes the secondary when the primary region is down.
- Moving data: AzCopy and object replication. AzCopy moves files in parallel from the command line, signed in with Microsoft Entra ID (and a Storage Blob Data role) or with a SAS. Storage Explorer does the same with a GUI. Object replication keeps copying new block blobs to another account by itself.
- Access tiers and lifecycle management. Blobs sit in Hot, Cool (30-day minimum), Cold (90 days) or Archive (180 days, offline). A lifecycle management rule moves or deletes blobs by age or last access, about once a day. Reading an archived blob means rehydrating it first.
- Undo buttons: soft delete, versioning and snapshots. Blob soft delete and container soft delete keep deleted items for 1 to 365 days. Versioning keeps every previous version of a blob. For Azure Files, share snapshots are read-only point-in-time copies and share soft delete keeps a deleted share.
Contoso keeps invoices in a storage account that anyone on the internet can reach with the right key. Close the front door, let only the app subnet and the office in, hand auditors a SAS you can revoke on your own terms, then rotate a key the safe way.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
The same storage key has sat in five apps for two years.
😊 THE SOLUTION
Rotate with two keys, get reminders, then move to Entra ID.
- Keys never change✓ Key expiration policy
- Rotation breaks apps✓ Swap to key2 first
- Keys leak✓ Disable key access
Start with a question
How do you change the locks on a shop without closing it for a day?
A shop with one front door has a problem: changing the lock means the door is out of use for a while. A shop with two doors doesn’t. You send everyone through the side door, change the front lock, hand out the new key, and next month you do it the other way round.
A storage account has two access keys for the same reason. Your apps use one while you regenerate the other.
Explain it like I’m 10
The technical explanation
Each account gets two 512-bit keys when it’s created. A request signed with either key (Shared Key authorization) can read, write and delete anything in the account. Connection strings contain a key. Account SAS and service SAS tokens are signed with a key too, so they live and die with it.
Who can see the keys
Listing keys uses the Microsoft.Storage/storageAccounts/listkeys/action permission. Owner, Contributor, Storage Account Contributor and Storage Account Key Operator Service Role have it. Reader doesn’t. Anyone who can list keys can read all the data, so treat that permission as a data permission.
Rotate without downtime
- Update every app to use key2 (ideally by changing one secret in Azure Key Vault).
- Regenerate key1: portal Access keys > Rotate key on key1, or
az storage account keys renew --key primary. - Next rotation, move apps back to key1 and regenerate key2.
If you regenerate the key an app is still using, that app gets 403 errors until you fix it, and every SAS signed with that key is dead.
Rotation reminders
Set rotation reminder on the Access keys blade creates a key expiration policy: keys older than, say, 90 days are flagged in the portal, and Azure Policy can report non-compliant accounts. It’s a reminder, not automation.
Turn keys off
Once apps use Microsoft Entra ID, go to Settings > Configuration and set Allow storage account key access to Disabled. Then any request signed with a key, and any account or service SAS, is refused. User delegation SAS and Entra ID keep working. Check first: old tools that only know keys will break.
az storage account keys list -g rg-storage-prod -n stcontosoprod -o table
az storage account keys renew -g rg-storage-prod -n stcontosoprod --key primary
az storage account update -g rg-storage-prod -n stcontosoprod --key-exp-days 90
az storage account update -g rg-storage-prod -n stcontosoprod --allow-shared-key-access false
Get-AzStorageAccountKey -ResourceGroupName rg-storage-prod -Name stcontosoprod
New-AzStorageAccountKey -ResourceGroupName rg-storage-prod -Name stcontosoprod -KeyName key1
Set-AzStorageAccount -ResourceGroupName rg-storage-prod -Name stcontosoprod -AllowSharedKeyAccess $false
Architect level Keys in Key Vault, and rotating automatically
Put the connection string in Key Vault and have apps read it at start-up through a managed identity. Rotation then means updating one secret. To automate it, a common pattern is an Azure Function triggered on a schedule (or by Key Vault’s near-expiry event) that regenerates the inactive key, writes it to Key Vault as a new secret version, then flips which key is active. Even better is dropping keys for Microsoft Entra ID altogether.
Real-world business scenario
Northwind Logistics (fictional)
- The problem
- The same storage key had sat in five apps and two scripts for over a year, and nobody dared rotate it.
- What they used
- The team moved the connection string into Azure Key Vault, switched every app to key2, regenerated key1, set a 90-day rotation reminder, and planned the move to managed identities.
- Why that choice
- Rotating through the second key meant zero downtime, and the reminder makes old keys show up before an audit does.
- The result
- Rotation now takes ten minutes, and the three apps already on managed identities don't need keys at all.
When to use it and when not to
✓ Use it when…
- A tool or legacy app only supports Shared Key, and you keep the key in Key Vault.
- Admins mount an Azure Files share with the key to set Windows ACLs.
- You need to kill every key-signed SAS at once by regenerating the key.
✕ Think twice when…
- Your own apps can use managed identities and RBAC data roles.
- You plan to hand the key to partners (give a SAS instead).
- Compliance requires no shared secrets (disable key access).
↔ Alternatives to consider
- Microsoft Entra ID with Storage Blob Data roles and managed identities.
- User delegation SAS for delegated, time-limited access with no key.
Test yourself with exercises
5 original practice questions in the AZ-104 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.
Interview preparation
Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.
Beginner Why does a storage account have two keys?
Model answer
So you can rotate them without downtime. Apps use one key while you regenerate the other. Then you switch the apps over and regenerate the first. If there were only one key, every rotation would be an outage.
Intermediate A support engineer with the Reader role can't see the access keys. Is that a bug?
Model answer
No. Listing keys needs the listKeys action, which Reader doesn't have. Owner, Contributor, Storage Account Contributor and Storage Account Key Operator Service Role have it. Reader and Data Access is another option if they only need to read data through the portal.
Experienced developer What does a key expiration policy actually do?
Model answer
It records how many days a key may live. The portal shows a rotation reminder and Azure Policy or Azure Monitor can flag accounts whose keys are older than that. It doesn't rotate anything for you. For automatic rotation you'd script it, for example with an Azure Automation runbook or an Event Grid triggered function, and keep the current value in Key Vault.
Scenario A key was pasted into a public chat. Walk me through the next ten minutes.
Model answer
Find out which key it was. If the apps use the other key, regenerate the leaked one straight away. If the apps use the leaked key, swap them to the other key in Key Vault or their settings first, then regenerate. Check that SAS tokens signed with that key are reissued. Then review the storage logs for unusual reads and plan the move to Microsoft Entra ID so this can't happen again.
Quick revision
Key points
- Portal path: storage account > Security + networking > Access keys.
- Two keys, each with full access. Rotate one at a time.
- Regenerating a key invalidates every connection string and SAS signed with it.
- Set rotation reminder = key expiration policy (CLI: --key-exp-days).
- Store keys in Azure Key Vault, never in code.
- Disabling Shared Key access stops keys, account SAS and service SAS. Entra ID and user delegation SAS keep working.
Important terminology
- Storage account access key
- One of two 512-bit keys that authorize any request to the account with Shared Key, giving full access to all data.
- Shared Key authorization
- Signing each request with an account key. Account SAS and service SAS tokens are also signed this way.
- Key rotation
- Regenerating an access key so the old value stops working.
- Key expiration policy
- An account setting (keyExpirationPeriodInDays) that marks keys as due for rotation after a number of days, shown as a rotation reminder.
- Allow storage account key access
- An account setting that, when disabled, refuses every request signed with an account key, including account and service SAS.
- Storage Account Key Operator Service Role
- A built-in role that lets a principal list and regenerate keys without other management rights.
Common mistakes
- Regenerating the key that apps are still using.
- Expecting the key expiration policy to rotate keys automatically.
- Giving Reader and expecting the person to see keys.
Exam tips
- "Rotate without downtime" = switch apps to the other key, then regenerate.
- "Prevent any use of account keys" = set Allow storage account key access to Disabled.
- "Let a script rotate keys but nothing else" = Storage Account Key Operator Service Role.
Five quick revision questions
-
1.How many access keys does a storage account have?Show
Two (key1 and key2).
-
2.Which CLI command regenerates key1?Show
az storage account keys renew --key primary
-
3.What happens to a SAS signed with key1 after key1 is regenerated?Show
It stops working.
-
4.Does the key expiration policy rotate keys?Show
No, it only flags keys as due for rotation.
-
5.Which authorization still works when Shared Key access is disabled?Show
Microsoft Entra ID (and user delegation SAS).
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: Identity-Based Access for Azure Files
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.