Protecting and Rotating Storage Account Keys
Account access keys grant full access to storage data. This lesson explains what they allow, how to rotate them safely and how to disable them.
Learning outcomes
After completing this lesson, you will be able to:
- Explain what account access keys allow and who can list them.
- Describe the steps of key rotation without downtime.
- Explain the effect of disabling storage account key access.
What the keys allow
Each storage account has two 512-bit access keys, key1 and key2. A key authorizes requests with Shared Key authorization, which grants full access to all data in the account, and signs service and account SAS tokens. Connection strings embed a key. Keys are shown on the account's Access keys page to principals with the Microsoft.Storage/storageAccounts/listkeys/action permission, which Owner, Contributor, Storage Account Contributor and Storage Account Key Operator Service Role have.
Because a key gives unrestricted access, it should be stored in Azure Key Vault rather than in code or configuration files, and applications should prefer Microsoft Entra ID authorization with managed identities. Granting someone Contributor on a storage account effectively grants full data access, because they can list the keys.
Who can list the keys?
Rotating keys without downtime
Two keys exist so that one can be rotated while the other is in use. The safe sequence is shown below.
-
Switch to key2
Update every application and connection string that uses key1 to use key2.
-
Regenerate key1
On the Access keys page, select Rotate key for key1 (or
az storage account keys renew --key primary). -
Switch back
Update applications to use the new key1.
-
Regenerate key2
Rotate key2 so that the old value is no longer valid.
Regenerating a key immediately invalidates it, including every SAS signed with it. A key expiration policy sets a reminder interval (in days), and Azure Policy and Azure Advisor can flag accounts whose keys are older than that. Key Vault can store the keys and rotate them with an Event Grid-triggered function.
The following diagram shows a key rotation order that avoids an outage for an application and partners that use storage account keys.

Rotating the keys
Disabling Shared Key authorization
Setting Allow storage account key access to Disabled on the account's Configuration page blocks all requests authorized with the account key, including service and account SAS tokens. Only Microsoft Entra ID authorization and user delegation SAS tokens continue to work. Before disabling, check with Azure Monitor logs that no clients still use Shared Key, and set Default to Microsoft Entra authorization in the Azure portal so that administrators browse data with their own roles. Some services and tools that require keys, such as some Azure Files scenarios, may stop working.
After disabling Shared Key
A rotation that caused an outage
An administrator regenerated key1 as part of quarterly rotation. Immediately afterwards, a web application and a partner's SAS tokens stopped working. How should rotation be performed in future to avoid this, and what longer-term change reduces the risk?
The application used key1 and the partner's SAS tokens were signed with it, so regenerating it invalidated both. In future, switch the application to key2 first, regenerate key1, and issue partner tokens tied to stored access policies or as user delegation SAS. Longer term, give the web app a managed identity with a Storage Blob Data role and disable storage account key access.
Why does Contributor on a storage account effectively grant full data access?
Show answer
Because Contributor can list the account keys, and a key authorizes every data operation.
Exam Tips
Remember for the exam
- Rotate keys one at a time, moving applications to the other key first.
- Regenerating a key invalidates every SAS signed with it.
- Contributor can list keys, which grants full data access.
- Disabling storage account key access forces Microsoft Entra ID or user delegation SAS.