Shared access signatures and account keys

An Azure SAS token is a signed link that gives someone limited access to your storage for a limited time, without handing them a password or a role. A typical one says “read this one file until 6 pm”.

You’ll find SAS links all over the place, in app download links, backup tools and partner uploads. They’re also behind a lot of storage leaks, because a SAS signed with an account key can’t easily be switched off.

In the lab you’ll create the safest kind of SAS, one you can revoke, and also an unsafe one that you’ll then have to kill by rotating a key.

TimeYou needCostBy the end you can
About 40 minutesThe storage account from Lesson 21, the CLINothing extra: a few reads and writesCreate user delegation and policy-based SAS links, read a SAS, and revoke access safely

What it is, in one line

A SAS is a URL carrying a signature that grants specific permissions on storage until a set expiry time.

In Simple Words

The visitor pass at the school gate

The school’s master key opens every door, so you’d never hand it to a visitor. Instead the office writes out a pass saying “Room 4 only, today, until 3 pm” and stamps it, and that pass is a SAS.

Some passes get written in a register, so the office can cancel one by striking it out. Others are only stamped paper, and the only way to cancel those is to change the stamp, which cancels every pass made with it. The master key here is the account key, and if you lose it you have to change every lock in the building.

Engineer's View

Three kinds of SAS, and the keys behind them

  • User delegation SAS: signed with a key that Azure issues to your Entra ID identity. It works for Blob and Data Lake only, lasts up to 7 days, and can never do more than your own RBAC rights allow. This is the type Microsoft recommends.
  • Service SAS: signed with an account key and covers one service (a blob, container, share, queue or table). It can point at a stored access policy on the container, and changing or deleting that policy revokes it. You can have up to 5 policies per container.
  • Account SAS: also signed with an account key, but it can span several services and even account operations, which makes it the widest and riskiest type.
  • Inside the token: sp permissions, se expiry, st start, spr=https, sr resource type, sv version and sig, the signature. User delegation tokens add skoid, sktid and other sk* fields about the signing identity.
  • Account keys: there are two (key1 and key2) so you can rotate one while apps carry on using the other, and either one gives full control of the data.
  • Revoking: a key-signed SAS only dies when it expires or when its signing key is rotated. A policy-based SAS dies when you remove the policy, and a user delegation SAS dies with az storage account revoke-delegation-keys or when the signer loses the role.
  • Locking down: setting --allow-shared-key-access false blocks account keys and every key-signed SAS, while user delegation SAS carries on working. Account policies can also cap SAS lifetime and remind you to rotate keys.

How it works, step by step

This is what happens when someone opens a user delegation SAS link:

Azure SAS token types compared: user delegation, service and account SAS
  1. Your app uses its Entra ID identity to ask Azure for a user delegation key.
  2. It signs a SAS for one blob, read only, valid for one hour, and hands out the URL.
  3. The person on the other end opens the URL, and storage works out the signature again from the token fields.
  4. If the signature matches, the time is valid and the permission covers the request, the read goes through, and anything else fails with 403.
  5. Storage also checks that the signing identity still has rights, so taking away its role cuts the link.

A key-signed SAS skips that identity check, so anyone holding the URL keeps the access until it expires, even if the person who created it left the company a year ago.

Azure SAS token checks when a user delegation link is opened

My rule of thumb: reach for user delegation SAS first, use a policy-based service SAS when you need a longer life or a non-blob service, almost never use an account SAS, and keep account keys only in a vault.

Hands-on lab: create and revoke an Azure SAS token

Before you run any command, double-check it

Read every command twice before you press Enter. Check the target: the system or account, the IDs, the names and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only list commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.

Load your storage account name and set an expiry time one hour from now:

$st = (Get-Content C:\azure-lab\storage.txt)
$exp = (Get-Date).ToUniversalTime().AddHours(1).ToString('yyyy-MM-ddTHH:mmZ')

1Look at the account keys, without printing them

Run this:

az storage account keys list --resource-group rg-saat-data --account-name $st --query "[].{name:keyName, permissions:permissions}" -o table

You should see this:

Name    Permissions
------  -------------
key1    FULL
key2    FULL

Don’t ever print the values in a shared terminal or paste them into a ticket, because anyone who sees one has full control of the data in that account.

2Make a user delegation SAS for one file

Run this:

$url = az storage blob generate-sas --account-name $st --container-name lab --name hello.txt --permissions r --expiry $exp --https-only --auth-mode login --as-user --full-uri -o tsv
(Invoke-WebRequest -Uri $url -UseBasicParsing).Content

You should see this:

hello from lesson 21

Anybody with that URL can read hello.txt for an hour from any browser. It was your Storage Blob Data Contributor role (Lesson 21) that allowed you to sign it.

3Read what’s inside the token

List the fields, leaving the signature out:

([uri]$url).Query.TrimStart('?').Split('&') | Where-Object { $_ -notlike 'sig=*' }

You should see something like this:

se=2026-10-20T17%3A30Z
sp=r
spr=https
sv=2026-04-06
sr=b
skoid=3f6a...
sktid=9b1c...
skt=2026-10-20T16%3A30%3A12Z
ske=2026-10-20T17%3A30%3A00Z
sks=b
skv=2026-04-06

sp=r is read only, sr=b means a single blob, and the sk* fields tell you which identity signed it. Whenever a SAS fails, reading these fields is the first thing to do.

4Prove the SAS is read only

Try overwriting the file with it:

try { Invoke-WebRequest -Method Put -Uri $url -Headers @{'x-ms-blob-type'='BlockBlob'} -Body 'changed' -UseBasicParsing } catch { $_.Exception.Response.StatusCode.value__; $_.ErrorDetails.Message }

You should see something like this:

403
<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthorizationPermissionMismatch</Code><Message>This request is not authorized to perform this operation using this permission.
RequestId:...
Time:...</Message></Error>

5Make a revocable SAS with a stored access policy

Create a policy on the container, sign a SAS that uses it, and then delete the policy:

az storage container policy create --account-name $st --container-name lab --name pol-read --permissions r --expiry $exp -o none
$purl = az storage blob generate-sas --account-name $st --container-name lab --name hello.txt --policy-name pol-read --full-uri -o tsv
(Invoke-WebRequest -Uri $purl -UseBasicParsing).StatusCode
az storage container policy delete --account-name $st --container-name lab --name pol-read -o none
Start-Sleep -Seconds 40
try { Invoke-WebRequest -Uri $purl -UseBasicParsing } catch { $_.Exception.Response.StatusCode.value__ }

You should see this:

200
403

Behind the scenes these commands use the account key, and the CLI warns you about it. Deleting the policy killed the link without touching the key, though policy changes can take up to 30 seconds to apply.

Azure SAS token lab: read-only link, refused write and revoked policy
A read-only user delegation SAS, a write that got refused, and a policy-based SAS revoked.

✅ Checkpoint: You read a file through a user delegation SAS, proved it can’t write, and revoked a policy-based SAS.

Break It, Then Fix It

Both of these come up when somebody asks for “a link that works for a month”.

1Break it: a user delegation SAS for 30 days

Run this:

$long = (Get-Date).ToUniversalTime().AddDays(30).ToString('yyyy-MM-ddTHH:mmZ')
az storage blob generate-sas --account-name $st --container-name lab --name hello.txt --permissions r --expiry $long --auth-mode login --as-user --full-uri -o tsv

You’ll get an error like this:

ERROR: incorrect usage: --expiry should be within 7 days from now

A user delegation key lasts 7 days at most, so the SAS can’t outlive it, and the CLI stops you before it even asks Azure.

Fix it: don’t try to stretch a SAS for long-term access. Give the partner’s app its own identity and a data role, or have an app issue a fresh short SAS each time. If you really do need a long link, use a stored access policy so you can still revoke it:

az storage container policy create --account-name $st --container-name lab --name pol-partner --permissions r --expiry $long -o none
az storage container policy list --account-name $st --container-name lab --query "keys(@)" -o tsv

You should see this:

pol-partner

2Break it: the leaked link you can’t switch off

Make an ad hoc SAS signed with the account key, the way plenty of old scripts do, and imagine it ended up in a public chat:

$leak = az storage blob generate-sas --account-name $st --container-name lab --name hello.txt --permissions r --expiry $long --https-only --full-uri -o tsv
(Invoke-WebRequest -Uri $leak -UseBasicParsing).StatusCode

You should see this:

200

There’s no policy you can delete and no identity you can remove, so this link works for 30 days for whoever has it.

Fix it: rotate the key that signed it (the CLI signs with key1). That would also break any apps on key1, so in real life you move them to key2 first:

az storage account keys renew --resource-group rg-saat-data --account-name $st --key primary -o none
Start-Sleep -Seconds 30
try { Invoke-WebRequest -Uri $leak -UseBasicParsing } catch { $_.Exception.Response.StatusCode.value__; $_.ErrorDetails.Message }

You should see something like this:

403
<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:...
Time:...</Message><AuthenticationErrorDetail>Signature did not match. String to sign used was r ...</AuthenticationErrorDetail></Error>

The leak is closed, but so is every other SAS and connection string that relied on key1. That much collateral damage is why key-signed SAS links should be a last resort.

Clean up by removing the partner policy:

az storage container policy delete --account-name $st --container-name lab --name pol-partner -o none
az storage container policy list --account-name $st --container-name lab -o tsv

The last command prints nothing.

Azure SAS token errors: 7-day limit and a leaked link closed by key rotation
The 7-day limit, plus the only way to kill an ad hoc key-signed SAS.

✅ Checkpoint: The 30-day user delegation SAS was refused, the leaked key-signed link now returns 403, and no stored access policies are left.

This happened at work

The SAS link in a support ticket

A software vendor’s support team used to ask customers to upload their logs to a container. To make life easy, one engineer created an account SAS with read, write, list and delete on every service, valid for two years, and pasted it straight into a public help article.

Eighteen months later a security researcher got in touch about it. That link could list and download every customer’s logs, and some of those logs had passwords in them. There was no stored policy to delete, so the only way out was to rotate both account keys, and that broke three internal apps for an afternoon.

What they changed: the upload page now calls a small function that hands out a user delegation SAS for one new blob, create and write only, valid for 15 minutes. They turned shared key access off on the account, an Azure Policy now flags any storage account that still allows it, and SAS lifetime is capped by account policy.

Common mistakes and troubleshooting

MistakeWhat you seeWhat to do
Long-lived account SASData leak you can’t revoke quicklyUse a user delegation SAS with a short expiry and a narrow scope.
Printing account keysFull access exposedDon’t print them; keep keys in Key Vault (Lesson 55).
SAS with write when read is enoughFiles changed or deletedGrant only the permission you need (sp=r).
user delegation SAS over 7 daysError: --expiry should be within 7 daysUse a stored policy or an app identity instead.
Rotating key1 with apps still on itApps fail with AuthenticationFailedMove apps to key2, rotate key1, then do it the other way round.
Start time set to “now”403 on machines with a fast clockLeave the start out, or set it 15 minutes earlier.
Wrong resource type in the SAS403 on the right fileCheck sr (b means blob, c means container).

Interview questions

Click a question to open it. Each one is phrased the way an interviewer would ask it, and underneath you’ll find why they ask it and one way you could answer in your own words.

Fresher level

1. What is a SAS token?

Why they ask this: It’s the basic idea.

How you might answer: It’s a signed URL query string that grants specific permissions on storage resources for a limited time, so you don’t have to share account keys or give the user a role.

2. What are the three types of SAS?

Why they ask this: They want the names and how they differ.

How you might answer: There’s the user delegation SAS, signed with a key based on Entra ID; the service SAS, signed with an account key for one service; and the account SAS, also signed with an account key but able to cover several services. User delegation is the one Microsoft recommends.

3. Why are there two account keys?

Why they ask this: It checks that you know rotation basics.

How you might answer: It’s so you can rotate without downtime. You move the apps to key2 and regenerate key1, and later you move them back and regenerate key2.

2–5 years experience

4. A SAS link was leaked. How do you revoke it?

Why they ask this: They want to hear that the answer depends on the type.

How you might answer: If it uses a stored access policy, I’d delete or change the policy. For a user delegation SAS I’d revoke the delegation keys or take away the signer’s role. And if it’s an ad hoc key-signed SAS, I’d have to rotate the signing key once the apps were moved to the other key.

5. A SAS returns 403. How do you troubleshoot?

Why they ask this: It’s a practical ticket that comes up often.

How you might answer: I’d decode the token and look at the expiry and start time, the permissions, the resource type, HTTPS only and any IP range. Then I’d check whether the signing key has been rotated, whether the stored policy still exists, whether the signer still has rights, and whether the storage firewall lets the caller in.

6. What changes when you disable shared key access?

Why they ask this: They want to see you think about the side effects.

How you might answer: Account keys, connection strings with keys in them, and every service or account SAS all stop working, while Entra ID access and user delegation SAS keep going. Before doing it I’d go through sign-in logs and app configs, because older tools often still rely on keys.

Senior level

7. How would you design file sharing with external partners?

Why they ask this: They’re looking for a secure pattern.

How you might answer: I’d build a small service with a managed identity that checks who’s asking and then issues a user delegation SAS for one blob, with the minimum permission and a short expiry. The account would block shared keys, sit behind the firewall or private endpoints where possible, and log access to Log Analytics.

8. How would you manage storage keys across hundreds of accounts?

Why they ask this: They want governance that works at scale.

How you might answer: I’d try to remove the need for keys altogether with Entra ID, managed identities and a policy that turns shared key access off. Where keys have to exist, they go in Key Vault with automated rotation, a key expiration policy on each account, and alerts for keys older than the limit.

9. Is a SAS safe if it’s HTTPS only and expires in an hour?

Why they ask this: They want a nuanced answer.

How you might answer: It’s safer, but I wouldn’t call it safe. For that hour anyone with the URL has the access, so permission and scope still matter. I’d also watch where URLs end up, like logs, browser history and chat tools, and keep them out of query-string logging.

Quick quiz

Q1. Which SAS type does Microsoft recommend for blobs?

  1. Account SAS
  2. Service SAS
  3. User delegation SAS
  4. Anonymous access
Show answer

C — It’s signed with Entra ID credentials and limited by RBAC.

Q2. What is the maximum validity of a user delegation SAS?

  1. 1 hour
  2. 24 hours
  3. 7 days
  4. 1 year
Show answer

C — User delegation keys last up to 7 days.

Q3. How do you revoke an ad hoc service SAS signed with key1?

  1. Delete the blob
  2. Rotate key1
  3. Change the tier
  4. Remove soft delete
Show answer

B — Rotating the signing key invalidates it.

Q4. In a SAS token, sp=r means:

  1. Start time
  2. Read permission
  3. Resource is a page blob
  4. Region
Show answer

B — sp lists the permissions.

Q5. After shared key access is disabled, which still works?

  1. Account SAS
  2. Connection strings with keys
  3. User delegation SAS
  4. Service SAS with key1
Show answer

C — Only Entra ID based access keeps working.

Quick recap

You can now hand out storage access safely, and take it back again.

  • User delegation SAS is the default choice, and it lasts up to 7 days.
  • A stored access policy is what makes a service SAS revocable.
  • An ad hoc key-signed SAS only dies when it expires or the key is rotated.
  • Rotate keys one at a time, with the apps moved to the other key first.
  • When a SAS fails, decode the token fields first.

Next lesson

Lesson 25: Azure Files: SMB shares, snapshots, soft delete → Next you’ll mount an Azure file share on win01, take a snapshot and restore a deleted file.

Further reading: Azure SAS token

Want to go deeper into Azure SAS token? See Microsoft’s Grant limited access with shared access signatures and Create a user delegation SAS with the Azure CLI. You can also see the full plan for this course on the Azure Cloud Administration course page.

Scroll to Top

This website uses cookies

We use a few cookies to keep this site working. If you allow it, we also use Google Analytics to count visits so we can improve our lessons. You can accept all, deny the optional ones, or choose what to allow.