Skip to content

Commit 5eedc7d

Browse files
committed
adding PS and CLI GA examples
1 parent 20130fb commit 5eedc7d

File tree

1 file changed

+46
-21
lines changed

1 file changed

+46
-21
lines changed

articles/storage/common/storage-auth-aad-script.md

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,79 @@
11
---
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
33
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.
44
services: storage
55
author: tamram
66

77
ms.service: storage
88
ms.topic: article
9-
ms.date: 10/15/2018
9+
ms.date: 03/12/2019
1010
ms.author: tamram
1111
ms.subservice: common
1212
---
1313

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
1515

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).
1717

1818
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.
1919

2020
[!INCLUDE [storage-auth-aad-note-include](../../../includes/storage-auth-aad-note-include.md)]
2121

2222
## Supported operations
2323

24-
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.
2525

2626
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).
2727

2828
## Call CLI commands with an Azure AD identity
2929

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.
3131

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:
3440

3541
```azurecli
36-
az extension add -n storage-preview
42+
az login
3743
```
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:
3846
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:
4061
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)
4364
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:
4568
46-
```azurecli
47-
az login
48-
az storage blob download --account-name storagesamples --container sample-container --name myblob.txt --file myfile.txt --auth-mode login
49-
```
69+
```azurecli
70+
az storage container create \
71+
--account-name <storage-account> \
72+
--name sample-container \
73+
--auth-mode login
74+
```
5075
51-
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.
5277
5378
## Call PowerShell commands with an Azure AD identity
5479
@@ -74,10 +99,10 @@ To use Azure PowerShell to sign in with an Azure AD identity:
7499
Install-Module Az –Repository PSGallery –AllowClobber
75100
```
76101
77-
1. Install an Azure Storage preview module that supports Azure AD:
102+
1. Install the latest Azure Storage module:
78103
79104
```powershell
80-
Install-Module Az.Storage -Repository PSGallery -AllowPrerelease -AllowClobber -Force
105+
Install-Module Az.Storage -Repository PSGallery -AllowClobber -Force
81106
```
82107
1. Close and reopen the PowerShell window.
83108
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
87112

88113
```powershell
89114
$ctx = New-AzStorageContext -StorageAccountName storagesamples -UseConnectedAccount
90-
Get-AzStorageBlob -Container sample-container -Context $ctx
115+
Get-AzStorageBlob -Container sample-container -Context $ctx
91116
```
92117

93118
## Next steps

0 commit comments

Comments
 (0)