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/azure-app-configuration/reload-key-vault-secrets-dotnet.md
+16-12Lines changed: 16 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,38 +17,42 @@ ms.author: avgupta
17
17
18
18
Azure App Configuration and Azure Key Vault are complementary services used side by side in many applications. App Configuration helps you use the services together by creating keys in your App Configuration store that reference secrets or certificates stored in Key Vault. Because Key Vault stores the public and private key pair of a certificate as a secret, your application can retrieve any certificate as a secret from Key Vault.
19
19
20
-
As a good security practice, [secrets](/azure/key-vault/secrets/tutorial-rotation) and [certificates](/azure/key-vault/certificates/tutorial-rotate-certificates) should be rotated periodically. After they're rotated in Key Vault, your application should pick up the latest secret and certificate values. There are two ways to load these values without restarting your application:
21
-
22
-
- Update the value of a sentinel key to trigger the refresh of your entire configuration. This process reloads all Key Vault secrets and certificates. For more information, see [Monitoring a sentinel key](howto-best-practices.md#monitoring-a-sentinel-key) and [Azure App Configuration dynamic settings sample](/samples/dotnet/samples/azure-app-config-dynamic-settings/).
23
-
- Periodically reload some or all secrets and certificates from Key Vault.
24
-
25
-
When you use the first option, you need to update the value of the sentinel key in App Configuration whenever you rotate secrets and certificates in Key Vault. This approach works well when you want to force an immediate reload of secrets and certificates in your application. However, when secrets and certificates are rotated automatically in Key Vault, your application can experience errors if you don't update the value of the sentinel key in time.
26
-
27
-
The second option provides a way to completely automate this process. You can configure your application to reload secrets and certificates from Key Vault within your acceptable delay from the time of rotation. This article walks you through the second option.
20
+
When secrets and certificates are rotated in Key Vault, your application should pick up the latest values. This article shows you how to automate the process of reloading Key Vault secrets and certificates without restarting your application.
28
21
29
22
## Prerequisites
30
23
31
24
- The ASP.NET Core web app that you update when you complete the steps in [Tutorial: Use Key Vault references in an ASP.NET Core app](./use-key-vault-references-dotnet-core.md). This article shows you how to set up your application to automatically reload secrets and certificates from Key Vault. It builds on the tutorial for implementing Key Vault references in your code.
32
25
- The key vault that you create when you complete the steps in [Tutorial: Use Key Vault references in an ASP.NET Core app](./use-key-vault-references-dotnet-core.md).
33
26
- The [Microsoft.Azure.AppConfiguration.AspNetCore](https://www.nuget.org/packages/Microsoft.Azure.AppConfiguration.AspNetCore) package, version 4.4.0 or later.
34
27
28
+
## Choose an approach to reloading
29
+
30
+
As a good security practice, secrets and certificates should be rotated periodically. For more information, see [Automate the rotation of a secret for resources that use one set of authentication credentials](/azure/key-vault/secrets/tutorial-rotation) and [Tutorial: Configure certificate autorotation in Key Vault](/azure/key-vault/certificates/tutorial-rotate-certificates). After secrets and certificates are rotated in Key Vault, there are two ways to load these values without restarting your application:
31
+
32
+
- Update the value of a sentinel key to trigger the refresh of your entire configuration. This process reloads all Key Vault secrets and certificates. For more information, see [Monitoring a sentinel key](howto-best-practices.md#monitoring-a-sentinel-key) and [Azure App Configuration dynamic settings sample](/samples/dotnet/samples/azure-app-config-dynamic-settings/).
33
+
- Periodically reload some or all secrets and certificates from Key Vault.
34
+
35
+
When you use the first option, you need to update the value of the sentinel key in App Configuration whenever you rotate secrets and certificates in Key Vault. This approach works well when you want to force an immediate reload of secrets and certificates in your application. However, when secrets and certificates are rotated automatically in Key Vault, your application can experience errors if you don't update the value of the sentinel key in time.
36
+
37
+
The second option provides a way to automate this process. You can configure your application to reload secrets and certificates from Key Vault within your acceptable delay from the time of rotation. This article walks you through the second option.
38
+
35
39
## Add an automatically rotating certificate to Key Vault
36
40
37
41
To add an automatically rotating certificate to a key vault, follow the steps in [Tutorial: Configure certificate autorotation in Key Vault](/azure/key-vault/certificates/tutorial-rotate-certificates).
38
42
39
-
- Use the key vault that you create in [Tutorial: Use Key Vault references in an ASP.NET Core app](./use-key-vault-references-dotnet-core.md).
43
+
- Use the key vault that you create in the tutorial listed in [Prerequisites](#prerequisites).
40
44
- Name the certificate **ExampleCertificate**.
41
45
42
46
## Add a reference to the Key Vault certificate in App Configuration
43
47
44
-
1. Go to the [Azure portal](https://portal.azure.com), select **All resources**, and then select the App Configuration instance that you use in [Tutorial: Use Key Vault references in an ASP.NET Core app](./use-key-vault-references-dotnet-core.md).
48
+
1. Go to the [Azure portal](https://portal.azure.com), select **All resources**, and then select the App Configuration store that you use in the tutorial listed in [Prerequisites](#prerequisites).
45
49
46
50
1. Select **Configuration explorer**.
47
51
48
52
1. Select **Create** > **Key Vault reference**, and then enter the following values:
49
53
- For **Key**: Enter **TestApp:Settings:KeyVaultCertificate**.
50
54
- For **Label**: Leave the value blank.
51
-
- For **Subscription**, **Resource group**, and **Key vault**: Enter the values you use when you create the key vault in [Tutorial: Use Key Vault references in an ASP.NET Core app](./use-key-vault-references-dotnet-core.md).
55
+
- For **Subscription**, **Resource group**, and **Key vault**: Enter the values you use when you create the key vault in the tutorial listed in [Prerequisites](#prerequisites).
52
56
- For **Secret**: Select the secret named **ExampleCertificate** that you create in the previous section.
53
57
- For **Secret Version**: Select **Latest version**.
54
58
@@ -57,7 +61,7 @@ To add an automatically rotating certificate to a key vault, follow the steps in
57
61
58
62
## Update code to reload Key Vault secrets and certificates
59
63
60
-
Go to the folder that contains the ASP.NET Core web app project that you update in [Tutorial: Use Key Vault references in an ASP.NET Core app](./use-key-vault-references-dotnet-core.md).
64
+
Go to the folder that contains the ASP.NET Core web app project that you update in the tutorial listed in [Prerequisites](#prerequisites).
61
65
62
66
Open *Program.cs*, and replace the call to the `AddAzureAppConfiguration` method with the call in the following code. The updated call uses the `SetSecretRefreshInterval` method to set up a refresh interval for your Key Vault certificate. With this change, your application reloads the public-private key pair for **ExampleCertificate** every 12 hours.
0 commit comments