Lesson 3 of 5 Securing Access to Azure Storage

Controlling SAS Tokens with Stored Access Policies

Stored access policies let service SAS tokens be changed or revoked after they are issued. This lesson explains how they work and their limits.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain how a service SAS inherits values from a stored access policy.
  • Describe how to revoke tokens through a stored access policy.
  • Identify the limits of stored access policies.

How stored access policies work

A stored access policy is defined on a container, file share, queue or table. It has an identifier (up to 64 characters) and optionally a start time, an expiry time and permissions. A service SAS created with si=<identifier> inherits the policy's values; any value defined in the policy must not also be defined in the SAS, and together they must define the start, expiry and permissions. Each container, share, queue or table can have up to five stored access policies.

Stored access policies apply only to service SAS. They cannot be used with an account SAS or a user delegation SAS. Changes to a policy can take up to 30 seconds to take effect, during which requests with an affected SAS may still succeed or fail with a 403 error.

True or false

Policy rules

Exam skills 2.1.3

Check the rules for stored access policies and the tokens that use them.

Log in to try this activity Interactive activities are free with an account.

Managing and revoking

In the portal, policies are managed on a container's or share's Access policy page (Add policy), and the Generate SAS dialog can select one. The steps below show the typical life cycle.

  1. Create the policy

    Add a policy such as partner-read on the container with read and list permissions and an expiry date.

  2. Issue tokens

    Generate service SAS tokens that reference the policy by identifier; the tokens carry no permissions or expiry of their own.

  3. Extend or change

    Edit the policy's expiry or permissions; every linked SAS changes immediately (within 30 seconds).

  4. Revoke

    Delete the policy, rename its identifier, or set its expiry to the past; every linked SAS stops working.

Revocation through the policy affects only the tokens linked to it, while rotating the account key would break every SAS and application that uses the key. If a policy is deleted and a new one is created with the same identifier, existing tokens that reference that identifier become valid again with the new policy's values, so a different identifier should be used.

The following diagram shows the effect of deleting the stored access policy.

Revoking a leaked service SAS with least disruption. Every partner token was created with the stored access policy partners, so deleting the policy, or setting its expiry in the past, invalidates all of them within 30 seconds while applications using the account key carry on. A new policy with a new identifier then backs fresh tokens for legitimate partners.
The number of tokens shown is illustrative.
Scenario questions

Revoking through a policy

Exam skills 2.1.3

Use stored access policies to change or revoke tokens.

Log in to try this activity Interactive activities are free with an account.
Worked example

Revoking a leaked token

Several partners use service SAS tokens for the container exports. One token was posted publicly. The tokens were created with the stored access policy partners. Other applications use the account key directly. How should you revoke access with the least disruption, and then restore access for legitimate partners?

Delete the partners policy (or change its expiry to the past), which invalidates every SAS linked to it within 30 seconds without affecting the applications that use the account key. Then create a new policy with a new identifier, such as partners-v2, and issue new tokens to the legitimate partners. Rotating the account key would also revoke the token but would break the other applications.

Check yourself

Can a stored access policy be used with an account SAS?

Show answer

No. Stored access policies work only with service SAS tokens.

Exam Tips

Remember for the exam

  • Stored access policies work with service SAS only.
  • Up to five policies per container, share, queue or table.
  • Revoke linked tokens by deleting or changing the policy; changes take up to 30 seconds.
  • Do not reuse a deleted policy's identifier.