DFdom@fradley
← ~/writing
$ cat find-public-storage.md

Find your public-facing storage before someone else does

Storage accounts are where most Azure data ends up: backups, exports, documents, the spreadsheet someone needed to share in a hurry. Azure can hand a file from one to anyone on the internet with no sign-in at all. That's handy for a public website and a data leak everywhere else.

Two switches, and the account one wins

ACCOUNT SWITCH ON Storage account Anonymous access: on Private (default) Public access level: Blob Anyone on the internet reads files, no sign-in ACCOUNT SWITCH OFF Storage account Anonymous access: off Private (default) Public ignored: account wins Anyone on the internet blocked
A container's own setting only matters while the account allows anonymous access. Switch it off at the account and every container underneath goes private.

Each storage account has a setting called Allow Blob anonymous access. Each container inside it (a folder, more or less) has its own access level, which starts as Private. A file is only open to the internet when both are on, and the account setting overrides the container: switch the account off and a container marked public stops serving anything.

New accounts start with anonymous access off. The ones to look for are older accounts and ones someone changed. Some older accounts never had the setting made at all, and Microsoft's own remediation script treats a blank value the same as on.

Find them

This Azure Resource Graph query checks every subscription you can see in one go:

az graph query -q "Resources | where type =~ 'microsoft.storage/storageaccounts' | where tostring(properties.allowBlobPublicAccess) != 'false' | project name, resourceGroup, subscriptionId, publicAccess = properties.allowBlobPublicAccess"

Anything it lists has the account switch on, or never set. If az graph isn't recognised, add it with az extension add --name resource-graph.

Close one down

Check first whether anything reads from the account anonymously on purpose. Microsoft's guide shows how to spot anonymous requests in the storage logs. Then:

az storage account update --name <account> --resource-group <rg> --allow-blob-public-access false

The change takes up to 30 seconds to apply. One exception: a static website's $web container stays public whatever the switch says, because serving the website is its job.

To stop the switch creeping back on, an Azure Policy assignment can deny any storage account that allows anonymous access. Azure Policy out of the box shows how to turn one on in audit mode first.

The query and the command are in blog-examples/find-public-storage.

discuss on linkedin → more writing