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/azure-app-configuration/howto-integrate-azure-managed-service-identity.md
+93-54Lines changed: 93 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,23 +1,24 @@
1
1
---
2
2
title: Integrate with Azure managed identities
3
3
description: Learn how to use Azure managed identities to authenticate with and gain access to Azure App Configuration
4
-
services: azure-app-configuration
5
-
author: yegu-ms
6
-
ms.author: yegu
4
+
ms.service: azure-app-configuration
5
+
author: lisaguthrie
6
+
7
7
ms.service: azure-app-configuration
8
8
ms.topic: conceptual
9
-
ms.date: 02/24/2019
9
+
ms.date: 12/29/2019
10
+
ms.author: lcozzens
10
11
11
12
---
12
13
# Integrate with Azure Managed Identities
13
14
14
-
Azure Active Directory [managed identities](https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/overview) help simplify secrets management for your cloud application. With a managed identity, you can set up your code to use the service principal that was created for the Azure service it runs on. You use a managed identity instead of a separate credential stored in Azure Key Vault or a local connection string.
15
+
Azure Active Directory [managed identities](https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/overview) help simplify secrets management for your cloud application. With a managed identity, your code can use the service principal that was created for the Azure service it runs on. You use a managed identity instead of a separate credential stored in Azure Key Vault or a local connection string.
15
16
16
-
Azure App Configuration and its .NET Core, .NET Framework, and Java Spring client libraries come with the managed identity support built into them. Although you aren't required to use it, the managed identity eliminates the need for an access token that contains secrets. Your code can access the App Configuration store using only the service endpoint. You can embed this URL in your code directly without the concern of exposing any secret.
17
+
Azure App Configuration and its .NET Core, .NET Framework, and Java Spring client libraries have managed identity support built into them. Although you aren't required to use it, the managed identity eliminates the need for an access token that contains secrets. Your code can access the App Configuration store using only the service endpoint. You can embed this URL in your code directly without the concern of exposing any secret.
17
18
18
19
This tutorial shows how you can take advantage of the managed identity to access App Configuration. It builds on the web app introduced in the quickstarts. Before you continue, finish [Create an ASP.NET Core app with App Configuration](./quickstart-aspnet-core-app.md) first.
19
20
20
-
In addition, this tutorial optionally shows how you can use the managed identity in conjunction with App Configuration's Key Vault references. This allows you to seamlessly access secrets stored in Key Vault as well as configuration values in App Configuration. If you wish to explore this capability, finish [Use Key Vault References with ASP.NET Core](./use-key-vault-references-dotnet-core.md) first.
21
+
This tutorial also shows how you can use the managed identity in conjunction with App Configuration's Key Vault references. With a single managed identity, you can seamlessly access both secrets from Key Vault and configuration values from App Configuration. If you wish to explore this capability, finish [Use Key Vault References with ASP.NET Core](./use-key-vault-references-dotnet-core.md) first.
21
22
22
23
You can use any code editor to do the steps in this tutorial. [Visual Studio Code](https://code.visualstudio.com/) is an excellent option available on the Windows, macOS, and Linux platforms.
23
24
@@ -39,15 +40,15 @@ To complete this tutorial, you must have:
39
40
40
41
## Add a managed identity
41
42
42
-
To set up a managed identity in the portal, you first create an application as normal and then enable the feature.
43
+
To set up a managed identity in the portal, you first create an application and then enable the feature.
43
44
44
45
1. Create an App Services instance in the [Azure portal](https://portal.azure.com) as you normally do. Go to it in the portal.
45
46
46
-
2. Scroll down to the **Settings** group in the left pane, and select **Identity**.
47
+
1. Scroll down to the **Settings** group in the left pane, and select **Identity**.
47
48
48
-
3. On the **System assigned** tab, switch **Status** to **On** and select **Save**.
49
+
1. On the **System assigned** tab, switch **Status** to **On** and select **Save**.
49
50
50
-
4. Answer **Yes** when prompted to enable system assigned managed identity.
51
+
1. Answer **Yes** when prompted to enable system assigned managed identity.
51
52
52
53

53
54
@@ -59,7 +60,7 @@ To set up a managed identity in the portal, you first create an application as n
59
60
60
61
1. On the **Check access** tab, select **Add** in the **Add role assignment** card UI.
61
62
62
-
1. Under **Role**, select **Contributor**. Under **Assign access to**, select **App Service** under **System assigned managed identity**.
63
+
1. Under **Role**, select **App Configuration Data Reader**. Under **Assign access to**, select **App Service** under **System assigned managed identity**.
63
64
64
65
1. Under **Subscription**, select your Azure subscription. Select the App Service resource for your app.
65
66
@@ -71,7 +72,13 @@ To set up a managed identity in the portal, you first create an application as n
71
72
72
73
## Use a managed identity
73
74
74
-
1. Find the URL to your App Configuration store by going into its configuration screen in the Azure portal, then clicking on the **Access Keys** tab.
75
+
1. Add a reference to the *Azure.Identity* package:
76
+
77
+
```cli
78
+
dotnet add package Azure.Identity --version 1.1.0
79
+
```
80
+
81
+
1. Find the endpoint to your App Configuration store. This URL is listed on the **Access keys** tab for the store in the Azure portal.
75
82
76
83
1. Open *appsettings.json*, and add the following script. Replace *\<service_endpoint>*, including the brackets, with the URL to your App Configuration store.
77
84
@@ -81,52 +88,98 @@ To set up a managed identity in the portal, you first create an application as n
81
88
}
82
89
```
83
90
84
-
1. If you wish to access only values stored directly in App Configuration, open *Program.cs*, and update the `CreateWebHostBuilder` method by replacing the `config.AddAzureAppConfiguration()` method.
91
+
1. Open *Program.cs*, and add a reference to the `Azure.Identity` and `Microsoft.Azure.Services.AppAuthentication` namespaces:
85
92
86
-
```csharp
87
-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
1. If you wish to use App Configuration values as well as Key Vault references, open *Program.cs*, and update the `CreateWebHostBuilder` method as shown below. This creates a new `KeyVaultClient` using an `AzureServiceTokenProvider` and passes this reference to a call to the `UseAzureKeyVault` method.
98
+
1. If you wish to access only values stored directly in App Configuration, update the `CreateWebHostBuilder` method by replacing the `config.AddAzureAppConfiguration()` method.
99
+
100
+
> [!IMPORTANT]
101
+
> `CreateHostBuilder` replaces `CreateWebHostBuilder` in .NET Core 3.0. Select the correct syntax based on your environment.
102
+
103
+
### [.NET Core 2.x](#tab/core2x)
99
104
100
105
```csharp
101
106
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
options.Connect(new Uri(settings["AppConfig:Endpoint"]), new ManagedIdentityCredential()));
128
+
})
129
+
.UseStartup<Startup>());
130
+
```
131
+
---
132
+
133
+
1. To use both App Configuration values and Key Vault references, update *Program.cs* as shown below. This code creates a new `KeyVaultClient` using an `AzureServiceTokenProvider` and passes this reference to a call to the `UseAzureKeyVault` method.
134
+
135
+
### [.NET Core 2.x](#tab/core2x)
136
+
137
+
```csharp
138
+
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();
161
+
KeyVaultClient kvClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
162
+
163
+
config.AddAzureAppConfiguration(options => options.Connect(new Uri(settings["AppConfig:Endpoint"]), new ManagedIdentityCredential()).UseAzureKeyVault(kvClient));
164
+
})
165
+
.UseStartup<Startup>());
166
+
```
167
+
---
168
+
114
169
You can now access Key Vault references just like any other App Configuration key. The config provider will use the `KeyVaultClient` that you configured to authenticate to Key Vault and retrieve the value.
The easiest way to enable local Git deployment for your app with the Kudu build server is to use Azure Cloud Shell.
175
+
The easiest way to enable local Git deployment for your app with the Kudu build server is to use [Azure Cloud Shell](https://shell.azure.com).
123
176
124
177
### Configure a deployment user
125
178
126
179
[!INCLUDE [Configure a deployment user](../../includes/configure-deployment-user-no-h.md)]
127
180
128
181
### Enable local Git with Kudu
129
-
If you don't have a local git repository for your app, you'll need to initialize one. To do this, run the following commands from your app's project directory:
182
+
If you don't have a local git repository for your app, you'll need to initialize one. To initialize a local git repository, run the following commands from your app's project directory:
130
183
131
184
```cmd
132
185
git init
@@ -140,33 +193,17 @@ To enable local Git deployment for your app with the Kudu build server, run [`az
140
193
az webapp deployment source config-local-git --name <app_name> --resource-group <group_name>
141
194
```
142
195
143
-
To create a Git-enabled app instead, run [`az webapp create`](/cli/azure/webapp?view=azure-cli-latest#az-webapp-create) in Cloud Shell with the `--deployment-local-git` parameter.
144
-
145
-
```azurecli-interactive
146
-
az webapp create --name <app_name> --resource-group <group_name> --plan <plan_name> --deployment-local-git
147
-
```
148
-
149
-
The `az webapp create` command gives you something similar to the following output:
196
+
This command gives you something similar to the following output:
150
197
151
198
```json
152
-
Local git is configured with url of 'https://<username>@<app_name>.scm.azurewebsites.net/<app_name>.git'
Back in the _local terminal window_, add an Azure remote to your local Git repository. Replace _\<url>_ with the URL of the Git remote that you got from [Enable Git for your app](#enable-local-git-with-kudu).
206
+
In the _local terminal window_, add an Azure remote to your local Git repository. Replace _\<url>_ with the URL of the Git remote that you got from [Enable local Git with Kudu](#enable-local-git-with-kudu).
App Configuration providers for .NET Framework and Java Spring also have built-in support for managed identity. In these cases, use your App Configuration store's URL endpoint instead of its full connection string when you configure a provider. For example, for the .NET Framework console app created in the quickstart, specify the following settings in the *App.config* file:
232
+
App Configuration providers for .NET Framework and Java Spring also have built-in support for managed identity. You can use your store's URL endpoint instead of its full connection string when you configure one of these providers.
233
+
234
+
For example, you can update the .NET Framework console app created in the quickstart to specify the following settings in the *App.config* file:
196
235
197
236
```xml
198
237
<configSections>
@@ -220,4 +259,4 @@ App Configuration providers for .NET Framework and Java Spring also have built-i
220
259
In this tutorial, you added an Azure managed identity to streamline access to App Configuration and improve credential management for your app. To learn more about how to use App Configuration, continue to the Azure CLI samples.
0 commit comments