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/key-vault/general/tutorial-net-create-vault-azure-web-app.md
+10-19Lines changed: 10 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,16 +15,11 @@ ms.author: mbaldwin
15
15
16
16
---
17
17
18
-
# Tutorial: Use a managed identity to connect a key vault to an Azure Web App in .NET
19
-
20
-
This tutorial illustrates how to use a [managed identity](../../active-directory/managed-identities-azure-resources/overview.md) to authenticate an Azure Web App with an Azure Key Vault. You can use a managed identity to authenticate to any service that supports Azure AD authentication, including Key Vault, without any credentials in your code.
21
-
22
-
> [!NOTE]
23
-
>
24
-
> This tutorial uses the [Azure Key Vault v4 client library for .NET](/dotnet/api/overview/azure/key-vault?view=azure-dotnet) and the [Azure CLI](/cli/azure/get-started-with-azure-cli). However, the same basic principles apply when using the development language of your choice and/or Azure PowerShell.
18
+
# Tutorial: Use a managed identity to connect Key Vault to an Azure Web App with .NET
25
19
20
+
Azure Key Vault provides a way to securely store credentials and other secrets, but your code needs to authenticate to Key Vault to retrieve them. [Managed identities for Azure resources overview](../../active-directory/managed-identities-azure-resources/overview.md) helps to solve this problem by giving Azure services an automatically managed identity in Azure AD. You can use this identity to authenticate to any service that supports Azure AD authentication, including Key Vault, without having to display credentials in your code.
This tutorial uses a managed identity to authenticate an Azure Web App with an Azure Key Vault. Although the steps use the [Azure Key Vault v4 client library for .NET](/dotnet/api/overview/azure/key-vault?view=azure-dotnet) and the [Azure CLI](/cli/azure/get-started-with-azure-cli), the same basic principles apply when using the development language of your choice, Azure PowerShell, and/or the Azure portal.
28
23
29
24
## Prerequisites
30
25
@@ -34,13 +29,11 @@ To complete this quickstart:
34
29
* The [.NET Core 3.1 SDK or later](https://dotnet.microsoft.com/download/dotnet-core/3.1).
35
30
*[Azure CLI](/cli/azure/install-azure-cli?view=azure-cli-latest) or [Azure PowerShell](/powershell/azure/overview)
36
31
37
-
This quickstart assumes you are running `dotnet`, [Azure CLI](/cli/azure/install-azure-cli?view=azure-cli-latest), and Windows commands in a Windows terminal (such as [PowerShell Core](/powershell/scripting/install/installing-powershell-core-on-windows?view=powershell-6), [Windows PowerShell](/powershell/scripting/install/installing-windows-powershell?view=powershell-6), or the [Azure Cloud Shell](https://shell.azure.com/)).
32
+
This quickstart assumes you are running `dotnet` and the [Azure CLI](/cli/azure/install-azure-cli?view=azure-cli-latest) in a Windows terminal (such as [PowerShell Core](/powershell/scripting/install/installing-powershell-core-on-windows?view=powershell-6), [Windows PowerShell](/powershell/scripting/install/installing-windows-powershell?view=powershell-6), or the [Azure Cloud Shell](https://shell.azure.com/)).
38
33
39
34
## Create a resource group
40
35
41
-
A resource group is a logical container into which Azure resources are deployed and managed.
42
-
43
-
Your first step is to create a resource group to house both your key vault and your web app. You can do so with the [az group create](/cli/azure/group?view=azure-cli-latest#az-group-create) command:
36
+
A resource group is a logical container into which Azure resources are deployed and managed. Create a resource group to house both your key vault and your web app with the [az group create](/cli/azure/group?view=azure-cli-latest#az-group-create) command:
44
37
45
38
```azurecli
46
39
az group create --name "myResourceGroup" -l "EastUS"
@@ -53,18 +46,18 @@ You will now create a key vault and place a secret in it, for use later in this
53
46
To create a key vault, use the [az keyvault create](/cli/azure/keyvault?view=azure-cli-latest#az-keyvault-create) command:
54
47
55
48
> [!Important]
56
-
> Each key vault must have a unique name. Replace <your-unique-keyvault-name> with the name of your key vault in the following examples.
49
+
> Each key vault must have a unique name. Replace <your-keyvault-name> with the name of your key vault in the following examples.
57
50
58
51
```azurecli
59
-
az keyvault create --name "<your-unique-keyvault-name>" -g "myResourceGroup"
52
+
az keyvault create --name "<your-keyvault-name>" -g "myResourceGroup"
60
53
```
61
54
62
-
Make a note of the returned `vaultUri`, which will be in the format"https://<your-unique-keyvault-name>.vault.azure.net/". It will be used in the [Update the code](#update-the-code) step.
55
+
Make a note of the returned `vaultUri`, which will be in the format"https://<your-keyvault-name>.vault.azure.net/". It will be used in the [Update the code](#update-the-code) step.
63
56
64
57
You can now place a secret in your key vault with the [az keyvault secret set](/cli/azure/keyvault/secret?view=azure-cli-latest#az-keyvault-secret-set) command. Set the name of your secret to MySecret and the value to "Success!".
65
58
66
59
```azurecli
67
-
az keyvault secret set --vault-name "<your-unique-keyvault-name>" --name "MySecret" --value "Success!"
60
+
az keyvault secret set --vault-name "<your-keyvault-name>" --name "MySecret" --value "Success!"
68
61
```
69
62
70
63
## Create a .NET web app
@@ -244,8 +237,6 @@ You will see the "Hello World!" message you previously saw when visiting `http:/
244
237
245
238
## Create and assign a managed identity
246
239
247
-
Azure Key Vault provides a way to securely store credentials and other secrets, but your code needs to authenticate to Key Vault to retrieve them. [Managed identities for Azure resources overview](../../active-directory/managed-identities-azure-resources/overview.md) helps to solve this problem by giving Azure services an automatically managed identity in Azure AD. You can use this identity to authenticate to any service that supports Azure AD authentication, including Key Vault, without having to display credentials in your code.
248
-
249
240
In the Azure CLI, to create the identity for this application, run the [az webapp-identity assign](/cli/azure/webapp/identity?view=azure-cli-latest#az-webapp-identity-assign) command:
250
241
251
242
```azurecli
@@ -265,7 +256,7 @@ The operation will return this JSON snippet:
265
256
To give your web app permission to do **get** and **list** operations on your key vault, pass the principalID to the Azure CLI [az keyvault set-policy](/cli/azure/keyvault?view=azure-cli-latest#az-keyvault-set-policy) command:
266
257
267
258
```azurecli
268
-
az keyvault set-policy --name "<your-unique-keyvault-name>" --object-id "<principalId>" --secret-permissions get list
259
+
az keyvault set-policy --name "<your-keyvault-name>" --object-id "<principalId>" --secret-permissions get list
0 commit comments