Azure Shared Access Signature security is a top priority, and it's essential to understand the basics of token management to keep your data safe. A Shared Access Signature (SAS) token is a unique string that grants access to Azure resources for a specified period.
SAS tokens can be used to control access to Azure resources, such as blobs and queues, and can be configured to expire after a set period. This means you can revoke access to your resources at any time by simply revoking the SAS token.
Azure SAS tokens are generated using a secret key, which should be kept secure to prevent unauthorized access. This is typically done by storing the key in a secure location, such as an Azure Key Vault.
Creating a Shared Access Signature
Creating a Shared Access Signature (SAS) is a crucial step in granting temporary access to your Azure storage resources. You can create a SAS token in the Azure portal or using Azure Storage Explorer.
To create a SAS token in the Azure portal, navigate to your storage account, containers, and then the specific container or file you want to grant access to. Right-click the container or file and select Generate SAS from the drop-down menu. Select Signing method → User delegation key.
You can also create a SAS token using Azure Storage Explorer. First, connect your storage account to the app, then navigate to Blob Containers and select the container you want to grant access to. Right-click the container node and select Get Shared Access Signature... from the options menu.
A SAS token is required to have the sig parameter, which is a Base64-encoded SHA256 HMAC that provides integrity to the SAS token. Any changes made to the SAS token will be detected through this signature, and requests will be rejected.
To construct a SAS URL, append the SAS token (URI) to the URL for a storage service. The SAS token includes the service, resource, and permissions that are available for access, as well as the time period during which the signature is valid.
Here's a breakdown of the components of a SAS URI:
- Resource URI: The service endpoint, with parameters for getting service properties or setting service properties.
- Delimiter: The delimiter that precedes the query string.
- Storage services version: The version of Azure Storage services to use.
- Services: The SAS applies to the Blob services.
- Resource types: The SAS applies to service-level, container-level, and object-level operations.
- Permissions: The permissions grant access to read, write, list, and create operations.
- Start time: Specified in UTC time.
- Expiry time: Specified in UTC time.
- Protocol: Only requests that use HTTPS are permitted.
- Signature: Used to authorize access to the blob.
Understanding Permissions
Understanding Permissions is a crucial aspect of Azure Shared Access Signature. You have fine-grained control over who can do what with your resources by specifying actions in SAS tokens.
SAS tokens allow you to define permissions for specific operations, such as read-only access or read-write access. This way, you can control what actions someone can perform with your resources.
Common values for signed permissions include Create, Read, Add, Write, Delete, and List. These values can be combined to allow multiple actions, such as listing objects and reading their contents.
Values like sp=rl or sp=rw may provide more functionality than the application itself, so be careful when inspecting them.
Grant Flexible Temporary
Granting temporary access to your resources is a great way to collaborate with others without compromising your security. You can create Shared Access Signatures (SAS) that expire after a certain period, reducing the risk of unauthorized access.
With SAS tokens, you can specify a time range for access, such as 3 hours or 1 day. For example, you might create a SAS token that expires in 1 hour, allowing a contractor to upload files but not delete them. This ensures that access is only granted for the duration needed.
You can also specify a start time for the SAS token, so that access is only available during a specific time window. For instance, you might create a SAS token that starts at 9:00 AM and expires at 5:00 PM.
Here are some common use cases for temporary access:
- Collaborating with a partner company for a short-term project
- Allowing a contractor to access resources for a specific task
- Providing temporary access to a resource for testing or debugging purposes
In each of these cases, creating a SAS token with a specific time range and start time can help you manage access and reduce the risk of unauthorized access.
Permissions
Permissions are a crucial aspect of sharing access to your resources. You can specify exactly what actions someone can perform, such as read-only access or read-write access.
Signed permissions are defined by the value of the sp parameter in a SAS token. Common values include Create, Read, Add, Write, Delete, and List.
You can combine values to allow multiple actions. For example, sp=rl would allow for listing all objects within a resource and reading the contents of each of those objects.
The permissions granted by a SAS token should be inspected carefully, as they may provide more functionality than the application itself. Even seemingly safe permissions, like sp=rw, can be abused by an attacker to rack up a large Azure bill through egress costs.
Here are some common values for the sp parameter:
By carefully selecting the permissions granted by a SAS token, you can ensure that the right people have the right level of access to your resources, reducing the risk of unauthorized access.
Generating Tokens
To generate tokens, you'll need to create a shared access signature (SAS) token. You can do this in the Azure portal or using Azure Storage Explorer. To create a SAS token for a container, navigate to your storage account, click on the container, and select "Generate SAS" from the drop-down menu.
The Azure portal provides a straightforward process for creating SAS tokens. Select the signing method as "User delegation key" and define the permissions by checking or clearing the appropriate checkbox. You'll also need to specify the signed key start and expiry times.
In Azure Storage Explorer, you can create tokens for a storage container or specific blob file. To create a token for a container, open the app, navigate to your connected storage account, expand the blob containers node, and right-click on the container node to display the options menu. Select "Get Shared Access Signature..." from the menu.
To create a token for a specific blob file, follow the same steps as above, but select the file where you wish to delegate SAS access and right-click to display the options menu. Select "Get Shared Access Signature..." from the menu.
Here's a quick rundown of the steps to create a SAS token:
- Right-click the container or file and select Generate SAS from the drop-down menu.
- Select Signing method → User delegation key.
- Define Permissions by checking and/or clearing the appropriate check box.
- Specify the signed key Start and Expiry times.
- Copy and paste the Blob SAS token query string and Blob SAS URL values in a secure location.
Remember, the allowed IP addresses and protocols fields are optional, but they can help you control access to your resources.
Token Management
Token management is crucial when dealing with Azure Shared Access Signature (SAS) tokens. Establishing a centralized system or tool for managing SAS tokens across the organization can simplify integration complexity and reduce the risk of security breaches.
To overcome the challenges associated with managing SAS tokens, you can implement a centralized system or tool for managing SAS tokens. This system should allow administrators to create, monitor, and revoke SAS tokens centrally.
Here are some key features to consider when setting up a centralized system for SAS token management:
- Role-based access control (RBAC) to delegate token management responsibilities to specific teams or individuals.
- Regular rotation and revocation of SAS tokens to minimize the risk of security breaches.
- Monitoring and auditing of SAS token usage to detect any unusual activity.
By implementing these features, you can ensure that your SAS tokens are secure, up-to-date, and easily manageable, reducing the risk of security breaches and simplifying integration complexity.
Tokens Explained
A SAS token is a special key that allows different people or systems to access specific resources in a storage service without giving them the master key (account keys).
Imagine you're trying to access a specific room in a building, and you don't have the master key to the building. A SAS token is like a special key that allows you to access that specific room without having the master key.
You can create SAS tokens in the Azure portal or using the Azure Storage Explorer app. In the Azure portal, you can create SAS tokens for a container or a specific file by right-clicking on the container or file and selecting Generate SAS from the drop-down menu.
To create a SAS token, you'll need to specify the signing method, permissions, start and expiry times, and allowed IP addresses or protocols. You can also specify a range of IP addresses or protocols if needed.
Here are the most common parameters that can be included in a SAS token:
- Signing method: User delegation key
- Permissions: Read, Write, Delete, etc.
- Start and Expiry times: Specify the date and time when the token becomes valid and expires
- Allowed IP addresses: Specify the IP addresses or range of IP addresses from which to accept requests
- Allowed protocols: Specify the protocol permitted for a request made with the SAS
Once you've created a SAS token, you can copy and paste the token and URL values in a secure location. They'll only be displayed once and cannot be retrieved once the window is closed. To construct a SAS URL, append the SAS token (URI) to the URL for a storage service.
Token Management Challenges
Token management can be a complex task, especially when dealing with multiple users or services that need access to different resources. Managing SAS tokens can become overwhelming.
If you have many users or services that need access to different resources, managing all the SAS tokens can become complex. Keeping track of who has access to what and ensuring tokens are regularly rotated and revoked can be challenging. This is why it's essential to establish a centralized system or tool for managing SAS tokens across the organization.
A centralized system should allow administrators to create, monitor, and revoke SAS tokens centrally. It can include features such as role-based access control (RBAC) to delegate token management responsibilities to specific teams or individuals.
Here are some key benefits of implementing a centralized system for managing SAS tokens:
- Improved security: A centralized system helps ensure that SAS tokens are properly rotated and revoked, reducing the risk of token misuse.
- Increased efficiency: With a centralized system, administrators can easily monitor and manage SAS tokens, reducing the time and effort required to do so.
- Enhanced scalability: A centralized system can handle a large number of users and services, making it easier to manage SAS tokens as your organization grows.
Configuring an Expiration Policy
To configure an expiration policy for your Azure Shared Access Signature (SAS), you can use the Azure portal, PowerShell, or Azure CLI. You can configure a SAS expiration policy on a storage account, which applies to each type of SAS: user delegation SAS, service SAS, and account SAS.
You can configure the policy using the Azure portal by navigating to your storage account, selecting Configuration, and enabling the setting for Allow recommended upper limit for shared access signature (SAS) expiry interval. If the setting is grayed out, you'll need to rotate both account access keys before you can set the Recommended upper limit for SAS expiry interval values.
The policy specifies the recommended upper limit for the signed expiry field on a SAS, which is a date/time value that is a combined number of days, hours, minutes, and seconds. The validity interval for the SAS is calculated by subtracting the date/time value of the signed start field from the date/time value of the signed expiry field.
To configure a SAS expiration policy using PowerShell, you can use the Set-AzStorageAccount command and set the -SasExpirationPeriod parameter to the number of days, hours, minutes, and seconds that a SAS token can be active from the time that a SAS is signed. For example, if you wanted the SAS to expire 1 day, 12 hours, 5 minutes, and 6 seconds after it's signed, you would use the string 1.12:05:06.
Here are the steps to configure a SAS expiration policy using Azure CLI:
- Navigate to your storage account.
- Use the az storage account update command and set the --key-exp-days parameter to the number of days, hours, minutes, and seconds that a SAS token can be active from the time that a SAS is signed.
- You can also set the SAS expiration policy as you create a storage account by setting the --key-exp-days parameter of the az storage account create command.
- To verify that the policy has been applied, call the az storage account show command and use the string {SasPolicy:sasPolicy} for the -query parameter.
A user delegation SAS is signed with a user delegation key, which has its own expiry interval that isn't subject to the SAS expiration policy. The SAS expiration policy applies only to the user delegation SAS, not the user delegation key it's signed with.
Best Practices
Securing your Azure Shared Access Signature (SAS) tokens is crucial to prevent unauthorized access to your data. Limit access to only the necessary permissions, so if someone only needs to read files, don't give them permissions to delete or modify them.
Set the expiration time of your SAS tokens to be as short as possible while still allowing enough time for the task to be completed. This helps minimize the risk if the token is somehow leaked.
Always use HTTPS when transmitting SAS tokens to encrypt the communication between your client and the Azure service. This makes it much harder for anyone to intercept or tamper with the token.
Store your SAS tokens securely, such as in a secure vault or as environment variables, and don't hardcode them in your application code or share them openly. Treat them like passwords.
Regularly rotate (change) your SAS tokens, especially if you suspect they might have been compromised. This ensures that even if a token is leaked, it won't be valid for long.
Monitor and audit who is using your SAS tokens and what they're doing with them. Keep track of access logs and permissions to ensure they're still appropriate.
Frequently Asked Questions
What is the difference between access keys and shared access signature?
Access keys grant full access to a storage account, whereas Shared Access Signatures (SAS) allow you to control and limit user access to specific actions and timeframes. This provides a more secure and flexible way to manage user permissions.
What are the recommended best practices of a shared access signature compromised?
To minimize damage, limit access to a compromised Shared Access Signature (SAS) to a single entity with read-only permissions. This reduces the attacker's power and prevents further unauthorized access.
Sources
- https://learn.microsoft.com/en-us/rest/api/storageservices/create-account-sas
- https://learn.microsoft.com/en-us/azure/ai-services/translator/document-translation/how-to-guides/create-sas-tokens
- https://bigid.com/blog/understanding-azure-sas-tokens/
- https://www.netspi.com/blog/technical-blog/web-application-pentesting/azure-sas-tokens/
- https://learn.microsoft.com/en-us/azure/storage/common/sas-expiration-policy
Featured Images: pexels.com