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/tutorial-net-windows-virtual-machine.md
+40-23Lines changed: 40 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,32 +49,34 @@ When you enable MSI for an Azure service, such as Azure Virtual Machines, Azure
49
49
50
50
Next, to get an access token, your code calls a local metadata service that's available on the Azure resource. To authenticate to an Azure Key Vault service, your code uses the access token that it gets from the local MSI endpoint.
51
51
52
-
## Log in to Azure
52
+
## Create resources and assign permissions
53
53
54
-
To log in to Azure by using the Azure CLI, enter:
54
+
Before you start coding you need to create some resources, put a secret into your key vault, and assign permissions.
55
+
56
+
### Sign in to Azure
57
+
58
+
To sign in to Azure by using the Azure CLI, enter:
55
59
56
60
```azurecli
57
61
az login
58
62
```
59
63
60
-
## Create a resource group
61
-
62
-
An Azure resource group is a logical container into which Azure resources are deployed and managed.
64
+
### Create a resource group
63
65
64
-
Create a resource group by using the [az group create](/cli/azure/group#az-group-create) command.
66
+
An Azure resource group is a logical container into which Azure resources are deployed and managed. Create a resource group by using the [az group create](/cli/azure/group#az-group-create) command.
65
67
66
-
Then, select a resource group name and fill in the placeholder. The following example creates a resource group in the West US location:
68
+
This example creates a resource group in the West US location:
67
69
68
70
```azurecli
69
71
# To list locations: az account list-locations --output table
70
72
az group create --name "<YourResourceGroupName>" --location "West US"
71
73
```
72
74
73
-
You use your newly created resource group throughout this tutorial.
75
+
Your newly created resource group will be used throughout this tutorial.
74
76
75
-
## Create a key vault
77
+
###Create a key vault and populate it with a secret
76
78
77
-
To create a key vault in the resource group that you created in the preceding step, provide the following information:
79
+
Create a key vault in your resource group by providing the [az keyvault create](/cli/azure/keyvault?view=azure-cli-latest#az-keyvault-create) command with the following information:
78
80
79
81
* Key vault name: a string of 3 to 24 characters that can contain only numbers (0-9), letters (a-z, A-Z), and hyphens (-)
At this point, your Azure account is the only one that's authorized to perform operations on this new key vault.
87
89
88
-
## Add a secret to the key vault
90
+
Now add a secret to your key vault using the [az keyvault secret set](/cli/azure/keyvault/secret?view=azure-cli-latest#az-keyvault-secret-set) command
89
91
90
-
We're adding a secret to help illustrate how this works. The secret might be a SQL connection string or any other information that you need to keep both secure and available to your application.
91
92
92
93
To create a secret in the key vault called **AppSecret**, enter the following command:
93
94
@@ -97,15 +98,15 @@ az keyvault secret set --vault-name "<YourKeyVaultName>" --name "AppSecret" --va
97
98
98
99
This secret stores the value **MySecret**.
99
100
100
-
## Create a virtual machine
101
-
You can create a virtual machine by using one of the following methods:
101
+
###Create a virtual machine
102
+
Create a virtual machine by using one of the following methods:
In this step, you create a system-assigned identity for the virtual machine by running the following command in the Azure CLI:
108
+
###Assign an identity to the VM
109
+
Create a system-assigned identity for the virtual machine with the [az vm identity assign](/cli/azure/vm/identity?view=azure-cli-latest#az-vm-identity-assign) command:
109
110
110
111
```azurecli
111
112
az vm identity assign --name <NameOfYourVirtualMachine> --resource-group <YourResourceGroupName>
@@ -120,33 +121,49 @@ Note the system-assigned identity that's displayed in the following code. The ou
120
121
}
121
122
```
122
123
123
-
## Assign permissions to the VM identity
124
-
Now you can assign the previously created identity permissions to your key vault by running the following command:
124
+
###Assign permissions to the VM identity
125
+
Assign the previously created identity permissions to your key vault with the [az keyvault set-policy](/cli/azure/keyvault?view=azure-cli-latest#az-keyvault-set-policy) command:
125
126
126
127
```azurecli
127
128
az keyvault set-policy --name '<YourKeyVaultName>' --object-id <VMSystemAssignedIdentity> --secret-permissions get list
128
129
```
129
130
130
-
## Log on to the virtual machine
131
+
### Sign in to the virtual machine
132
+
133
+
To sign in to the virtual machine, follow the instructions in [Connect and sign in to an Azure virtual machine running Windows](https://docs.microsoft.com/azure/virtual-machines/windows/connect-logon).
134
+
135
+
## Set up the console app
131
136
132
-
To log on to the virtual machine, follow the instructions in [Connect and log on to an Azure virtual machine running Windows](https://docs.microsoft.com/azure/virtual-machines/windows/connect-logon).
137
+
Create a console app and install the required packages using the `dotnet` command.
133
138
134
-
## Install .NET Core
139
+
###Install .NET Core
135
140
136
141
To install .NET Core, go to the [.NET downloads](https://www.microsoft.com/net/download) page.
137
142
138
-
## Create and run a sample .NET app
143
+
###Create and run a sample .NET app
139
144
140
145
Open a command prompt.
141
146
142
147
You can print "Hello World" to the console by running the following commands:
143
148
144
-
```batch
149
+
```console
145
150
dotnet new console -o helloworldapp
146
151
cd helloworldapp
147
152
dotnet run
148
153
```
149
154
155
+
### Install the packages
156
+
157
+
From the console window, install the .NET packages required for this quickstart:
158
+
159
+
```console
160
+
dotnet add package System.IO;
161
+
dotnet add package System.Net;
162
+
dotnet add package System.Text;
163
+
dotnet add package Newtonsoft.Json;
164
+
dotnet add package Newtonsoft.Json.Linq;
165
+
```
166
+
150
167
## Edit the console app
151
168
152
169
Open the *Program.cs* file and add these packages:
0 commit comments