Lesson 3 of 4 Securing Storage Accounts

Managing Access to Storage

This lesson explains data roles, shared access signatures, stored access policies and immutable storage.

Learning outcomes

After completing this lesson, you will be able to:

  • Choose a data role and condition.
  • Compare the three SAS types and their revocation.
  • Explain how stored access policies work.
  • Describe time-based retention and legal holds.

Data roles and conditions

The preferred way to grant access is through Azure RBAC data roles. Storage Blob Data Reader reads, Storage Blob Data Contributor reads and writes, and Storage Blob Data Owner also manages POSIX permissions and ownership. Equivalent roles exist for queues, tables and file shares. Remember that the management role Storage Account Contributor can list keys, and so can reach all the data unless Shared Key is disabled.

Attribute-based access control (ABAC) refines a role assignment with a condition. For example, a person can be given Storage Blob Data Reader, limited to blobs in a named container or to those with a given index tag. Conditions are helpful because they reduce the number of accounts and role assignments that an organization needs.

Azure Data Lake Storage also supports POSIX-style access control lists on directories and files. These are evaluated after Azure roles, so a role that allows access takes effect first.

Shared access signatures

A shared access signature (SAS) is a URL with a signed token that grants limited rights for a limited time. It allows an external client to reach data without holding an account key or a Microsoft Entra identity. There are three kinds, and their differences matter for both security and revocation.

SAS typeSigned withReachHow to revoke
User delegation SASA user delegation key from Microsoft Entra IDBlob StorageRevoke user delegation keys, or remove the signer's rights
Service SASAn account keyOne serviceUse a stored access policy, or rotate the key
Account SASAn account keyOne or more services, and service-level operationsRotate the key

A user delegation SAS is the recommended type, because no account key is involved, and because activity is linked to a Microsoft Entra identity in the logs. Whichever kind is used, follow these principles: use the shortest practical expiry, give the fewest permissions, limit the IP range if possible, and require HTTPS. Clock skew of up to 15 minutes can occur, so a start time should be set slightly in the past, or omitted.

Revocation

An ad hoc service SAS cannot be revoked individually. The only way to invalidate it before its expiry is to rotate the account key that signed it, which also breaks everything else that uses that key. This is the reason to use a stored access policy or a user delegation SAS.

Sort into groups

Which SAS type?

Exam skills 2.1.4

Decide which SAS type each statement describes.

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

Stored access policies

A stored access policy sits on a container, and it defines a start time, expiry and permissions. A service SAS can reference the policy rather than including those values in the URL. Changing or deleting the policy then affects every SAS that uses it, without changing an account key.

A container can hold up to five stored access policies. They apply only to service SAS, and they are not supported for user delegation SAS or account SAS. The following command creates a read-only policy that lasts until a set date.

az storage container policy create --account-name ACCOUNT --container-name CONTAINER \
  --name partner-read --permissions r --expiry 2027-01-31T00:00Z --auth-mode key

Note that the command needs an account key, since stored access policies belong to the Shared Key model. This is one reason why they cannot be combined with an account that has Shared Key disabled.

True or false

Stored access policies

Exam skills 2.1.4

Check how stored access policies work.

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

Immutable storage

Regulations can require that records cannot be changed or deleted for a fixed period. Immutable storage for Azure Blob Storage provides write once, read many (WORM) protection with two kinds of policy, which can be combined.

  • Time-based retention: blobs cannot be changed or deleted for a stated period, from 1 day to 146,000 days. An unlocked policy can be changed or deleted. A locked policy can be extended, but it cannot be shortened or deleted.
  • Legal hold: blobs cannot be changed or deleted until the hold is cleared, with no fixed period. It suits litigation or investigations.

Policies can apply at container level or at version level. Version-level WORM needs blob versioning, and it is not supported on accounts with a hierarchical namespace. Lock a time-based policy promptly, as Microsoft recommends doing so within about 24 hours. Immutability is not compatible with point-in-time restore or last access tracking, and it is not supported with NFS 3.0 or SFTP. Even an Owner cannot delete a protected blob, because the protection is enforced by the service.

Scenario questions

Immutable storage

Exam skills 2.1.4

Choose the immutability policy for each requirement.

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

Choosing an approach

The following steps give a way to choose. Start with the most secure option, and move down the list only when there is a reason.

  1. Internal workload

    Use a managed identity with a data role.

  2. Internal user

    Use a Microsoft Entra group with a data role, plus conditions if needed.

  3. External client, short term

    Use a user delegation SAS.

  4. External client with revocation by policy

    Use a service SAS with a stored access policy.

  5. Regulated records

    Add an immutability policy.

Worked example

Granting and revoking partner access

A partner with no Microsoft Entra account must read files from one container for 30 days. If the contract ends early, access must be revoked within minutes, with no effect on other applications. Shared Key is still enabled on the account because several old applications depend on it. What should you use?

A service SAS linked to a stored access policy on the container meets every condition. The partner needs no identity, the access is limited to one container and to read rights, and deleting or changing the policy revokes access at once without disturbing anything else.

An ad hoc service SAS would need a key rotation to revoke, which would break the old applications. An account SAS has the same problem and a broader reach. A data role needs an identity, which the partner does not have. A user delegation SAS would be a sound alternative only if revoking it did not affect other delegated signatures.

Check yourself

How do you revoke an ad hoc service SAS before its expiry?

Show answer

Rotate the account key that signed it, which affects everything else that uses the key. A stored access policy avoids this.

Exam Tips

Remember for the exam

  • User delegation SAS is the recommended type.
  • Stored access policies apply only to service SAS.
  • A locked retention policy can be extended but not shortened.
  • Storage Account Contributor can reach data by listing keys.