Learn how to generate Shared Access Signatures (SAS) for secure delegated access to your Azure Blob Storage resources.
A Shared Access Signature (SAS) provides a secure way to delegate access to your Azure Storage resources, such as blobs, containers, or tables, without sharing your account access keys. You can grant clients access to specific resources for a defined period and with specific permissions.
A SAS is a URI that contains a security token in its query parameters. This token represents delegated permissions to your storage resources. The SAS allows clients to access your storage accounts without their own Azure credentials. Key benefits include:
You can generate SAS tokens using several methods:
The Azure portal offers a user-friendly interface to generate SAS tokens for blobs and containers.
Navigate to your storage account, select the container or blob, and use the "Shared access signature" option in the left-hand menu. Configure permissions, expiry, and other settings, then copy the generated SAS token.
Use the Azure Command-Line Interface for scriptable SAS generation.
az storage blob generate-sas \
--account-name \
--container-name \
--name \
--permissions rwdlacu \
--expiry 2024-12-31T23:59:59Z \
--output tsv
Replace placeholders like <your-storage-account-name> with your actual values.
Leverage Azure Storage SDKs available in various programming languages to programmatically generate SAS.
Example using Python SDK:
from azure.storage.blob import BlobServiceClient, AccountSasPermissions, ResourceTypes
connect_str = ""
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
sas_permissions = AccountSasPermissions(read=True, write=True, delete=True, list=True)
sas_token = blob_service_client.generate_account_sas(
resource_types=ResourceTypes(container=True, object=True),
permission=sas_permissions,
expiry='2024-12-31T23:59:59Z'
)
print(f"Generated SAS Token: {sas_token}")
A SAS URI typically looks like this:
https://[account name].blob.core.windows.net/[container name]/[blob name]?[canonicalized resource]&[signature]
[canonicalized resource]: Includes parameters like sv (signed version), ss (signed services), srt (signed resource types), sp (signed permissions), se (signed expiry), st (signed start), sip (signed IP), and spr (signed protocol).[signature]: The HMAC-SHA256 hash of the string-to-sign.