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-rotation.md
+44-28Lines changed: 44 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,19 @@
1
-
---
1
+
---
2
2
title: Single User/Password Rotation Tutorial
3
-
description: Use this how-to guide to help you set up key rotation and monitor key vault logs.
3
+
description: Use this tutorial for automating rotation of single user/password
4
4
services: key-vault
5
5
author: msmbaldwin
6
6
manager: rkarlin
7
-
tags: ''
7
+
tags: 'rotation'
8
8
9
9
ms.service: key-vault
10
-
ms.topic: conceptual
10
+
ms.subservice: general
11
+
ms.topic: tutorial
11
12
ms.date: 01/26/2020
12
13
ms.author: mbaldwin
13
14
14
15
---
15
-
# Automate the rotation of a single user/password secret
16
+
# Automate the rotation of a secret for resources with single user/password authentication
16
17
17
18
Although the best way to authenticate to Azure services is by using an [managed identity](managed-identity.md), there are some scenarios where this is not an option. In these cases, access keys or secrets are used. Access keys or secrets should be periodically rotated.
18
19
@@ -25,7 +26,9 @@ This tutorial demonstrates how to automate the periodic rotation of secrets for
25
26
1. The function App receives secret information, generates new random password, and create a new version for the secret with a new password in Key Vault.
26
27
1. The function App updates SQL with new password.
27
28
28
-
Note: There could be a lag between step 3 and 4 and during that time secret in Key Vault would not be valid to authenticate to SQL. In case of failure in any of the steps Event Grid retries for 2 hours.
29
+
> [!NOTE]
30
+
> There could be a lag between step 3 and 4 and during that time secret in Key Vault would not be valid to authenticate to SQL.
31
+
> In case of failure in any of the steps Event Grid retries for 2 hours.
29
32
30
33
## Setup
31
34
@@ -35,7 +38,8 @@ Before we begin, we must create a Key Vault, create a SQL Server and database, a
35
38
36
39
This tutorial uses a pre-created Azure Resource Manager template to create components. You can find entire code here: [Basic Secret Rotation Template Sample](https://github.com/jlichwa/azure-keyvault-basicrotation-tutorial/tree/master/arm-templates).
37
40
38
-
1. Use the Azure Resource Manager template to create components by selecting this link: [Deploy](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fjlichwa%2Fazure-keyvault-basicrotation-tutorial%2Fmaster%2Farm-templates%2Finitial-setup%2Fazuredeploy.json)
You must now create a Function App with a with system managed identity, as well as the additional required components:
66
+
Create a Function App with a with system managed identity, as well as the additional required components:
63
67
64
68
Function app requires below components and configuration:
65
69
- App Service Plan
66
70
- Storage Account
67
71
- Access policy to access secrets in Key Vault using Function App Managed Identity
68
72
69
-
1. Use the Azure Resource Manager template to create components by selecting this link: [Deploy](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fjlichwa%2Fazure-keyvault-basicrotation-tutorial%2Fmaster%2Farm-templates%2Ffunction-app%2Fazuredeploy.json)
For information how to create Function App and using Managed Identity to access Key Vault, see [Create a function app from the Azure portal](../azure-functions/functions-create-function-app-portal.md) and [Provide Key Vault authentication with a managed identity](managed-identity.md)
92
100
93
101
### Rotation function and deployment
102
+
Function is using event as trigger and perform rotation of a secret updating Key Vault and SQL database.
94
103
95
-
Create a rotation function that retrieves the secret and executes rotation, using event grid as a trigger:
104
+
#### Function Event Trigger Handler
105
+
106
+
Below Function reads event data and executes rotation logic
96
107
97
108
```csharp
98
109
publicstaticclassSimpleRotationEventHandler
@@ -113,6 +124,7 @@ public static class SimpleRotationEventHandler
113
124
}
114
125
```
115
126
127
+
#### Secret Rotation Logic
116
128
This rotation method reads database information from the secret, create a new version of the secret, and updates the database with a new secret.
After deployment you should notice two functions under simplerotation-fn:
176
190
177
-

191
+

178
192
179
193
### Add event subscription for “SecretNearExpiry” event
180
194
181
195
Copy the function app eventgrid_extension key.
182
196
183
-

184
-
185
197

186
198
199
+

200
+
187
201
Use the copied eventgrid extension key and your subscription id in below command to create an event grid subscription for SecretNearExpiry events.
188
202
189
203
```azurecli
@@ -211,11 +225,11 @@ After few minutes, sqluser secret should automatically rotate.
211
225
212
226
To verify secret rotation verification, go to Key Vault > Secrets
213
227
214
-

228
+

215
229
216
230
Open the "sqluser" secret and view the original and rotated version
217
231
218
-

232
+

219
233
220
234
## Create Web App
221
235
@@ -225,13 +239,15 @@ The web app requires below components and configuration:
225
239
- Web App with System Managed Identity
226
240
- Access policy to access secrets in Key Vault using Web App Managed Identity
227
241
228
-
1. Use the Azure Resource Manager template to create components by selecting this link: [Deploy](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fjlichwa%2Fazure-keyvault-basicrotation-tutorial%2Fmaster%2Farm-templates%2Fweb-app%2Fazuredeploy.json)
Source code for the web app is at https://github.com/jlichwa/azure-keyvault-basicrotation-tutorial/tree/master/test-webapp.To deploy the web app, do the following:
249
+
Source code for the web app you can find at https://github.com/jlichwa/azure-keyvault-basicrotation-tutorial/tree/master/test-webapp
0 commit comments