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
+46-21Lines changed: 46 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,54 +1,79 @@
1
1
---
2
-
title: Run Azure CLI or PowerShell commands under an Azure AD identity to access Azure Storage (Preview) | Microsoft Docs
2
+
title: Run Azure CLI or PowerShell commands under an Azure AD identity to access Azure Storage | Microsoft Docs
3
3
description: Azure CLI and PowerShell support logging in with an Azure AD identity to run commands on Azure Storage containers and queues and their data. An access token is provided for the session and used to authorize calling operations. Permissions depend on the role assigned to the Azure AD identity.
4
4
services: storage
5
5
author: tamram
6
6
7
7
ms.service: storage
8
8
ms.topic: article
9
-
ms.date: 10/15/2018
9
+
ms.date: 03/12/2019
10
10
ms.author: tamram
11
11
ms.subservice: common
12
12
---
13
13
14
-
# Use an Azure AD identity to access Azure Storage with CLI or PowerShell (Preview)
14
+
# Use an Azure AD identity to access Azure Storage with CLI or PowerShell
15
15
16
-
Azure Storage provides preview extensions for Azure CLI and PowerShell that enable you to log in and run scripting commands under an Azure Active Directory (Azure AD) identity. The Azure AD identity can be a user, group, or application service principal, or it can be a [managed identity for Azure resources](../../active-directory/managed-identities-azure-resources/overview.md). You can assign permissions to access storage resources to the Azure AD identity 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 (Preview)](storage-auth-aad-rbac.md).
16
+
Azure Storage provides extensions for Azure CLI and PowerShell that enable you to log in and run scripting commands under an Azure Active Directory (Azure AD) identity. The Azure AD identity can be a user, group, or application service principal, or it can be a [managed identity for Azure resources](../../active-directory/managed-identities-azure-resources/overview.md). You can assign permissions to access storage resources to the Azure AD identity 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 (Preview)](storage-auth-aad-rbac.md).
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 preview 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.
24
+
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
25
26
26
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
27
28
28
## Call CLI commands with an Azure AD identity
29
29
30
-
To install the preview extension for Azure CLI:
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.
31
31
32
-
1. Make sure that you have installed Azure CLI version 2.0.32 or later. Run `az --version` to check your installed version.
33
-
2. Run the following command to install the preview extension:
32
+
Azure CLI supports the `--auth-mode` parameter for data operations against Azure Storage:
33
+
34
+
- Set the `--auth-mode` parameter to `login` to sign in using an Azure AD security principal.
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
+
37
+
The following example shows how to create a container in a new storage account from Azure CLI using your Azure AD credentials.
38
+
39
+
1. First, run `az login` and authenticate in the browser window:
34
40
35
41
```azurecli
36
-
az extension add -n storage-preview
42
+
az login
37
43
```
44
+
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:
38
46
39
-
The preview extension adds a new `--auth-mode` parameter to supported commands:
47
+
```azurecli
48
+
az account set --subscription <subscription-id>
49
+
az group create \
50
+
--name sample-resource-group \
51
+
--location eastus
52
+
az storage account create \
53
+
--name <storage-account> \
54
+
--resource-group sample-resource-group \
55
+
--location eastus \
56
+
--sku Standard_LRS \
57
+
--encryption-services blob
58
+
```
59
+
60
+
1. Before you create the container, assign RBAC permissions to the new storage account for yourself. Assign these two roles:
40
61
41
-
- Set the `--auth-mode` parameter to `login` to sign in using an Azure AD identity.
42
-
- 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.
62
+
- Owner
63
+
- Storage Blob Data Contributor (preview)
43
64
44
-
For example, to download a blob in Azure CLI using an Azure AD identity, first run `az login`, then call the command with `--auth-mode` set to `login`:
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).
66
+
67
+
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:
The environment variable associated with the `--auth-mode` parameter is `AZURE_STORAGE_AUTH_MODE`.
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.
52
77
53
78
## Call PowerShell commands with an Azure AD identity
54
79
@@ -74,10 +99,10 @@ To use Azure PowerShell to sign in with an Azure AD identity:
74
99
Install-Module Az –Repository PSGallery –AllowClobber
75
100
```
76
101
77
-
1. Install an Azure Storage preview module that supports Azure AD:
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.
@@ -87,7 +112,7 @@ The following example shows how to list the blobs in a container from Azure Powe
0 commit comments