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-msi.md
+66-13Lines changed: 66 additions & 13 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: conceptual
9
-
ms.date: 10/17/2019
9
+
ms.date: 11/25/2019
10
10
ms.author: tamram
11
11
ms.reviewer: cbrooks
12
12
ms.subservice: common
@@ -30,39 +30,92 @@ Before you can use managed identities for Azure Resources to authorize access to
30
30
31
31
For more information about managed identities, see [Managed identities for Azure resources](../../active-directory/managed-identities-azure-resources/overview.md).
32
32
33
-
## Authenticate with the Azure Identity library (preview)
33
+
## Authenticate with the Azure Identity library
34
34
35
-
The Azure Identity client library for .NET (preview) authenticates a security principal. When your code is running in Azure, the security principal is a managed identity for Azure resources.
35
+
An advantage of the Azure Identity client library is that it enables you to use the same code to authenticate whether your application is running in the development environment or in Azure. In code running in the Azure environment, the client library authenticates a managed identity for Azure resources. In the development environment, the managed identity does not exist, so the client library authenticates either the user or a service principal for testing purposes.
36
36
37
-
When your code is running in the development environment, authentication may be handled automatically, or it may require a browser login, depending on which tools you're using. Microsoft Visual Studio supports single sign-on (SSO), so that the active Azure AD user account is automatically used for authentication. For more information about SSO, see [Single sign-on to applications](../../active-directory/manage-apps/what-is-single-sign-on.md).
38
-
39
-
Other development tools may prompt you to login via a web browser. You can also use a service principal to authenticate from the development environment. For more information, see [Create identity for Azure app in portal](../../active-directory/develop/howto-create-service-principal-portal.md).
37
+
The Azure Identity client library for .NET authenticates a security principal. When your code is running in Azure, the security principal is a managed identity for Azure resources.
40
38
41
39
After authenticating, the Azure Identity client library gets a token credential. This token credential is then encapsulated in the service client object that you create to perform operations against Azure Storage. The library handles this for you seamlessly by getting the appropriate token credential.
42
40
43
41
For more information about the Azure Identity client library, see [Azure Identity client library for .NET](https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/identity/Azure.Identity).
44
42
45
-
## Assign RBAC roles for access to data
43
+
###Assign role-based access control (RBAC) roles for access to data
46
44
47
45
When an Azure AD security principal attempts to access blob or queue data, that security principal must have permissions to the resource. Whether the security principal is a managed identity in Azure or an Azure AD user account running code in the development environment, the security principal must be assigned an RBAC role that grants access to blob or queue data in Azure Storage. For information about assigning permissions via RBAC, see the section titled **Assign RBAC roles for access rights** in [Authorize access to Azure blobs and queues using Azure Active Directory](../common/storage-auth-aad.md#assign-rbac-roles-for-access-rights).
48
46
49
-
## Install the preview packages
47
+
### Authenticate the user in the development environment
48
+
49
+
When your code is running in the development environment, authentication may be handled automatically, or it may require a browser login, depending on which tools you're using. Microsoft Visual Studio supports single sign-on (SSO), so that the active Azure AD user account is automatically used for authentication. For more information about SSO, see [Single sign-on to applications](../../active-directory/manage-apps/what-is-single-sign-on.md).
50
+
51
+
Other development tools may prompt you to login via a web browser.
52
+
53
+
### Authenticate a service principal in the development environment
54
+
55
+
If your development environment does not support single sign-on or login via a web browser, then you can use a service principal to authenticate from the development environment.
56
+
57
+
#### Create the service principal
58
+
59
+
To create a service principal with Azure CLI and assign an RBAC role, call the [az ad sp create-for-rbac](/cli/azure/ad/sp#az-ad-sp-create-for-rbac) command. Provide an Azure Storage data access role to assign to the new service principal. Additionally, provide the scope for the role assignment. For more information about the built-in roles provided for Azure Storage, see [Built-in roles for Azure resources](../../role-based-access-control/built-in-roles.md).
60
+
61
+
If you do not have sufficient permissions to assign a role to the service principal, you may need to ask the account owner or administrator to perform the role assignment.
62
+
63
+
The following example uses the Azure CLI to create a new service principal and assign the **Storage Blob Data Reader** role to it with account scope
The `az ad sp create-for-rbac` command returns a list of service principal properties in JSON format. Copy these values so that you can use them to create the necessary environment variables in the next step.
73
+
74
+
```json
75
+
{
76
+
"appId": "generated-app-ID",
77
+
"displayName": "service-principal-name",
78
+
"name": "http://service-principal-uri",
79
+
"password": "generated-password",
80
+
"tenant": "tenant-ID"
81
+
}
82
+
```
83
+
84
+
> [!IMPORTANT]
85
+
> RBAC role assignments may take a few minutes to propagate.
86
+
87
+
#### Set environment variables
88
+
89
+
The Azure Identity client library reads values from three environment variables at runtime to authenticate the service principal. The following table describes the value to set for each environment variable.
90
+
91
+
|Environment variable|Value
92
+
|-|-
93
+
|`AZURE_CLIENT_ID`|The app ID for the service principal
94
+
|`AZURE_TENANT_ID`|The service principal's Azure AD tenant ID
95
+
|`AZURE_CLIENT_SECRET`|The password generated for the service principal
96
+
97
+
> [!IMPORTANT]
98
+
> After you set the environment variables, close and re-open your console window. If you are using Visual Studio or another development environment, you may need to restart the development environment in order for it to register the new environment variables.
99
+
100
+
For more information, see [Create identity for Azure app in portal](../../active-directory/develop/howto-create-service-principal-portal.md).
101
+
102
+
## Install client library packages
50
103
51
-
The examples in this article use the latest preview version of the Azure Storage client library for Blob storage. To install the preview package, run the following command from the NuGet package manager console:
104
+
The examples in this article use the latest version of the Azure Storage client library for Blob storage. To install the package, run the following command from the NuGet package manager console:
The examples in this article also use the latest preview version of the [Azure Identity client library for .NET](https://www.nuget.org/packages/Azure.Identity/) to authenticate with Azure AD credentials. To install the preview package, run the following command from the NuGet package manager console:
110
+
The examples in this article also use the latest version of the [Azure Identity client library for .NET](https://www.nuget.org/packages/Azure.Identity/) to authenticate with Azure AD credentials. To install the package, run the following command from the NuGet package manager console:
58
111
59
112
```powershell
60
-
Install-Package Azure.Identity -IncludePrerelease
113
+
Install-Package Azure.Identity
61
114
```
62
115
63
116
## .NET code example: Create a block blob
64
117
65
-
Add the following `using` directives to your code to use the preview versions of the Azure Identity and Azure Storage client libraries.
118
+
Add the following `using` directives to your code to use the Azure Identity and Azure Storage client libraries.
0 commit comments