SAS Tokens and Stored Access Policies
30-second answer
A shared access signature (SAS) is a signed URL token that grants limited permissions (such as read and list) on specific storage resources until an expiry time. There are three kinds: a user delegation SAS (signed with Microsoft Entra credentials, Blob Storage, at most 7 days, the recommended one), a service SAS (signed with an account key, one service) and an account SAS (signed with an account key, one or more services). A stored access policy on a container, share, queue or table (up to 5 each) holds the permissions and expiry for service SAS tokens that reference it, so deleting or changing the policy revokes them without rotating the keys.
Simulate it » No Azure account neededExam objective: 2.1.2 Create and use shared access signature (SAS) tokens. 2.1.3 Configure stored access policies. (Skills measured as of April 17, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
Open <strong>Containers</strong> and select <strong>invoices</strong>. Auditors need read access for a month.
👆 Click the glowing item in the portal to continue
Read the steps as text
- Open Containers and select invoices. Auditors need read access for a month.
- Under Settings pick Access policy, then + Add policy in Stored access policies.
- Name it auditors-read, give Read and List, and an expiry 30 days out.
- Select Save. Nothing changes until you save the container’s access policy.
- Now Shared access tokens. Pick Account key, choose the auditors-read policy, and it fills in permissions and expiry. HTTPS only.
- Copy the token. To end access early, delete the policy (or change its expiry). An ad hoc SAS without a policy can only be killed by rotating the key that signed it.
- For the strongest option pick User delegation key instead: the SAS is signed with your Microsoft Entra credentials, lasts at most 7 days and can’t use a stored access policy.
🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.
🖱️ Drag to rotate · scroll or pinch to zoom
SAS tokens and stored access policies
A service SAS can point at a stored access policy on the container (up to 5 per container). The policy holds the permissions and expiry, so deleting or editing it revokes every SAS that names it. An ad hoc SAS can only be revoked by regenerating the key that signed it.
🤔 What happens if…
Read this tour as text
- The front door: the storage firewall. Every account has a public endpoint that accepts all networks by default. Set the default action to Deny and only what you list gets in: virtual network rules (subnets with the Microsoft.Storage service endpoint), IP rules (public addresses only) and trusted Azure services if you tick the exception.
- Three ways in, plus one for file shares. Callers prove who they are with an account key (full control), a SAS (limited rights for limited time) or a Microsoft Entra ID token checked against RBAC data roles. For SMB file shares, users bring a Kerberos ticket from AD DS, Microsoft Entra Domain Services or Microsoft Entra Kerberos.
- SAS tokens and stored access policies. A service SAS can point at a stored access policy on the container (up to 5 per container). The policy holds the permissions and expiry, so deleting or editing it revokes every SAS that names it. An ad hoc SAS can only be revoked by regenerating the key that signed it.
- Rotate access keys. Each account has two keys so you can rotate without downtime: move apps to key2, regenerate key1, and next time do the reverse. A key expiration policy flags old keys. Regenerating a key kills every SAS signed with it.
- Encryption at rest. Azure Storage always encrypts data with AES-256. By default Microsoft manages the key. With a customer-managed key in Key Vault (soft delete and purge protection on), the account’s managed identity wraps and unwraps its data key with your key, and you can revoke it.
- Redundancy and a region outage. LRS keeps 3 copies in one datacenter, ZRS spreads 3 across availability zones, GRS adds an async copy in the paired region and GZRS combines both. RA- versions let you read the secondary. A customer-managed failover promotes the secondary when the primary region is down.
- Moving data: AzCopy and object replication. AzCopy moves files in parallel from the command line, signed in with Microsoft Entra ID (and a Storage Blob Data role) or with a SAS. Storage Explorer does the same with a GUI. Object replication keeps copying new block blobs to another account by itself.
- Access tiers and lifecycle management. Blobs sit in Hot, Cool (30-day minimum), Cold (90 days) or Archive (180 days, offline). A lifecycle management rule moves or deletes blobs by age or last access, about once a day. Reading an archived blob means rehydrating it first.
- Undo buttons: soft delete, versioning and snapshots. Blob soft delete and container soft delete keep deleted items for 1 to 365 days. Versioning keeps every previous version of a blob. For Azure Files, share snapshots are read-only point-in-time copies and share soft delete keeps a deleted share.
Contoso keeps invoices in a storage account that anyone on the internet can reach with the right key. Close the front door, let only the app subnet and the office in, hand auditors a SAS you can revoke on your own terms, then rotate a key the safe way.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
An auditor needs a month of read access, and you may need to cut it off early.
😊 THE SOLUTION
Give a service SAS tied to a stored access policy you can delete.
- Sharing the account key✓ Scoped, expiring SAS
- Access must end early✓ Delete the policy
- Want no key at all✓ User delegation SAS
Start with a question
How do you let a plumber into your flat on Tuesday without giving them your house key forever?
You don’t hand over your own key. You give the building guard a note: “Let the plumber into flat 4B, kitchen only, Tuesday 10 to 12.” The plumber shows the note, the guard checks it, and on Wednesday the note is worthless.
Better still, the guard keeps a clipboard with rules like “plumbers: kitchen only, until Friday”. The note just says “see clipboard, plumbers”. If you change your mind, you cross out the line on the clipboard and every plumber note stops working at once.
The note is a SAS. The clipboard line is a stored access policy.
Explain it like I’m 10
The technical explanation
A SAS is a query string you append to a storage URL. It carries the permissions (sp), expiry (se), optional start (st), allowed IPs (sip), protocol (spr=https), the resource type and a signature (sig). Storage recomputes the signature with the same key; if anything was changed, the request fails.
Three kinds of SAS
| User delegation SAS | Service SAS | Account SAS | |
|---|---|---|---|
| Signed with | User delegation key from Microsoft Entra ID | Account key | Account key |
| Covers | Blob Storage (containers and blobs) | One service (blob, file, queue or table) | One or more services, service-level operations too |
| Max lifetime | 7 days | Whatever you set | Whatever you set |
| Stored access policy | No | Yes | No |
| Works with key access disabled | Yes | No | No |
| Revoke early | Revoke delegation keys or the signer’s role | Delete the policy, or regenerate the key | Regenerate the key |
Microsoft recommends the user delegation SAS wherever it fits. The signer needs permission to get a user delegation key, and at use time the SAS can’t do more than the signer’s own data role allows.
Stored access policies
A stored access policy lives on a container, file share, queue or table, and each can hold up to five. It holds any of: permissions, start time, expiry time. A service SAS names it with si=<policy> and takes the missing fields from the policy. Don’t set the same field in both places; storage rejects that.
To revoke every SAS tied to a policy, delete the policy, rename it, or set its expiry in the past. Changes can take up to 30 seconds to apply. An ad hoc SAS (no policy) can only be revoked by regenerating the key that signed it.
Portal steps
- Open the container, then Settings > Access policy > + Add policy. Enter the identifier, tick the permissions, set start and expiry, then Save.
- Open Settings > Shared access tokens. Choose Signing method (Account key or User delegation key), the signing key, the Stored access policy, allowed IPs and HTTPS only.
- Select Generate SAS token and URL and copy it straight away. Azure doesn’t keep a copy.
The account-wide Shared access signature blade (under Security + networking) creates account SAS tokens.
CLI and PowerShell
EXP=$(date -u -d "+30 days" '+%Y-%m-%dT%H:%MZ')
# Stored access policy + service SAS that uses it
az storage container policy create --account-name stcontosoprod -c invoices \
-n auditors-read --permissions rl --expiry $EXP
az storage container generate-sas --account-name stcontosoprod -n invoices \
--policy-name auditors-read --https-only -o tsv
# Revoke every SAS tied to the policy
az storage container policy delete --account-name stcontosoprod -c invoices -n auditors-read
# User delegation SAS for one blob (max 7 days, no account key)
az storage blob generate-sas --account-name stcontosoprod -c invoices -n invoice-1001.pdf \
--permissions r --expiry 2026-11-30T18:00Z --auth-mode login --as-user --https-only --full-uri
$ctx = (Get-AzStorageAccount -ResourceGroupName rg-storage-prod -Name stcontosoprod).Context
New-AzStorageContainerStoredAccessPolicy -Container invoices -Policy auditors-read `
-Permission rl -ExpiryTime (Get-Date).AddDays(30) -Context $ctx
New-AzStorageContainerSASToken -Name invoices -Policy auditors-read -Protocol HttpsOnly -Context $ctx
Architect level SAS expiration policies and good hygiene
You can set a SAS expiration policy on the account (for example, one day). Azure then logs any SAS signed with an account key whose validity is longer, so you can find bad habits. Other habits that pay off: keep expiry short, use HTTPS only, restrict sip to known ranges, give only the letters you need (r and l, not racwdl), and prefer user delegation SAS so a leaked account key isn’t part of the story at all.
Real-world business scenario
Fabrikam Accounting (fictional)
- The problem
- External auditors were emailed the storage account key every year, and nobody remembered to rotate it afterwards.
- What they used
- A stored access policy auditors-read on the invoices container (read and list, 30 days), and a service SAS with HTTPS only and the auditors' office IP range.
- Why that choice
- Auditors only see one container, only read, only from their office, and the team can end access in seconds by deleting the policy.
- The result
- When the audit finished a week early, the admin deleted the policy and confirmed the SAS returned 403. The account keys never left the team.
When to use it and when not to
✓ Use it when…
- Someone outside your tenant needs time-limited access to specific containers or blobs.
- A client app uploads directly to storage and you hand it a short-lived token.
- You need to be able to revoke a group of tokens in one move (use a stored access policy).
✕ Think twice when…
- The caller is your own app or user with a Microsoft Entra identity (use RBAC data roles).
- You need long-lived access with no expiry (rethink the design).
- You want to revoke an ad hoc SAS without touching the keys (you can't).
↔ Alternatives to consider
- Microsoft Entra ID with Storage Blob Data roles for your own apps and staff.
- User delegation SAS instead of key-signed SAS where Blob Storage is used.
- Storage firewall to limit where a SAS can be used from.
Test yourself with exercises
5 original practice questions in the AZ-104 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.
Interview preparation
Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.
Beginner Why would you give someone a SAS instead of the storage account key?
Model answer
The key gives full control of everything in the account, forever. A SAS gives only the permissions I choose, on the container or blob I choose, until a time I choose, and I can require HTTPS or a specific IP range. If it leaks, the damage is limited.
Intermediate You gave a partner an ad hoc service SAS valid for six months and now need to cut them off. What can you do?
Model answer
An ad hoc SAS carries its own permissions and expiry, so the only way to revoke it early is to regenerate the account key that signed it. That also breaks anything else using that key, so I'd move other apps to the second key first. Next time I'd tie the SAS to a stored access policy so I can just delete the policy.
Experienced developer When would you choose a user delegation SAS?
Model answer
Whenever the data is in Blob Storage and the person creating the SAS has a Microsoft Entra identity. It's signed with a key Entra ID issues, not the account key, so it still works when Shared Key access is disabled, it's capped at seven days and its rights can never exceed what the signer's RBAC role allows. I can revoke all of them with az storage account revoke-delegation-keys.
Scenario Auditors need read access to the invoices container for 30 days, and you might have to end it early. How do you set it up?
Model answer
Create a stored access policy called auditors-read on the invoices container with read and list and a 30-day expiry. Then generate a service SAS with --policy-name auditors-read, HTTPS only. To end access I delete the policy, or change its expiry to the past. The account keys don't change.
Quick revision
Key points
- User delegation SAS = Microsoft Entra ID, Blob Storage, max 7 days, recommended.
- Service SAS = account key, one service. Account SAS = account key, several services.
- Stored access policies (max 5 per container) work only with service SAS tokens.
- Revoke a policy-based SAS by deleting or editing the policy. Revoke an ad hoc SAS by regenerating its signing key.
- Policy changes can take up to 30 seconds to apply.
- Use HTTPS only, short expiry and the least permissions.
Important terminology
- Shared access signature (SAS)
- A token appended to a storage URL that grants specific permissions on specific resources for a limited time.
- User delegation SAS
- A SAS signed with a user delegation key that Microsoft Entra ID issues, so no account key is involved. Valid for up to 7 days.
- Service SAS
- A SAS signed with an account key that grants access to resources in one service, such as one blob container.
- Account SAS
- A SAS signed with an account key that can cover one or more services and service-level operations.
- Stored access policy
- A named set of permissions, start and expiry time saved on a container, share, queue or table, which service SAS tokens can reference.
- Signed identifier (si)
- The SAS parameter that names the stored access policy the token uses.
Common mistakes
- Trying to attach a stored access policy to an account SAS or a user delegation SAS.
- Setting the same field (permissions or expiry) in both the policy and the SAS.
- Forgetting that disabling Shared Key access also kills service and account SAS tokens.
Exam tips
- "Revoke access without regenerating keys" = stored access policy.
- "SAS secured with Microsoft Entra credentials" = user delegation SAS.
- "One SAS for blobs and queues" = account SAS.
Five quick revision questions
-
1.How many stored access policies can one container have?Show
Five.
-
2.What is the maximum validity of a user delegation SAS?Show
Seven days.
-
3.Which SAS types can reference a stored access policy?Show
Service SAS only.
-
4.How do you revoke an ad hoc service SAS early?Show
Regenerate the account key that signed it.
-
5.Which SAS parameter names the stored access policy?Show
si (signed identifier).
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: Manage and Rotate Storage Access Keys
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.