# Storage Account

Source: /azure/services/storage-accounts/

## Introduction

An Azure storage account serves as a centralized container for all your data objects, including blobs, files, queues, and tables. It provides a unique, globally accessible namespace reachable via HTTP or HTTPS. For more information, see [Overview of storage accounts](https://learn.microsoft.com/en-us/azure/storage/common/storage-account-overview).

LocalStack for Azure provides a local environment for building and testing applications that make use of blobs, files, queues, and tables. For more information, see:

- [Blob Storage](/azure/services/blob-storage)
- [File Storage](/azure/services/file-storage)
- [Queue Storage](/azure/services/queue-storage)
- [Table Storage](/azure/services/table-storage)

The supported APIs are available on our [API Coverage section](#api-coverage), which provides information on the extent of Storage Account's integration with LocalStack.

## Getting started

This guide is designed for users new to Azure Storage Accounts and assumes basic knowledge of the Azure CLI and our `lstk az` proxy.

Launch LocalStack using your preferred method. For more information, see [Introduction to LocalStack for Azure](/azure/getting-started/). Once the container is running, enable Azure CLI interception by running:

```bash
lstk az start-interception
```

This command points the `az` CLI away from the public Azure management REST API and toward the LocalStack for Azure emulator API.
To revert this configuration, run:

```bash
lstk az stop-interception
```

This reconfigures the `az` CLI to send commands to the official Azure management REST API.

### Create a resource group

Create a resource group for your storage account resources:

```bash
az group create \
  --name rg-storage-demo \
  --location westeurope
```

```bash title="Output"
{
  "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-storage-demo",
  "location": "westeurope",
  "managedBy": null,
  "name": "rg-storage-demo",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": null,
  "type": "Microsoft.Resources/resourceGroups"
}
```

### Create a storage account

Create a storage account with the `StorageV2` kind and `Standard_LRS` SKU:

```bash
az storage account create \
  --name stordoc86acct \
  --resource-group rg-storage-demo \
  --location westeurope \
  --sku Standard_LRS \
  --kind StorageV2
```

```bash title="Output"
{
  ...
  "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-storage-demo/providers/Microsoft.Storage/storageAccounts/stordoc86acct",
  ...
  "kind": "StorageV2",
  "location": "westeurope",
  "name": "stordoc86acct",
  ...
  "primaryEndpoints": {
    "blob": "https://stordoc86acct.blob.core.azure.localhost.localstack.cloud:4566",
    "queue": "https://stordoc86acct.queue.core.azure.localhost.localstack.cloud:4566",
    "table": "https://stordoc86acct.table.core.azure.localhost.localstack.cloud:4566",
    ...
  },
  "provisioningState": "Succeeded",
  ...
}
```

### Authentication

There are three ways to authenticate storage commands against the emulator:

#### Storage account key

Retrieve the account key and pass it with `--account-name` and `--account-key`:

```bash
ACCOUNT_KEY=$(az storage account keys list \
  --account-name stordoc86acct \
  --resource-group rg-storage-demo \
  --query "[0].value" \
  --output tsv)

az storage container list \
  --account-name stordoc86acct \
  --account-key "$ACCOUNT_KEY"
```

#### Login credentials

Use `--auth-mode login` to authenticate with the current session credentials:

```bash
az storage container list \
  --account-name stordoc86acct \
  --auth-mode login
```

#### Connection string

Bundle the account name and key into a single value:

```bash
CONNECTION_STRING=$(az storage account show-connection-string \
  --name stordoc86acct \
  --resource-group rg-storage-demo \
  --query connectionString -o tsv)

az storage container list \
  --connection-string "$CONNECTION_STRING"
```

The remaining examples in this guide use connection strings for brevity.

### Manage account keys and connection string

List the storage account access keys:

```bash
az storage account keys list \
  --account-name stordoc86acct \
  --resource-group rg-storage-demo
```

```bash title="Output"
[
  {
    "keyName": "key1",
    "permissions": "FULL",
    "value": "MWFjYTgyZjgtYzU0My00NjE0LThmZDctNzlkODg5ZjU4ZTE5",
    "..."
  },
  {
    "keyName": "key2",
    "permissions": "FULL",
    "value": "NzliNzVhN2EtYTcwZC00ZTg4LWJkMTQtYjg4MWNlMDJjZDcx",
    "..."
  }
]
```

Regenerate the primary key:

```bash
az storage account keys renew \
  --account-name stordoc86acct \
  --resource-group rg-storage-demo \
  --key key1
```

Fetch a connection string for data-plane operations:

```bash
az storage account show-connection-string \
  --name stordoc86acct \
  --resource-group rg-storage-demo
```

```bash title="Output"
{
  "connectionString": "DefaultEndpointsProtocol=https;EndpointSuffix=core.azure.localhost.localstack.cloud:4566;AccountName=stordoc86acct;AccountKey=YWQ5Y2Q2NDYtZTJmOC00ZjU3LWFmOTEtNzk5MjAxNzE1OWQx;BlobEndpoint=https://stordoc86acct.blob.core.azure.localhost.localstack.cloud:4566;FileEndpoint=https://stordoc86acct.file.core.azure.localhost.localstack.cloud:4566;QueueEndpoint=https://stordoc86acct.queue.core.azure.localhost.localstack.cloud:4566;TableEndpoint=https://stordoc86acct.table.core.azure.localhost.localstack.cloud:4566"
}
```

### Data plane authentication

The emulator validates data-plane requests to Blob, Queue, and Table Storage as Azure does:

- **Shared Key and SharedKeyLite**: The signature is checked against `key1` and `key2`. A bad signature returns `AuthenticationFailed` (403).
- **SAS tokens**: Account, service, stored access policy, and user delegation SAS tokens are checked for signature, validity window, source IP, protocol, service, resource type, and permission.
- **Bearer tokens**: The emulator checks only that a token is present.
- **Anonymous requests**: These return `NoAuthenticationInformation` (401), unless the account allows public access and the request reads a public container or blob.

Generate an account SAS and use it to list containers:

```bash
SAS=$(az storage account generate-sas \
  --account-name stordoc86acct \
  --account-key "$ACCOUNT_KEY" \
  --services b \
  --resource-types sco \
  --permissions rl \
  --expiry 2030-01-01T00:00Z \
  --output tsv)

az storage container list \
  --account-name stordoc86acct \
  --sas-token "$SAS"
```

A SAS that lacks a permission is refused. A token with a wrong signature fails with an authentication error:

```bash title="Output"
ERROR:
Authentication failure. This may be caused by either invalid account key, connection string or sas token value provided for your storage account.
```

To refuse key-based requests, set `allowSharedKeyAccess` to `false`:

```bash
az storage account update \
  --name stordoc86acct \
  --resource-group rg-storage-demo \
  --allow-shared-key-access false

az storage container list \
  --connection-string "$CONNECTION_STRING"
```

```bash title="Output"
ERROR: Key based authentication is not permitted on this storage account.
ErrorCode:KeyBasedAuthenticationNotPermitted
```

The management API also supports `listAccountSas`, `listServiceSas`, and `revokeUserDelegationKeys`.

## Features

The Storage Account emulator supports the following features:

- **Control plane REST API**: Storage account CRUD (create, read, update, delete, list), account key management, and name availability checks via Azure Resource Manager.
- **Multiple authentication modes**: Storage account key, login credentials, and connection strings.
- **Storage account management**: Create, update, delete, and list storage accounts. Supports `StorageV2`, `BlobStorage`, and `Storage` account kinds with configurable SKU, access tier, and TLS version.
- **Scoped lookups**: Get and list operations respect the subscription and resource group in the request.
- **Account properties**: Documented account properties are stored and returned. A partial update (`PATCH`) keeps the fields you omit, and create and update requests are validated as Azure does.
- **Account key management**: List and regenerate storage account keys (`key1`/`key2`). Regenerating a key returns the keys.
- **Connection string generation**: Retrieve ready-to-use connection strings containing all service endpoints (Blob, Queue, Table, File).
- **SAS management**: Generate account and service SAS tokens through the management API, and revoke user delegation keys.
- **Data plane authentication**: Shared Key, SharedKeyLite, and SAS requests are validated, and the `allowSharedKeyAccess` and `allowBlobPublicAccess` settings are enforced.
- **Blob range restore validation**: `restoreBlobRanges` validates the request, such as the restore time and the blob ranges, as Azure does.

## Limitations

- **Data Lake and static website endpoints**: The `dfs` and `web` primary endpoints point at the emulator, but the emulator doesn't serve Data Lake or static website requests.
- **Unsupported operations**: Management policies are not yet supported.
- **Header validation**: Unsupported request headers or parameters are silently accepted instead of being rejected.
- **API version enforcement**: The emulator does not validate the `x-ms-version` header; all API versions are accepted.
- **Blob range restore does not restore data**: A valid `restoreBlobRanges` request returns a restore with status `Failed`, because the emulator keeps no blob history. If a container has an immutability policy, the failure reason says so.
- **Bearer tokens are not inspected**: Data-plane requests with a bearer token succeed whenever a token is present, unless you enable [RBAC enforcement](/azure/services/role-assignment/#enabling-rbac-enforcement).
- **User delegation SAS is not re-authorized**: The emulator doesn't re-check the RBAC of the principal that requested the user delegation key when the SAS is used, and doesn't bind a user-bound SAS (`sduoid`) to the caller's token.
- **SAS source IP restrictions**: The emulator sees the Docker or loopback address, not your public address, so a SAS restricted to your public IP is refused.
- **Anonymous requests without `x-ms-version`**: When an account disallows public access, Azure answers an anonymous request that has no `x-ms-version` header with 409 `PublicAccessNotPermitted`. The emulator answers 401.

## Samples

The following samples demonstrate how to use Storage Accounts with LocalStack for Azure:

- [Azure Functions Sample with LocalStack for Azure](https://github.com/localstack/localstack-azure-samples/tree/main/samples/function-app-storage-http/dotnet)
- [Azure Functions App with Managed Identity](https://github.com/localstack/localstack-azure-samples/tree/main/samples/function-app-managed-identity/python)
- [Azure Web App with Managed Identity](https://github.com/localstack/localstack-azure-samples/tree/main/samples/web-app-managed-identity/python)

## API Coverage


### Storage Account API coverage

Source service: `storage-accounts`. 51 of 81 tracked operations are implemented.

Service documentation: /azure/services/storage-accounts/

| Operation | Status |
| --- | --- |
| AdvancedPlatformMetrics.CreateOrUpdate | Not implemented |
| AdvancedPlatformMetrics.Delete | Not implemented |
| AdvancedPlatformMetrics.Get | Not implemented |
| AdvancedPlatformMetrics.List | Not implemented |
| BlobAccessPointConfigurations.Create | Not implemented |
| BlobAccessPointConfigurations.Delete | Not implemented |
| BlobAccessPointConfigurations.Get | Not implemented |
| BlobAccessPointConfigurations.ListByStorageAccount | Not implemented |
| BlobAccessPointConfigurations.TestExistingConnection | Not implemented |
| BlobAccessPointConfigurations.Update | Not implemented |
| BlobAccessPointConnectionTests.TestProposedConnection | Not implemented |
| BlobInventoryPolicies.CreateOrUpdate | Implemented |
| BlobInventoryPolicies.Delete | Implemented |
| BlobInventoryPolicies.Get | Implemented |
| BlobInventoryPolicies.List | Implemented |
| Connectors.Create | Not implemented |
| Connectors.Delete | Not implemented |
| Connectors.Get | Not implemented |
| Connectors.ListByStorageAccount | Not implemented |
| Connectors.TestExistingConnection | Not implemented |
| Connectors.Update | Not implemented |
| DataShares.Create | Not implemented |
| DataShares.Delete | Not implemented |
| DataShares.Get | Not implemented |
| DataShares.ListByStorageAccount | Not implemented |
| DataShares.Update | Not implemented |
| EncryptionScopes.Get | Implemented |
| EncryptionScopes.List | Implemented |
| EncryptionScopes.Patch | Implemented |
| EncryptionScopes.Put | Implemented |
| LocalUsers.CreateOrUpdate | Implemented |
| LocalUsers.Delete | Implemented |
| LocalUsers.Get | Implemented |
| LocalUsers.List | Implemented |
| LocalUsers.ListKeys | Implemented |
| LocalUsers.RegeneratePassword | Implemented |
| ManagementPolicies.CreateOrUpdate | Implemented |
| ManagementPolicies.Delete | Implemented |
| ManagementPolicies.Get | Implemented |
| NetworkSecurityPerimeterConfigurations.Get | Implemented |
| NetworkSecurityPerimeterConfigurations.List | Implemented |
| NetworkSecurityPerimeterConfigurations.Reconcile | Implemented |
| ObjectReplicationPolicies.CreateOrUpdate | Implemented |
| ObjectReplicationPolicies.Delete | Implemented |
| ObjectReplicationPolicies.Get | Implemented |
| ObjectReplicationPolicies.List | Implemented |
| Operations.List | Implemented |
| PrivateEndpointConnections.Delete | Implemented |
| PrivateEndpointConnections.Get | Implemented |
| PrivateEndpointConnections.List | Implemented |
| PrivateEndpointConnections.Put | Implemented |
| PrivateLinkResources.ListByStorageAccount | Implemented |
| Skus.List | Implemented |
| StorageAccounts.AbortHierarchicalNamespaceMigration | Implemented |
| StorageAccounts.CheckNameAvailability | Implemented |
| StorageAccounts.Create | Implemented |
| StorageAccounts.CustomerInitiatedMigration | Implemented |
| StorageAccounts.Delete | Implemented |
| StorageAccounts.Failover | Implemented |
| StorageAccounts.GetCustomerInitiatedMigration | Implemented |
| StorageAccounts.GetProperties | Implemented |
| StorageAccounts.HierarchicalNamespaceMigration | Implemented |
| StorageAccounts.List | Implemented |
| StorageAccounts.ListAccountSas | Implemented |
| StorageAccounts.ListByResourceGroup | Implemented |
| StorageAccounts.ListKeys | Implemented |
| StorageAccounts.ListServiceSas | Implemented |
| StorageAccounts.RegenerateKey | Implemented |
| StorageAccounts.RestoreBlobRanges | Implemented |
| StorageAccounts.RevokeUserDelegationKeys | Implemented |
| StorageAccounts.Update | Implemented |
| StorageTaskAssignmentInstancesReport.List | Not implemented |
| StorageTaskAssignments.Create | Not implemented |
| StorageTaskAssignments.Delete | Not implemented |
| StorageTaskAssignments.Get | Not implemented |
| StorageTaskAssignments.List | Not implemented |
| StorageTaskAssignments.StopAssignment | Not implemented |
| StorageTaskAssignments.Update | Not implemented |
| StorageTaskAssignmentsInstancesReport.List | Not implemented |
| Usage.List | Implemented |
| Usages.ListByLocation | Implemented |
