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/common/storage-auth-aad-script.md
+51-43Lines changed: 51 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ author: tamram
6
6
7
7
ms.service: storage
8
8
ms.topic: article
9
-
ms.date: 03/12/2019
9
+
ms.date: 03/06/2019
10
10
ms.author: tamram
11
11
ms.subservice: common
12
12
---
@@ -17,52 +17,53 @@ Azure Storage provides extensions for Azure CLI and PowerShell that enable you t
17
17
18
18
When you log in to Azure CLI or PowerShell with an Azure AD identity, an access token is returned for accessing Azure Storage under that identity. That token is then automatically used by CLI or PowerShell to authorize operations against Azure Storage. For supported operations, you no longer need to pass an account key or SAS token with the command.
The extensions are supported for operations on containers and queues. Which operations you may call depends on the permissions granted to the Azure AD identity with which you log in to Azure CLI or PowerShell. Permissions to Azure Storage containers or queues are assigned via role-based access control (RBAC). For example, if a Data Reader role is assigned to the identity, then you can run scripting commands that read data from a container or queue. If a Data Contributor role is assigned to the identity, then you can run scripting commands that read, write, or delete a container or queue or the data they contain.
25
23
26
24
For details about the permissions required for each Azure Storage operation on a container or queue, see [Permissions for calling REST operations](https://docs.microsoft.com/rest/api/storageservices/authenticate-with-azure-active-directory#permissions-for-calling-rest-operations).
27
25
28
-
## Call CLI commands with an Azure AD identity
26
+
## Environment variable
27
+
28
+
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.
29
29
30
-
To install the extension for Azure CLI, make sure that you have installed Azure CLI version 2.0.46 or later. Run `az --version` to check your installed version.
30
+
## Call CLI commands using Azure AD credentials
31
31
32
32
Azure CLI supports the `--auth-mode` parameter for data operations against Azure Storage:
33
33
34
34
- Set the `--auth-mode` parameter to `login` to sign in using an Azure AD security principal.
35
35
- 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.
36
36
37
-
The following example shows how to create a container in a new storage account from Azure CLI using your Azure AD credentials.
37
+
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:
38
+
39
+
1. Make sure that you have installed Azure CLI version 2.0.46 or later. Run `az --version` to check your installed version.
38
40
39
-
1.First, run`az login` and authenticate in the browser window:
41
+
1.Run`az login` and authenticate in the browser window:
40
42
41
43
```azurecli
42
44
az login
43
45
```
44
46
45
-
1. Next, set your subscription, then create a resource group and a storage account within that resource group. Make sure to replace placeholder values in angle brackets with your own values:
47
+
1. Next, set your subscription, then create a resource group and a storage account within that resource group:
46
48
47
49
```azurecli
48
50
az account set --subscription <subscription-id>
49
51
az group create \
50
-
--name sample-resource-group \
52
+
--name sample-resource-group-cli \
51
53
--location eastus
54
+
52
55
az storage account create \
53
56
--name <storage-account> \
54
-
--resource-group sample-resource-group \
57
+
--resource-group sample-resource-group-cli \
55
58
--location eastus \
56
59
--sku Standard_LRS \
57
60
--encryption-services blob
58
61
```
59
62
60
-
1. Before you create the container, assign RBAC permissions to the new storage account for yourself. Assign these two roles:
61
-
62
-
- Owner
63
-
- Storage Blob Data Contributor (preview)
63
+
1. Before you create the container, assign the [Storage Blob Data Contributor (preview)](../../role-based-access-control/built-in-roles.md#storage-blob-data-contributor-preview) 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 containers and queues with RBAC in the Azure portal (preview)](storage-auth-aad-rbac.md).
64
64
65
-
For more information about assigning RBAC roles, see [Grant access to Azure containers and queues with RBAC in the Azure portal (preview)](storage-auth-aad-rbac.md).
65
+
> [!IMPORTANT]
66
+
> During the preview of Azure AD support for blobs and queues, RBAC role assignments may take up to 5 minutes to propagate.
66
67
67
68
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:
68
69
@@ -73,47 +74,54 @@ The following example shows how to create a container in a new storage account f
73
74
--auth-mode login
74
75
```
75
76
76
-
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 operation.
77
-
78
-
## Call PowerShell commands with an Azure AD identity
77
+
## Call PowerShell commands using Azure AD credentials
To use Azure PowerShell to sign in with an Azure AD identity:
81
+
To use Azure PowerShell to sign in and run subsequent operations against Azure Storage using Azure AD credentials, create a storage context to reference the storage account, and including the `-UseConnectedAccount` parameter.
82
+
83
+
The following example shows how to create a container in a new storage account from Azure PowerShell using your Azure AD credentials. Remember to replace placeholder values in angle brackets with your own values:
83
84
84
-
1. Uninstall any previous installations of Azure PowerShell:
85
+
1. Sign in to your Azure subscription with the `Connect-AzAccount` command and follow the on-screen directions to enter your Azure AD credentials:
85
86
86
-
- Remove any previous installations of Azure PowerShell from Windows using the **Apps & features** setting under **Settings**.
87
-
- Remove all **Azure*** modules from `%Program Files%\WindowsPowerShell\Modules`.
87
+
```powershell
88
+
Connect-AzAccount
89
+
```
90
+
91
+
1. Create an Azure resource group by calling [New-AzResourceGroup](/powershell/module/az.resources/new-azresourcegroup).
88
92
89
-
1. Make sure that you have the latest version of PowerShellGet installed. Open a Windows PowerShell window, and run the following command to install the latest version:
1. Call the [New-AzStorageContext](https://docs.microsoft.com/powershell/module/az.storage/new-azstoragecontext) cmdlet to create a context, and include the `-UseConnectedAccount` parameter.
109
-
1. To call a cmdlet with an Azure AD identity, pass the newly created context to the cmdlet.
110
-
111
-
The following example shows how to list the blobs in a container from Azure PowerShell using an Azure AD identity. Be sure to replace the placeholder account and container names with your own values:
1. Get the storage account context that specifies the new storage account. When acting on a storage account, you can reference the context instead of repeatedly passing in the credentials. Include the `-UseConnectedAccount` parameter to call subsequent data operations using your Azure AD credentials.
1. Before you create the container, assign the [Storage Blob Data Contributor (preview)](../../role-based-access-control/built-in-roles.md#storage-blob-data-contributor-preview) 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 containers and queues with RBAC in the Azure portal (preview)](storage-auth-aad-rbac.md).
115
+
116
+
> [!IMPORTANT]
117
+
> During the preview of Azure AD support for blobs and queues, RBAC role assignments may take up to 5 minutes to propagate.
118
+
119
+
1. Create a container. Because this call uses the context created in the previous steps, the container is created using your Azure AD credentials.
0 commit comments