Join our Newsletter — 33% off our NHI Course
Home› Guides› How to rotate Azure storage account keys and…
Guide Cloud & Workload Identity

How to rotate Azure storage account keys and move to disabled Shared Key access: rotate safely, find key users, then switch keys off

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 20 November 2026 12 min read
On this page

Azure storage account keys are long-lived shared secrets that grant access to all data in an account, so the safest end state is to rotate them now and then stop accepting them altogether. This guide gives a practical sequence: rotate key1 and key2 without an outage, set rotation reminders and policy, find every client still using Shared Key or key-signed SAS, move those clients to Microsoft Entra ID, and finally set Allow storage account key access to Disabled. The broader Azure Storage security model, including anonymous access and immutability, is covered in the Azure Storage Security Guide and is not repeated here.

Storage account keys are a classic non-human identity problem. They are not tied to a person, they do not expire by themselves, they are easy to copy into connection strings, pipelines and scripts, and anyone holding one does not need an Entra identity at all. Rotation limits how long a leaked key stays useful. Disabling Shared Key removes the class of credential entirely.

This is an independent guide from NHI Mgmt Group, based on Microsoft's public documentation as of November 2026. It is not sponsored or reviewed by Microsoft. Product features change, so confirm settings against Microsoft's current documentation.

Key takeaways

  • Every storage account has two 512-bit access keys, key1 and key2. Microsoft advises using key1 normally, reserving key2 for rotation, and using only one key across all applications at a time.
  • Regenerating a key revokes account and service SAS tokens signed with it. User delegation SAS tokens, secured with Microsoft Entra credentials, are not affected.
  • Use the Set rotation reminder feature and the built-in Azure Policy "Storage account keys should not be expired" to stop keys from ageing silently.
  • Before disabling Shared Key, find its users with the Transactions metric filtered by Authentication, or with the AuthenticationType field in storage logs.
  • When AllowSharedKeyAccess is false, Azure Storage rejects requests authorised with account keys with HTTP 403, and account and service SAS are denied for all services.
  • Azure Files and Cloud Shell need special care: the portal uses Shared Key by default for file shares.
  • Disabling Shared Key is also a prerequisite for applying Entra Conditional Access to a storage account.

Why storage account keys are a high-value credential

Microsoft's documentation describes the keys as authorising access through Shared Key, or through SAS tokens signed with the shared key. It also notes that the roles able to manage Shared Key settings (Owner, Contributor and Storage Account Contributor) include the Microsoft.Storage/storageAccounts/listkeys/action permission, which grants access to all account data through the account keys. In other words, anyone with the right management-plane role can turn that role into full data-plane access simply by listing the keys, bypassing any data-plane RBAC you have designed.

That has three consequences for identity teams. First, data-plane RBAC is only as strong as the set of people and workloads that can list keys. Second, a key copied into a script or configuration file outlives the person who copied it. Third, audit trails show the key, not the human or workload that used it, which makes investigation slow.

Before you start: inventory and permissions

Viewing keys needs the Microsoft.Storage/storageAccounts/listkeys/action permission and regenerating them needs Microsoft.Storage/storageAccounts/regeneratekey/action. Microsoft lists the Owner, Contributor and Storage Account Key Operator Service Role built-in roles as carrying them. Changing the AllowSharedKeyAccess setting needs Microsoft.Storage/storageAccounts/write or Microsoft.Storage/storageAccounts/*, assigned at the storage account level or higher.

Start with an estate-wide view. Microsoft documents an Azure Resource Graph query that lists each account's setting:

resources | where type =~ 'Microsoft.Storage/storageAccounts' | extend allowSharedKeyAccess = parse_json(properties).allowSharedKeyAccess | project subscriptionId, resourceGroup, name, allowSharedKeyAccess

Note that the property is not set by default and does not return a value until you explicitly set it. Shared Key requests are permitted when the value is null or true, so an empty result means keys are allowed. The property is supported for accounts using the Azure Resource Manager deployment model only.

For each account, record its owner, the workloads that use it, whether it hosts Azure Files shares, and where its keys are stored. NHI Mgmt Group recommends tagging accounts with a migration status (keys in use, migrating, keys disabled) so progress is visible.

Step 1: rotate keys without an outage

Microsoft's manual rotation procedure in the portal is a two-key swap:

  1. Update connection strings in your application code to reference the secondary key (key2).
  2. Go to the storage account in the Azure portal.
  3. Under Security + networking, select Access keys.
  4. Select Regenerate next to the primary key (key1).
  5. Update your code to reference the new primary key.
  6. Regenerate the secondary key in the same way.
  7. Verify by testing a connection, or by confirming the key value changed on the Access keys page.

With the Azure CLI, the same regeneration is done with az storage account keys renew --account-name <name> --resource-group <group> --key key1, where --key accepts key1, key2, primary or secondary. List current keys with az storage account keys list --account-name <name> --resource-group <group>. Treat the output as a secret: do not run it in shared terminals or pipelines that log output.

Plan for what regeneration breaks. Microsoft states that applications, Azure services and tools such as Azure Storage Explorer that use the account key must be updated, and that regenerating a key revokes SAS tokens signed with it, so account and service SAS tokens must be regenerated. User delegation SAS tokens are secured with Entra credentials and are not affected by key rotation.

Emergency rotation after a suspected leak

If a key is believed to be exposed, the order changes. Regenerate the exposed key first, accept that some clients will fail, and fix them afterwards. A planned swap protects availability; an emergency rotation protects data. If you do not know which key leaked, regenerate both, one after the other, once the clients that matter most have been pointed at the new key. The Cloud Access Key Leak Playbook covers the wider investigation.

Step 2: make rotation routine

Rotation that relies on memory does not happen. Microsoft provides two controls:

  • Rotation reminders. On the Access keys page, select Set rotation reminder, select Enable key rotation reminders, set a frequency and select Save. The reminder appears when the interval has passed without rotation. You may need to rotate each key once before the button is enabled; if it is greyed out, rotate the keys first.
  • Azure Policy. Assign the built-in policy "Storage account keys should not be expired" at a subscription or management group scope, then use View compliance. Non-compliant accounts are fixed by rotating their keys.

Microsoft also recommends storing keys in Azure Key Vault and rotating them regularly, never hard-coding them or storing them in plain text, and rotating if you suspect compromise. The Azure Key Vault Security Guide covers vault access design. Treat any key that has been in a configuration file, a ticket, a chat or a repository as compromised and rotate it.

Step 3: find every client still using Shared Key

You cannot safely disable Shared Key until you know who uses it. Microsoft warns that if any clients are currently accessing data with Shared Key, you should migrate those clients to Microsoft Entra ID before disallowing Shared Key access.

Metrics view

In the storage account, under Monitoring, select Metrics. Set Metric Namespace to Account, Metric to Transactions and Aggregation to Sum. Add a filter with Property set to Authentication and Values set to Account Key and SAS. Any non-zero line shows key-based traffic. Metrics and logs do not distinguish SAS types, so the SAS value reports all SAS types together, including user delegation SAS.

Logs view

With a diagnostic setting sending logs to a Log Analytics workspace, Microsoft provides a query to find the top callers using keys or SAS over seven days. It is shown here as an illustrative starting point:

StorageBlobLogs | where AuthenticationType in ("AccountKey", "SAS") and TimeGenerated > ago(7d) | summarize count() by CallerIpAddress, UserAgentHeader, AccountName | top 10 by count_ desc

Caller IP address and user agent usually identify the workload. Run the query over a full business cycle (month end, batch windows, backups) before you trust that you have seen every client. Repeat the exercise for the other storage services the account serves.

Step 4: move clients to Microsoft Entra ID

Microsoft recommends using Microsoft Entra ID with managed identities for blob, queue and table data whenever possible, and preferring user delegation SAS where a SAS is genuinely needed. For each client found in Step 3:

  • Azure-hosted workloads. Give the workload a managed identity and assign a narrow data-plane role on the account or container, then change the client library to use Entra authentication instead of a connection string. The Azure Managed Identities Security Guide covers design choices.
  • Workloads outside Azure. Use workload identity federation where the platform supports it, rather than a client secret. The guide How to replace Azure app secrets with federated credentials walks through the pattern.
  • Shared links. Replace account and service SAS with user delegation SAS (Blob Storage only), which is permitted when Shared Key is disallowed.
  • People and tools. Microsoft lists Entra support in the Azure portal for blob data, AzCopy for Blob Storage, Azure Storage Explorer for Blob, Queue, Table and Data Lake Storage (not File), and Azure PowerShell and Azure CLI for blob and queue. Give operators data-plane roles so they no longer need to list keys.

As each client moves, recheck the metrics view. The goal is a flat zero for Account Key, and SAS traffic that you can attribute to user delegation SAS.

Step 5: handle Azure Files and other exceptions

Microsoft's documentation calls out Azure Files explicitly. The Azure portal uses Shared Key by default to access file shares, so without the right RBAC assignments requests fail and you cannot reach file shares in the portal. Microsoft's mitigations are to authorise file data access with your Entra account, to migrate Azure Files data to a separate storage account before disallowing Shared Key, or not to apply the setting to accounts that support Azure Files workloads. Azure Cloud Shell files stored in an Azure file share become inaccessible if Shared Key authorisation is disallowed.

Anonymous requests are a separate matter: if anonymous read access is configured, those requests are not authorised and simply proceed, so disabling Shared Key does not close public containers. Deal with anonymous access as its own control.

Where an account must keep Shared Key for now, record the exception with an owner and an end date, keep rotation reminders on, restrict who holds listkeys, and keep the account in a policy scope where the audit result stays visible.

Step 6: disable Shared Key and enforce it

In the portal, go to the storage account, select Configuration under Settings and set Allow storage account key access to Disabled. Verify with:

az storage account show --name <storage-account-name> --resource-group <resource-group-name> --query "allowSharedKeyAccess"

The command returns false when Shared Key is disallowed. From then on, Microsoft states, Azure Storage rejects all subsequent requests authorised with the account access keys, returning 403 (Forbidden) with an error indicating that key-based authorisation is not permitted. Account and service SAS are denied for all Azure Storage services.

Enforce the end state with the built-in policy "Storage accounts should prevent shared key access". Start in Audit mode to identify accounts that still allow Shared Key, then edit the assignment and change Effect from Audit to Deny, so that new or modified accounts cannot re-enable keys. Microsoft notes that a policy change can take up to 30 minutes to take effect.

Once Shared Key is disallowed on an account, you can apply Entra Conditional Access policies to it, which Microsoft states requires disallowing Shared Key. That lets storage access sit inside the same identity controls as the rest of your estate.

Rollback

If a critical client fails after the change, the 403 error tells you the cause. Setting the property back to Enabled restores key access, but treat that as a time-boxed exception: rotate both keys when you re-disable, because the period with keys allowed is a period in which old copies worked.

Common failure patterns

  • Both keys in use. Different applications use key1 and key2, so there is no safe key to rotate to. Consolidate on one key first.
  • Forgotten SAS. Key rotation silently breaks account and service SAS links handed to partners, and the business pushes to undo it.
  • Short observation window. A week of logs misses month-end jobs, which then fail with 403 after Shared Key is disabled.
  • Diagnostic logs not enabled. Without a diagnostic setting there is no caller data, only metric counts.
  • Azure Files surprise. Shared Key is disabled on an account hosting file shares and portal access and Cloud Shell storage stop working.
  • Audit without Deny. The policy reports non-compliance forever but nothing stops new accounts being created with keys allowed.
  • Listkeys sprawl. Contributor is granted widely, so many identities can still extract keys from accounts that have not yet been migrated.

Practitioner checklist

  • Run the Resource Graph query and list every account where allowSharedKeyAccess is null or true.
  • Consolidate each account's clients on a single key, then rotate key1 and key2 using the two-key swap.
  • Regenerate any account or service SAS you still need, or replace it with user delegation SAS.
  • Enable rotation reminders and assign "Storage account keys should not be expired".
  • Enable diagnostic logs and review Account Key and SAS traffic over a full business cycle.
  • Move each client to managed identities, federated credentials or user delegation SAS.
  • Decide the approach for accounts hosting Azure Files before disabling keys.
  • Set Allow storage account key access to Disabled and verify the CLI returns false.
  • Assign "Storage accounts should prevent shared key access" in Audit, then switch to Deny.
  • Reduce who holds listkeys, and apply Conditional Access to accounts that no longer allow Shared Key.

Standards and references

Related NHI Mgmt Group resources: Azure Storage Security Guide · Azure Managed Identities Security Guide · Azure Key Vault Security Guide · Cloud Access Key Leak Playbook

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.