You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/storage/blobs/storage-quickstart-blobs-cli.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ For more information about authentication` with Azure CLI, see [Sign in with Azu
40
40
41
41
You can authorize access to Blob storage from the Azure CLI either with Azure AD credentials or by using the storage account access key. Using Azure AD credentials is recommended. This article shows how to authorize Blob storage operations using Azure AD.
42
42
43
-
Azure CLI commands for data operations against Blob storage support the `--auth-mode` parameter, which enables you to specify how to authorize a given operation. Set the `--auth-mode` parameter to `login` to authorize with Azure AD credentials. For more information, see [Run Azure CLI commands with Azure AD credentials to access blob or queue data](../common/authorize-active-directory-cli.md?toc=%2fazure%2fstorage%2fblobs%2ftoc.json).
43
+
Azure CLI commands for data operations against Blob storage support the `--auth-mode` parameter, which enables you to specify how to authorize a given operation. Set the `--auth-mode` parameter to `login` to authorize with Azure AD credentials. For more information, see [Authorize access to blob or queue data with Azure CLI](../common/authorize-data-operations-cli.md?toc=%2fazure%2fstorage%2fblobs%2ftoc.json).
44
44
45
45
Only Blob storage data operations support the `--auth-mode` parameter. Management operations, such as creating a resource group or storage account, automatically use Azure AD credentials for authorization.
Copy file name to clipboardExpand all lines: articles/storage/common/authorize-data-operations-cli.md
+39-34Lines changed: 39 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,8 +17,8 @@ ms.subservice: common
17
17
18
18
Azure Storage provides extensions for Azure CLI that enable you to specify how you want to authorize operations on blob or queue data. You can authorize data operations in the following ways:
19
19
20
-
-By specifying Azure Active Directory (Azure AD) credentials (recommended).
21
-
-By specifying the account access key or a shared access signature (SAS) token.
20
+
-With an Azure Active Directory (Azure AD) security principal. Microsoft recommends using Azure AD credentials for superior security and ease of use.
21
+
-With the account access key or a shared access signature (SAS) token.
22
22
23
23
## Specify how data operations are authorized
24
24
@@ -27,53 +27,30 @@ Azure CLI commands for reading and writing blob and queue data include the optio
27
27
- Set the `--auth-mode` parameter to `login` to sign in using an Azure AD security principal.
28
28
- Set the `--auth-mode` parameter to the legacy `key` value to attempt to query for an account key if no authentication parameters for the account are provided.
29
29
30
-
## Call Azure CLI commands using Azure AD credentials
30
+
To use the `--auth-mode` parameter, make sure that you have installed Azure CLI version 2.0.46 or later. Run `az --version` to check your installed version.
31
+
32
+
## Authorize with Azure AD credentials
31
33
32
34
When you sign in to Azure CLI with Azure AD credentials, an OAuth 2.0 access token is returned. That token is automatically used by Azure CLI to authorize subsequent data operations against Blob or Queue storage. For supported operations, you no longer need to pass an account key or SAS token with the command.
33
35
34
36
You can assign permissions to blob and queue data to an Azure AD security principal via role-based access control (RBAC). For more information about RBAC roles in Azure Storage, see [Manage access rights to Azure Storage data with RBAC](storage-auth-aad-rbac.md).
35
37
36
-
### Supported operations
38
+
### Permissions for calling data operations
37
39
38
40
The Azure Storage extensions are supported for operations on blob and queue data. Which operations you may call depends on the permissions granted to the Azure AD security principal with which you sign in to Azure CLI. Permissions to Azure Storage containers or queues are assigned via RBAC. For example, if you are assigned the **Blob Data Reader** role, then you can run scripting commands that read data from a container or queue. If you are assigned the **Blob Data Contributor** role, then you can run scripting commands that read, write, or delete a container or queue or the data they contain.
39
41
40
42
For details about the permissions required for each Azure Storage operation on a container or queue, see [Call storage operations with OAuth tokens](/rest/api/storageservices/authorize-with-azure-active-directory#call-storage-operations-with-oauth-tokens).
41
43
42
-
### Example: Authorize with Azure AD
43
-
44
-
The following example shows how to create a container in a new storage account from Azure CLI using your Azure AD credentials. Remember to replace placeholder values in angle brackets with your own values:
45
-
46
-
1. Make sure that you have installed Azure CLI version 2.0.46 or later. Run `az --version` to check your installed version.
47
-
48
-
1. Run `az login` and authenticate in the browser window:
44
+
### Example: Authorize an operation to create a container with Azure AD credentials
49
45
50
-
```azurecli
51
-
az login
52
-
```
53
-
54
-
1. Specify your desired subscription. Create a resource group using [az group create](https://docs.microsoft.com/cli/azure/group?view=azure-cli-latest#az-group-create). Create a storage account within that resource group using [az storage account create](https://docs.microsoft.com/cli/azure/storage/account?view=azure-cli-latest#az-storage-account-create):
55
-
56
-
```azurecli
57
-
az account set --subscription <subscription-id>
58
-
59
-
az group create \
60
-
--name sample-resource-group-cli \
61
-
--location eastus
62
-
63
-
az storage account create \
64
-
--name <storage-account> \
65
-
--resource-group sample-resource-group-cli \
66
-
--location eastus \
67
-
--sku Standard_ZRS \
68
-
--encryption-services blob
69
-
```
46
+
The following example shows how to create a container from Azure CLI using your Azure AD credentials. To create the container, you'll need to log in to the Azure CLI, and you'll need a resource group and a storage account. To learn how to create these resources, see [Quickstart: Create, download, and list blobs with Azure CLI](../blobs/storage-quickstart-blobs-cli.md).
70
47
71
48
1. Before you create the container, assign the [Storage Blob Data Contributor](../../role-based-access-control/built-in-roles.md#storage-blob-data-contributor) role to yourself. Even though you are the account owner, you need explicit permissions to perform data operations against the storage account. For more information about assigning RBAC roles, see [Grant access to Azure blob and queue data with RBAC in the Azure portal](storage-auth-aad-rbac.md).
72
49
73
50
> [!IMPORTANT]
74
51
> RBAC role assignments may take a few minutes to propagate.
75
52
76
-
1. Call the [az storage container create](https://docs.microsoft.com/cli/azure/storage/container?view=azure-cli-latest#az-storage-container-create) command with the `--auth-mode` parameter set to `login` to create the container using your Azure AD credentials:
53
+
1. Call the [az storage container create](/cli/azure/storage/container#az-storage-container-create) command with the `--auth-mode` parameter set to `login` to create the container using your Azure AD credentials. Remember to replace placeholder values in angle brackets with your own values:
77
54
78
55
```azurecli
79
56
az storage container create \
@@ -82,13 +59,41 @@ The following example shows how to create a container in a new storage account f
82
59
--auth-mode login
83
60
```
84
61
85
-
## Call Azure CLI commands using the account access key
62
+
## Authorize with the account access key
63
+
64
+
If you possess the account key, you can call any Azure Storage data operation. In general, using the account key is less secure. If the account key is compromised, all data in your account may be compromised.
65
+
66
+
The following example shows how to create a container using the account access key:
86
67
68
+
```azurecli
69
+
az storage container create \
70
+
--account-name <storage-account> \
71
+
--name sample-container \
72
+
--auth-mode key
73
+
```
87
74
75
+
## Authorize with a SAS token
76
+
77
+
If you possess a SAS token, you can call data operations that are permitted by the SAS. The following example shows how to create a container using a SAS token:
78
+
79
+
```azurecli
80
+
az storage container create \
81
+
--account-name <storage-account> \
82
+
--name sample-container \
83
+
--sas-token <token>
84
+
```
88
85
89
86
## Set environment variables for authorization parameters
90
87
91
-
The environment variable associated with the `--auth-mode` parameter is `AZURE_STORAGE_AUTH_MODE`. You can specify the appropriate value in the environment variable to avoid including it on every call to an Azure Storage data operation.
88
+
You can specify authorization parameters in environment variables to avoid including them on every call to an Azure Storage data operation. The following table describes the available environment variables.
| AZURE_STORAGE_ACCOUNT | The storage account name. This variable must be used in conjunction with either the storage account key or a SAS token. If neither are present, the command will attempt to query the storage account key using the authenticated Azure AD account. If a large number of storage commands are executed at one time, the API throttling limit may be reached. |
93
+
| AZURE_STORAGE_KEY | The storage account key. This variable must be used in conjunction with the storage account name. |
94
+
| AZURE_STORAGE_CONNECTION_STRING | A connection string that includes the storage account key or a SAS token. This variable must be used in conjunction with the storage account name. |
95
+
| AZURE_STORAGE_SAS_TOKEN | A shared access signature (SAS) token. This variable must be used in conjunction with the storage account name. |
96
+
| AZURE_STORAGE_AUTH_MODE | The authorization mode with which to run the command. Permitted values are `login` (recommended) or `key`. If you specify `login`, the Azure CLI will use your Azure AD credentials to authorize the data operation. If you specify the legacy `key` mode, the Azure CLI will attempt to query for the account access key and authorize the command with the key. |
0 commit comments