Home / Azure

AzureChecklistAdvanced

Disabling Shared Key access on Azure Storage: a rollout checklist that finds key and SAS callers before they break

Find every client still using account keys or SAS, move it to Entra ID, then set allowSharedKeyAccess to false and enforce it with Azure Policy without a 403 outage.

Deepak Bhardwaj8 min read

Applies toAzure Storage (StorageV2, BlockBlobStorage, FileStorage) on Azure Resource Manager; Azure CLI 2.20.0+; Az.Storage 3.4.0+

The goal is to turn off account-key authorization on a storage account so that a leaked key or account SAS is useless. Once allowSharedKeyAccess is false, every request signed with the account key gets 403 Forbidden. Service SAS and account SAS fail too, on every storage service. If you flip the setting before you know who is still using keys, you cause the outage yourself.

Work through this checklist per account, or per ring of accounts. It covers inventory, finding callers, migrating them, the switch, and enforcement.

Caution

Disabling Shared Key breaks any client that authenticates with a connection string containing AccountKey=, an account SAS or a service SAS. That includes some Azure services and portal features. Do not change production accounts until the caller queries below have shown zero key/SAS traffic for at least one full business cycle (month-end jobs included).

1. Inventory: which accounts still allow Shared Key

The allowSharedKeyAccess property is not set by default. Null and true both mean Shared Key is allowed. Only false means it is blocked.

// Azure Resource Graph
resources
| where type =~ 'Microsoft.Storage/storageAccounts'
| extend allowSharedKeyAccess = tostring(properties.allowSharedKeyAccess)
| where allowSharedKeyAccess != 'false'
| project subscriptionId, resourceGroup, name, kind, location, allowSharedKeyAccess
| order by subscriptionId, name
az graph query -q "resources | where type =~ 'Microsoft.Storage/storageAccounts' | where tostring(properties.allowSharedKeyAccess) != 'false' | project name, resourceGroup, subscriptionId, kind" --first 1000 -o table
  • Export the list and tag each account with an owner.
  • Mark accounts that host Azure Files shares, Function App content shares or Cloud Shell storage. They need special handling (section 4).
  • Start with accounts that have the fewest callers, such as log archives or backup targets, not the busiest app account.

2. Turn on resource logs before you look for callers

You need per-request authentication data. Send blob, queue, table and file logs to Log Analytics with a diagnostic setting on each service sub-resource. Without them the KQL in the next step returns nothing.

SA_ID=$(az storage account show -n <account> -g <rg> --query id -o tsv)
WS_ID=<log-analytics-workspace-resource-id>

for svc in blobServices queueServices tableServices fileServices; do
  az monitor diagnostic-settings create \
    --name shared-key-audit \
    --resource "$SA_ID/$svc/default" \
    --workspace "$WS_ID" \
    --logs '[{"category":"StorageRead","enabled":true},{"category":"StorageWrite","enabled":true},{"category":"StorageDelete","enabled":true}]'
done
  • Leave logging on for at least 7 days, longer if monthly batch jobs touch the account.
  • For a quick first look without logs, open the account in Metrics: namespace Account, metric Transactions, aggregation Sum, and filter or split by the Authentication dimension. The values you care about are Account Key and SAS.

3. Find who still uses keys or SAS

This is the query from the Microsoft guidance, extended to all four services:

union StorageBlobLogs, StorageQueueLogs, StorageTableLogs, StorageFileLogs
| where TimeGenerated > ago(7d)
| where AuthenticationType in ("AccountKey", "SAS")
| summarize Requests = count(), LastSeen = max(TimeGenerated),
            Operations = make_set(OperationName, 10)
    by AccountName, AuthenticationType, CallerIpAddress, UserAgentHeader
| order by Requests desc

Map each row to an owner. The user agent string usually gives it away:

User agent / pattern Likely caller Move it to
azsdk-net-Storage.Blobs/..., azsdk-python-storage-blob/... App code using a connection string DefaultAzureCredential plus a managed identity with Storage Blob Data role
AzCopy/... Scripts or scheduled copies azcopy login --identity or AZCOPY_AUTO_LOGIN_TYPE set to MSI or AzCLI
Microsoft Azure Storage Explorer People browsing data Sign in with Entra ID (works for blob, queue, table and ADLS; not for Files)
AzureCLI/... with AccountKey Scripts calling az storage without --auth-mode login Add --auth-mode login and grant a data-plane role
Azure service IPs, Function host user agents Function App AzureWebJobsStorage, Logic Apps, Data Factory linked services Identity-based connections or managed identity on the linked service
SAS from partner IPs Shared links given to third parties User delegation SAS (blob only) or a separate account

Note

Logs and metrics do not tell you which kind of SAS was used. User delegation SAS is signed with Entra credentials and keeps working after the switch, but it still shows up as SAS. Check the caller's code or the token (skoid/sktid fields mean user delegation) before you count it as a blocker.

  • Every row has an owner and a migration ticket.
  • Re-run the query after each fix and confirm that caller's rows stop.

4. Migrate the callers

App code and scripts:

# Grant a data-plane role to the app's managed identity
az role assignment create \
  --assignee-object-id <principal-id> --assignee-principal-type ServicePrincipal \
  --role "Storage Blob Data Contributor" --scope "$SA_ID"

# Scripts: stop using keys
az storage blob list --account-name <account> --container-name logs --auth-mode login -o table

# Generate a user delegation SAS instead of a service SAS
az storage blob generate-sas --account-name <account> --container-name exports --name report.csv \
  --permissions r --expiry 2026-12-06T00:00Z --auth-mode login --as-user --https-only

Function Apps that use AzureWebJobsStorage: replace the connection string with an identity-based connection (AzureWebJobsStorage__accountName = <account>) and grant the Function's identity the blob, queue and table roles its triggers need. On plans that keep app content on an Azure Files share (WEBSITE_CONTENTAZUREFILECONNECTIONSTRING), that share is mounted with a key. Keep that content account out of scope, or move the app to a plan that doesn't need a content share. Check the current Functions documentation for your plan.

Azure Files: the portal uses Shared Key for file shares by default, and SMB mounts with the storage key will fail. Either set up identity-based access (Entra Kerberos or AD DS plus share-level RBAC) first, move the shares to a separate account, or leave Files accounts out of this rollout.

Warning

Cloud Shell storage becomes inaccessible when Shared Key is disallowed. Exclude Cloud Shell accounts (usually cs* accounts in a cloud-shell-storage-* resource group) from policy and from the switch.

  • Portal users have a data-plane role (Storage Blob Data Reader or higher). Without it they lose the data view after the switch, even as Owner.
  • On the account's Configuration page, set Default to Microsoft Entra authorization in the Azure portal to Enabled and test with a normal admin account.

5. Make the switch

Do one account, then wait a day before the next ring.

az storage account update -n <account> -g <rg> --allow-shared-key-access false
az storage account show -n <account> -g <rg> --query allowSharedKeyAccess

PowerShell:

Set-AzStorageAccount -ResourceGroupName <rg> -Name <account> -AllowSharedKeyAccess $false

Then watch for failures for an hour:

union StorageBlobLogs, StorageQueueLogs, StorageTableLogs, StorageFileLogs
| where TimeGenerated > ago(1h) and AccountName == "<account>"
| where StatusCode == 403
| summarize count() by AuthenticationType, StatusText, CallerIpAddress, UserAgentHeader

Tip

Rollback is one command: az storage account update -n <account> -g <rg> --allow-shared-key-access true. Keep it in the change record. Don't rotate the account keys during the same change, or rolling back won't help callers that cached the old key.

  • No unexpected 403s for the next business cycle.
  • Once the switch has held, rotate both keys anyway (az storage account keys renew --key primary then secondary), so any copies that leaked earlier are dead too.

6. Enforce it so new accounts stay compliant

Assign the built-in policy Storage accounts should prevent shared key access in Audit first, review compliance, then change the assignment's effect parameter to Deny. Policy changes can take up to 30 minutes to apply.

DEF=$(az policy definition list --query "[?displayName=='Storage accounts should prevent shared key access'].name" -o tsv)
az policy assignment create --name deny-storage-shared-key \
  --policy "$DEF" --scope /subscriptions/<sub-id> \
  --params '{"effect":{"value":"Audit"}}'
  • Add exemptions for Cloud Shell, Function content-share accounts and Files accounts that are still waiting on identity-based access.
  • Update your Bicep or Terraform modules to set allowSharedKeyAccess: false so new accounts are created without key access. Check that your Terraform provider version and configuration can still manage data-plane settings without a key.

Prevent it next time

  • Build new apps on managed identity and data-plane RBAC from day one. Never hand out connection strings.
  • Keep the Transactions/Authentication metric on a dashboard, and alert on any Account Key traffic to accounts that should have none.
  • Remember that Owner, Contributor and Storage Account Contributor can still list keys. Disabling Shared Key makes those keys useless, but the 403s you see after the switch tell you who still needs to migrate.