Lesson 4 of 5 Securing Access to Azure Storage

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.

Select all that apply

Who can list the keys?

Exam skills 2.1.4

Select every built-in role that can list a storage account's access keys.

Log in to try this activity Interactive activities are free with an account.

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.

  1. Switch to key2

    Update every application and connection string that uses key1 to use key2.

  2. Regenerate key1

    On the Access keys page, select Rotate key for key1 (or az storage account keys renew --key primary).

  3. Switch back

    Update applications to use the new key1.

  4. 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 storage account keys without an outage. The application used key1 and partner SAS tokens were signed with it, so regenerating key1 broke both. Switch the application to key2 first, then regenerate key1; issue partner tokens tied to stored access policies or as user delegation SAS; and longer term give the app a managed identity.
The scenario is illustrative.
Put in order

Rotating the keys

Exam skills 2.1.4

Arrange the key rotation steps so that no application loses access.

Log in to try this activity Interactive activities are free with an account.

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.

Sort into groups

After disabling Shared Key

Exam skills 2.1.4 · 2.1.2

Allow storage account key access is set to Disabled. Decide whether each request still works.

Log in to try this activity Interactive activities are free with an account.
Worked example

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.

Check yourself

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.