Skip to content

Commit 3647166

Browse files
authored
Merge pull request #91783 from tamram/tamram-1014
update MSI doc for v12 .NET client lib
2 parents 76c5e38 + 4cb89f9 commit 3647166

File tree

2 files changed

+80
-121
lines changed

2 files changed

+80
-121
lines changed

articles/storage/blobs/storage-blob-user-delegation-sas-create-dotnet.md

Lines changed: 20 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: tamram
66

77
ms.service: storage
88
ms.topic: conceptual
9-
ms.date: 08/12/2019
9+
ms.date: 10/17/2019
1010
ms.author: tamram
1111
ms.reviewer: cbrooks
1212
ms.subservice: blobs
@@ -16,71 +16,40 @@ ms.subservice: blobs
1616

1717
[!INCLUDE [storage-auth-sas-intro-include](../../../includes/storage-auth-sas-intro-include.md)]
1818

19-
This article shows how to use Azure Active Directory (Azure AD) credentials to create a user delegation SAS for a container or blob with the [Azure Storage client library for .NET](https://www.nuget.org/packages/Azure.Storage.Blobs).
19+
This article shows how to use Azure Active Directory (Azure AD) credentials to create a user delegation SAS for a container or blob with the Azure Storage client library for .NET.
2020

2121
[!INCLUDE [storage-auth-user-delegation-include](../../../includes/storage-auth-user-delegation-include.md)]
2222

23-
## Install the preview packages
23+
## Authenticate with the Azure Identity library (preview)
2424

25-
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:
25+
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.
2626

27-
```
28-
Install-Package Azure.Storage.Blobs -IncludePrerelease
29-
```
27+
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).
3028

31-
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. The Azure Identity client library authenticates a security principal. The authenticated security principal can then create the user delegation SAS. 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).
29+
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).
3230

33-
```
34-
Install-Package Azure.Identity -IncludePrerelease
35-
```
31+
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 your seamlessly by getting the appropriate token credential.
3632

37-
## Create a service principal
33+
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).
3834

39-
To authenticate with Azure AD credentials via the Azure Identity client library, use either a service principal or a managed identity as the security principal, depending on where your code is running. If your code is running in a development environment, use a service principal for testing purposes. If your code is running in Azure, use a managed identity. This article assumes that you are running code from the development environment, and shows how to use a service principal to create the user delegation SAS.
35+
## Assign RBAC roles for access to data
4036

41-
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. The role must include the **Microsoft.Storage/storageAccounts/blobServices/generateUserDelegationKey** action. 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).
37+
When an Azure AD security principal attempts to access blob 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 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).
4238

43-
Additionally, provide the scope for the role assignment. The service principal will create the user delegation key, which is an operation performed at the level of the storage account, so the role assignment should be scoped at the level of the storage account, resource group, or subscription. For more information about RBAC permissions for creating a user delegation SAS, see the **Assign permissions with RBAC** section in [Create a user delegation SAS (REST API)](/rest/api/storageservices/create-user-delegation-sas).
44-
45-
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.
39+
## Install the preview packages
4640

47-
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
41+
The examples in this article use the latest preview version of the [Azure Storage client library for Blob storage](https://www.nuget.org/packages/Azure.Storage.Blobs). To install the preview package, run the following command from the NuGet package manager console:
4842

49-
```azurecli-interactive
50-
az ad sp create-for-rbac \
51-
--name <service-principal> \
52-
--role "Storage Blob Data Reader" \
53-
--scopes /subscriptions/<subscription>/resourceGroups/<resource-group>/providers/Microsoft.Storage/storageAccounts/<storage-account>
43+
```powershell
44+
Install-Package Azure.Storage.Blobs -IncludePrerelease
5445
```
5546

56-
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.
47+
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:
5748

58-
```json
59-
{
60-
"appId": "generated-app-ID",
61-
"displayName": "service-principal-name",
62-
"name": "http://service-principal-uri",
63-
"password": "generated-password",
64-
"tenant": "tenant-ID"
65-
}
49+
```powershell
50+
Install-Package Azure.Identity -IncludePrerelease
6651
```
6752

68-
> [!IMPORTANT]
69-
> RBAC role assignments may take a few minutes to propagate.
70-
71-
## Set environment variables
72-
73-
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.
74-
75-
|Environment variable|Value
76-
|-|-
77-
|`AZURE_CLIENT_ID`|The app ID for the service principal
78-
|`AZURE_TENANT_ID`|The service principal's Azure AD tenant ID
79-
|`AZURE_CLIENT_SECRET`|The password generated for the service principal
80-
81-
> [!IMPORTANT]
82-
> 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.
83-
8453
## Add using directives
8554

8655
Add the following `using` directives to your code to use the preview versions of the Azure Identity and Azure Storage client libraries.
@@ -96,11 +65,11 @@ using Azure.Storage.Blobs;
9665
using Azure.Storage.Blobs.Models;
9766
```
9867

99-
## Authenticate the service principal
68+
## Get an authenticated token credential
10069

101-
To authenticate the service principal, create an instance the [DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential) class. The `DefaultAzureCredential` constructor reads the environment variables that you created previously.
70+
To get a token credential that your code can use to authorize requests to Azure Storage, create an instance of the [DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential) class.
10271

103-
The following code snippet shows how to get the authenticated credential and use it to create a service client for Blob storage
72+
The following code snippet shows how to get the authenticated token credential and use it to create a service client for Blob storage:
10473

10574
```csharp
10675
string blobEndpoint = string.Format("https://{0}.blob.core.windows.net", accountName);

0 commit comments

Comments
 (0)