Implement SAS Security and Revocation Strategies
A Shared Access Signature (SAS) is a signed URL that provides limited, delegated access to Azure Storage resources. To maintain high security, clients must always use HTTPS to distribute these tokens and prevent them from being intercepted. Administrators should also follow the principle of least privilege by granting only the minimum necessary permissions for the shortest duration possible.
There are three main types of signatures: User Delegation SAS, Service SAS, and Account SAS. Microsoft recommends using a User Delegation SAS for blob data because it is secured using Microsoft Entra ID credentials rather than storage account keys. This approach significantly reduces security risks because it avoids exposing your secret account keys and relies entirely on identity-based security.
Setting appropriate expiration times is a critical strategy for mitigating risks if a token is ever leaked. An ad-hoc SAS defines its permissions and end time directly in the URI, which makes it difficult to cancel once it is issued. For these types of signatures, you should use near-term expiration times, such as one hour or less, to keep the vulnerability window small.
For better administrative control, you can use a stored access policy to manage service-level signatures. This policy allows you to define constraints on a container and associate multiple signatures with it. This relationship provides a powerful revocation mechanism, as deleting the policy or changing its expiration date to a time in the past immediately cancels all linked signatures.
To protect the entire storage environment, you should store your storage account keys in Azure Key Vault and rotate them periodically. If you suspect a key has been compromised, rotating that key will instantly invalidate every SAS token created with it. For the most secure configuration, you can disable shared key authorization entirely, which forces all clients to authenticate using Microsoft Entra ID.
Key security practices include:
- Use User Delegation SAS to leverage identity-based security for blob storage.
- Implement stored access policies to enable easy revocation of service-level signatures.
- Set short expiration times to limit the life of any ad-hoc SAS.
- Rotate account keys regularly to maintain long-term security.
Manage Lifecycle and Revocation through Stored Access Policies
A stored access policy acts as a server-side management layer used to control service-level shared access signatures. These policies are defined directly on specific resource containers, such as blob containers or Azure Queue Storage, to group multiple signatures together. By using a policy, administrators can centrally manage access constraints like start times, expiration dates, and specific permissions.
One major advantage of this centralized control is the ability to revoke access or change permissions without regenerating storage account keys. If a signature is compromised, you can simply modify or delete the underlying policy to stop access immediately. This provides a much higher level of operational control compared to ad-hoc signatures, which cannot be easily canceled once they are generated.
There are several methods to manage the lifecycle and revoke access of a signature through its policy. To effectively revoke access, administrators can use the following methods:
- Change the expiration time of the policy to a date in the past.
- Delete the stored access policy from the resource container.
- Rename the policy to instantly invalidate all existing tokens referencing the old name.
When a Service SAS is associated with a policy, it inherits all constraints defined within that policy. This relationship ensures that any changes made to the policy are automatically applied to all active signatures linked to it. This connection is essential for maintaining consistent access control across different client applications using the same storage resources.
When implementing these policies, you must plan around the platform constraint of a maximum of five stored access policies per container. Administrators should use these policies for any long-term access needs to ensure they can respond to security threats quickly. Note that stored access policies are only supported for Service SAS and cannot be used with Account SAS or User Delegation SAS.
A shared access signature provides a secure way to grant limited access to Azure Storage resources without sharing your account keys. It provides granular control over what data a client can see and what actions they can perform. By using a SAS, you can specify exactly which resources are available, what permissions are granted, and how long the access remains valid.
You can generate different types of tokens, including a Service SAS and an Account SAS, using Azure SDKs or tools. A Service SAS delegates access to a resource in only one storage service, such as Azure Blob Storage or Azure Queue Storage. In contrast, an Account SAS can delegate access to multiple services at once and allows for service-level operations that a Service SAS cannot handle.
Microsoft recommends using a User Delegation SAS whenever possible because it is secured with Microsoft Entra ID credentials instead of the storage account key. This method provides superior security because it does not require you to store or share your secret account keys. It is currently supported for Azure Blob Storage and Azure Data Lake Storage but not for other services like Files or Tables.
When you construct a SAS, you must define specific security constraints to protect your data. You should specify the resource types and storage services the client can access to enforce least-privilege principles. These settings include:
- Permissions: Choosing only the necessary actions like read, write, or delete.
- IP Address Restrictions: Limiting access to specific trusted IP addresses.
- Protocols: Requiring the use of HTTPS to prevent data from being intercepted.
- Expiration: Setting a short validity period to reduce the risk if a token is leaked.
Managing SAS tokens effectively requires a clear revocation plan in case a token is compromised. For a Service SAS, you can use a stored access policy to manage constraints and revoke access without changing your account keys. For other types, using near-term expiration times is a best practice to ensure that leaked tokens are only useful for a very short time.
Understand the Types and Permissions of SAS
Understanding the differences between the types of SAS is essential for designing secure applications. With any SAS, you can specify permissions, start and expiry times, and allowed protocols for clients. This approach provides fine-grained control, enabling scenarios like temporary data sharing or restricted application access.
An Account SAS is signed with the storage account key and applies across multiple services and resource types. It allows you to grant permissions at the account level across several areas:
- Services: blob, queue, table, and file.
- Resource types: service (s), container (c), and object (o).
- Permissions: read, write, delete, list, add, create, update, and more.
You should use an Account SAS when you need broad access for management tasks or cross-service automation, but keep in mind that it is less restrictive than other SAS types.
A Service SAS is scoped to a specific service resource, like a single blob container or queue. It is also signed with the account key but provides more granular access to a particular container, table, or queue. Permissions for a Service SAS typically include actions like read, write, delete, and list. This type is ideal when you want to grant limited operations on a single service endpoint, such as letting a client upload files to a container without giving them full account access.
A User Delegation SAS is signed with Microsoft Entra ID credentials instead of account keys and only applies to the Blob service. This type of SAS inherits the security benefits of Microsoft Entra ID, including identity binding and direct revocation. The token is tied to a specific Azure Active Directory principal, and you can revoke it by removing the user’s role assignment. This is the recommended type for scenarios where security and compliance are critical.
Apply Security Constraints and Network Restrictions
Shared access signatures provide a secure way to grant limited, time-bound access to Azure Storage resources without sharing your account keys. A SAS token is a signed URL that specifies the permissions granted, the resources that can be accessed, and the time interval during which the signature is valid. Using a SAS helps enforce the principle of least privilege by granting only the necessary permissions for a limited time.
To enhance security, you can configure SAS tokens to enforce HTTPS-only communication, ensuring all data transfers are encrypted. Additionally, you can restrict access to specific IP address ranges, limiting requests to trusted networks only. It is also critical to carefully evaluate the start and expiry times of the SAS token to minimize the window of vulnerability. Shorter validity periods drastically reduce the risk if a token is compromised.
Microsoft recommends using a User Delegation SAS whenever possible, as it offers superior security by leveraging Microsoft Entra ID instead of storage account keys. You should avoid using Shared Key authorization for storage accounts, as it provides full access and presents a significant security risk. Instead, use Azure role-based access control (Azure RBAC) with managed identities for optimal security. Protect your storage account keys by storing them in Azure Key Vault and rotating them regularly.
You can implement network security by configuring firewalls and virtual networks to restrict access to your storage account. Use private endpoints for secure connectivity within your virtual network and disable public network access if it is not required. You can also configure the storage account to only allow trusted Microsoft services to bypass network rules when necessary. Finally, continuously monitor access patterns using Azure Storage logs and Azure Monitor to detect any unauthorized requests or anomalies.