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
+35-18Lines changed: 35 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,32 +49,36 @@ 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
+
## Set up the project
53
+
54
+
Before you start coding you need to create some resources, put a secret into your key vault, and set up the .NET project.
55
+
56
+
### Log in to Azure
53
57
54
58
To log 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
64
+
###Create resources and assign permissions
61
65
62
-
An Azure resource group is a logical container into which Azure resources are deployed and managed.
66
+
#### Create a resource group
63
67
64
-
Create a resource group by using the [az group create](/cli/azure/group#az-group-create) command.
68
+
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
69
66
-
Then, select a resource group name and fill in the placeholder. The following example creates a resource group in the West US location:
70
+
This example creates a resource group in the West US location:
67
71
68
72
```azurecli
69
73
# To list locations: az account list-locations --output table
70
74
az group create --name "<YourResourceGroupName>" --location "West US"
71
75
```
72
76
73
-
You use your newly created resource group throughout this tutorial.
77
+
Your newly created resource group will be used throughout this tutorial.
74
78
75
-
## Create a key vault
79
+
####Create a key vault and populate it with a secret
76
80
77
-
To create a key vault in the resource group that you created in the preceding step, provide the following information:
81
+
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
82
79
83
* 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
91
88
-
## Add a secret to the key vault
92
+
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
93
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
94
92
95
To create a secret in the key vault called **AppSecret**, enter the following command:
93
96
@@ -97,15 +100,15 @@ az keyvault secret set --vault-name "<YourKeyVaultName>" --name "AppSecret" --va
97
100
98
101
This secret stores the value **MySecret**.
99
102
100
-
## Create a virtual machine
101
-
You can create a virtual machine by using one of the following methods:
103
+
####Create a virtual machine
104
+
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:
110
+
####Assign an identity to the VM
111
+
Create a system-assigned identity for the virtual machine bwith the [az vm identity assign]/cli/azure/vm/identity?view=azure-cli-latest#az-vm-identity-assign) command:
109
112
110
113
```azurecli
111
114
az vm identity assign --name <NameOfYourVirtualMachine> --resource-group <YourResourceGroupName>
@@ -120,17 +123,19 @@ Note the system-assigned identity that's displayed in the following code. The ou
120
123
}
121
124
```
122
125
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:
126
+
####Assign permissions to the VM identity
127
+
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
128
126
129
```azurecli
127
130
az keyvault set-policy --name '<YourKeyVaultName>' --object-id <VMSystemAssignedIdentity> --secret-permissions get list
128
131
```
129
132
130
-
## Log on to the virtual machine
133
+
####Log on to the virtual machine
131
134
132
135
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).
133
136
137
+
## Set up the console app
138
+
134
139
## Install .NET Core
135
140
136
141
To install .NET Core, go to the [.NET downloads](https://www.microsoft.com/net/download) page.
@@ -141,12 +146,24 @@ 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