Skip to content

Commit 408e103

Browse files
authored
Merge pull request #100123 from lisaguthrie/5514040-msifreshnesspass
MSI article updates for AAD
2 parents 6b85480 + b3eb3b3 commit 408e103

File tree

1 file changed

+93
-54
lines changed

1 file changed

+93
-54
lines changed

articles/azure-app-configuration/howto-integrate-azure-managed-service-identity.md

Lines changed: 93 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
---
22
title: Integrate with Azure managed identities
33
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+
77
ms.service: azure-app-configuration
88
ms.topic: conceptual
9-
ms.date: 02/24/2019
9+
ms.date: 12/29/2019
10+
ms.author: lcozzens
1011

1112
---
1213
# Integrate with Azure Managed Identities
1314

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

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

1819
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.
1920

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

2223
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.
2324

@@ -39,15 +40,15 @@ To complete this tutorial, you must have:
3940

4041
## Add a managed identity
4142

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

4445
1. Create an App Services instance in the [Azure portal](https://portal.azure.com) as you normally do. Go to it in the portal.
4546

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**.
4748

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**.
4950

50-
4. Answer **Yes** when prompted to enable system assigned managed identity.
51+
1. Answer **Yes** when prompted to enable system assigned managed identity.
5152

5253
![Set managed identity in App Service](./media/set-managed-identity-app-service.png)
5354

@@ -59,7 +60,7 @@ To set up a managed identity in the portal, you first create an application as n
5960

6061
1. On the **Check access** tab, select **Add** in the **Add role assignment** card UI.
6162

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**.
6364

6465
1. Under **Subscription**, select your Azure subscription. Select the App Service resource for your app.
6566

@@ -71,7 +72,13 @@ To set up a managed identity in the portal, you first create an application as n
7172

7273
## Use a managed identity
7374

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.
7582
7683
1. Open *appsettings.json*, and add the following script. Replace *\<service_endpoint>*, including the brackets, with the URL to your App Configuration store.
7784
@@ -81,52 +88,98 @@ To set up a managed identity in the portal, you first create an application as n
8188
}
8289
```
8390
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:
8592
86-
```csharp
87-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
88-
WebHost.CreateDefaultBuilder(args)
89-
.ConfigureAppConfiguration((hostingContext, config) =>
90-
{
91-
var settings = config.Build();
92-
config.AddAzureAppConfiguration(options =>
93-
options.ConnectWithManagedIdentity(settings["AppConfig:Endpoint"]));
94-
})
95-
.UseStartup<Startup>();
93+
```csharp-interactive
94+
using Azure.Identity;
95+
using Microsoft.Azure.Services.AppAuthentication;
9696
```
9797
98-
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)
99104
100105
```csharp
101106
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
102107
WebHost.CreateDefaultBuilder(args)
103108
.ConfigureAppConfiguration((hostingContext, config) =>
104109
{
105110
var settings = config.Build();
106-
AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();
107-
KeyVaultClient kvClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
108-
109-
config.AddAzureAppConfiguration(options => options.ConnectWithManagedIdentity(settings["AppConfig:Endpoint"])).UseAzureKeyVault(kvClient));
111+
config.AddAzureAppConfiguration(options =>
112+
options.Connect(new Uri(settings["AppConfig:Endpoint"]), new ManagedIdentityCredential()));
110113
})
111114
.UseStartup<Startup>();
112115
```
113116
117+
### [.NET Core 3.x](#tab/core3x)
118+
119+
```csharp
120+
public static IHostBuilder CreateHostBuilder(string[] args) =>
121+
Host.CreateDefaultBuilder(args)
122+
.ConfigureWebHostDefaults(webBuilder =>
123+
webBuilder.ConfigureAppConfiguration((hostingContext, config) =>
124+
{
125+
var settings = config.Build();
126+
config.AddAzureAppConfiguration(options =>
127+
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) =>
139+
WebHost.CreateDefaultBuilder(args)
140+
.ConfigureAppConfiguration((hostingContext, config) =>
141+
{
142+
var settings = config.Build();
143+
AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();
144+
KeyVaultClient kvClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
145+
146+
config.AddAzureAppConfiguration(options => options.Connect(new Uri(settings["AppConfig:Endpoint"]), new ManagedIdentityCredential()).UseAzureKeyVault(kvClient));
147+
})
148+
.UseStartup<Startup>();
149+
```
150+
151+
### [.NET Core 3.x](#tab/core3x)
152+
153+
```csharp
154+
public static IHostBuilder CreateHostBuilder(string[] args) =>
155+
Host.CreateDefaultBuilder(args)
156+
.ConfigureWebHostDefaults(webBuilder =>
157+
webBuilder.ConfigureAppConfiguration((hostingContext, config) =>
158+
{
159+
var settings = config.Build();
160+
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+
114169
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.
115170
116171
[!INCLUDE [Prepare repository](../../includes/app-service-deploy-prepare-repo.md)]
117172
118-
[!INCLUDE [cloud-shell-try-it](../../includes/cloud-shell-try-it.md)]
119-
120173
## Deploy from local Git
121174
122-
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).
123176
124177
### Configure a deployment user
125178
126179
[!INCLUDE [Configure a deployment user](../../includes/configure-deployment-user-no-h.md)]
127180
128181
### 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:
130183
131184
```cmd
132185
git init
@@ -140,33 +193,17 @@ To enable local Git deployment for your app with the Kudu build server, run [`az
140193
az webapp deployment source config-local-git --name <app_name> --resource-group <group_name>
141194
```
142195

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

151198
```json
152-
Local git is configured with url of 'https://<username>@<app_name>.scm.azurewebsites.net/<app_name>.git'
153199
{
154-
"availabilityState": "Normal",
155-
"clientAffinityEnabled": true,
156-
"clientCertEnabled": false,
157-
"cloningInfo": null,
158-
"containerSize": 0,
159-
"dailyMemoryTimeQuota": 0,
160-
"defaultHostName": "<app_name>.azurewebsites.net",
161-
"deploymentLocalGitUrl": "https://<username>@<app_name>.scm.azurewebsites.net/<app_name>.git",
162-
"enabled": true,
163-
< JSON data removed for brevity. >
200+
"url": "https://<username>@<app_name>.scm.azurewebsites.net/<app_name>.git"
164201
}
165202
```
166203

167204
### Deploy your project
168205

169-
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).
170207

171208
```bash
172209
git remote add azure <url>
@@ -192,7 +229,9 @@ http://<app_name>.azurewebsites.net
192229

193230
## Use managed identity in other languages
194231

195-
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:
196235

197236
```xml
198237
<configSections>
@@ -220,4 +259,4 @@ App Configuration providers for .NET Framework and Java Spring also have built-i
220259
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.
221260

222261
> [!div class="nextstepaction"]
223-
> [CLI samples](./cli-samples.md)
262+
> [CLI samples](./cli-samples.md)

0 commit comments

Comments
 (0)