Azure Docs

Blob Storage Access Control

Securing your data in Azure Blob Storage is paramount. This document outlines the various mechanisms available for controlling access to your blobs, ensuring only authorized users and applications can interact with your data.

Key Concepts

Azure Blob Storage provides a layered approach to security. You can control access at the storage account level, container level, and individual blob level.

Authentication Methods

1. Azure Active Directory (Azure AD) Authentication

This is the recommended method for modern applications and services. Azure AD allows you to manage identities centrally and assign granular permissions using Role-Based Access Control (RBAC).

Tip

Leveraging Azure AD with RBAC provides a more secure and manageable access control solution compared to shared access signatures (SAS) for service-to-service communication.

You can assign built-in roles like Storage Blob Data Reader, Storage Blob Data Contributor, and Storage Blob Data Owner to Azure AD principals at the storage account or container scope.

2. Shared Access Signatures (SAS)

SAS tokens provide a delegated way to grant limited access to blobs or containers. You can specify the start and expiry times, permissions (read, write, delete, list), and the IP address range or HTTP methods allowed.

There are two types of SAS:


// Example of generating a blob SAS token (using Azure Storage SDK for .NET)
var blobClient = containerClient.GetBlobClient(blobName);
var sasUri = blobClient.GenerateSasUri(new BlobSasBuilder()
{
    ExpiresOn = DateTimeOffset.UtcNow.AddHours(1),
    Protocol = SasProtocol.Https,
    StartsOn = DateTimeOffset.UtcNow.AddMinutes(-5), // Allow for clock skew
    Permissions = "rwdl" // read, write, delete, list
});
Console.WriteLine($"SAS URI: {sasUri}");
            

3. Account Key Access

Accessing blobs using the storage account access key provides full administrative access to the storage account. This method should be used with extreme caution and is generally not recommended for application access.

Important

Never embed storage account keys directly in client-side code or in applications that are publicly accessible. If an account key is compromised, all data in the storage account is at risk.

Authorization Mechanisms

1. Role-Based Access Control (RBAC)

RBAC is the primary authorization mechanism when using Azure AD authentication. You assign roles to users, groups, service principals, or managed identities. These roles define a set of permissions that determine what actions the principal can perform on Azure resources.

For Blob Storage, relevant RBAC roles include:

These roles can be assigned at the subscription, resource group, storage account, or container level.

2. Access Control Lists (ACLs) for Hierarchical Namespaces (ADLS Gen2)

If your storage account has the hierarchical namespace feature enabled (Azure Data Lake Storage Gen2), you can also use POSIX-like Access Control Lists (ACLs) on directories and files. ACLs provide finer-grained control over individual file and directory access.

ACLs can be managed alongside RBAC. When both are present, the most restrictive permission set typically applies.

Best Practices for Access Control

Container Access Level

You can configure the default access level for a container. This setting determines how unauthenticated users can access blobs within that container.

Highlight

Be extremely cautious when setting a container's access level to Blob or Container, as this makes your data publicly accessible. Ensure this is the intended behavior and that no sensitive data is exposed.

By understanding and implementing these access control mechanisms, you can effectively secure your data in Azure Blob Storage.