Azure Storage Blobs Documentation

Container Access Policies

Azure Blob Storage allows you to control access to your containers and the blobs within them. Container access policies define how clients can access blobs without requiring Azure credentials. This is particularly useful for scenarios like sharing files publicly or providing temporary access.

There are two primary ways to manage container access:

1. Public Access Level

You can configure the public access level for a container at three granularities:

Configuring Public Access

You can configure the public access level through the Azure portal, Azure CLI, PowerShell, or REST API.

Using Azure CLI:


az storage container set-permission \
    --account-name  \
    --name  \
    --public-access blob
            

Replace and with your actual values.

Important: Setting a container to public access means anyone with the URL can access the blobs. Be mindful of sensitive data.

2. Shared Access Signatures (SAS)

SAS tokens are a powerful mechanism for delegating access to Blob Storage resources. A SAS token is a string that contains a security token and is appended to the URI of a Blob Storage resource.

Types of SAS:

SAS Permissions:

When creating a SAS, you can specify the following permissions:

SAS Expiry and Start Time:

You must specify an expiry time for a SAS token. You can also specify a start time to indicate when the token becomes valid.

Generating a SAS Token (Azure CLI Example):

This example generates a service SAS for a blob with read, write, and delete permissions, valid for one hour.


az storage blob generate-sas \
    --account-name  \
    --container-name  \
    --name  \
    --permissions rwd \
    --expiry $(date -u -d "1 hour" '+%Y-%m-%dT%H:%MZ') \
    --output tsv
            

The output will be the SAS token itself. You append this token to the blob's URI.

Example URI with SAS: https://.blob.core.windows.net//?sv=2020-08-04&ss=b&srt=sco&sp=rwd&se=2023-10-27T10%3A00%3A00Z&st=2023-10-27T09%3A00%3A00Z&spr=https&sig=...

Security Best Practice: Never embed SAS tokens directly in client-side code or public repositories. Generate them dynamically on your backend and provide them to trusted clients. Always set the shortest possible expiry time.

Key Considerations:

Understanding and implementing container access policies and SAS tokens are crucial for secure and efficient management of your Azure Blob Storage data.