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
:::danger[Ensure data protection keys are persisted]
50
-
Always make sure data protection is configured to persist data protection keys to storage, using `.PersistKeys...()`
50
+
Always make sure data protection is configured to persist data protection keys to storage, using `.PersistKeysTo...()`
51
51
for your storage mechanism. If you lose your data protection keys, all data protected with those keys is no longer be readable.
52
52
53
-
Additionally ensure the storage mechanism itself is durable. For example, if you are using the default file system
53
+
Additionally, ensure the storage mechanism itself is durable. For example, if you are using the default file system
54
54
based key store, make sure that the configured path is not stored on ephemeral storage. If you are using Redis to store
55
55
data protection keys using `PersistKeysToStackExchangeRedis()`, ensure that your Redis service is configured to persist
56
-
data to a database backup or append-only file. Otherwise you will lose all data
57
-
protection keys when your Redis instance reboots.
56
+
data to a database backup or append-only file. Otherwise, you will lose all data protection keys when your Redis instance reboots.
58
57
59
-
For a more advanced setup, you can create a [key escrow sink](https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/extensibility/key-management?view=aspnetcore-10.0#xmlkeymanager), allowing you to store new data protection keys into a secure storage (e.g., Azure Key Vault) before the new keys are encrypted. This enables you to restore existing data protection keys in case they become corrupted or lost.
58
+
For a more advanced setup, you can create a [key escrow sink](https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/extensibility/key-management?view=aspnetcore-10.0#xmlkeymanager), allowing you to store new data protection keys into
59
+
a secure storage (e.g., Azure Key Vault) before the new keys are encrypted.
60
+
This enables you to restore existing data protection keys in case they become corrupted or lost.
60
61
:::
61
62
62
-
63
63
## Common Problems
64
64
65
65
Common data protection problems occur when data is protected with a key that is not available when the data is later
66
66
read. A common symptom is `CryptographicException`s in the application logs. For example, when IdentityServer's automatic key
67
67
management fails to read its signing keys due to a data protection failure, it will log an error message
68
-
such as "Error unprotecting key with kid {Signing Key ID}.", and log the underlying
69
-
`System.Security.Cryptography.CryptographicException`, with a message like "The key {Data Protection Key ID} was not
70
-
found in the key ring."
68
+
such as `"Error unprotecting key with kid {Signing Key ID}."`, and log the underlying
69
+
`System.Security.Cryptography.CryptographicException`, with a message like `"The key {Data Protection Key ID} was not
70
+
found in the key ring."`
71
71
72
72
Failures to read automatic signing keys are often the first place where a data protection problem manifests, but any of
73
73
many places where ASP.NET uses data protection might also throw `CryptographicException`s.
@@ -82,16 +82,14 @@ There are several ways that data protection problems can occur:
82
82
directory from source control and make sure keys are not included in your builds. Note that if you are using our
83
83
Entity Framework based implementation of the operational data stores, then the keys will instead be stored in the
84
84
database.
85
-
3. Data protection creates keys isolated by application name. If you don't specify a name, the content root path of the
86
-
application will be used. But, beginning in .NET 6.0 Microsoft changed how they handle the path, which can cause data
87
-
protection keys to break. Their docs on the problem
88
-
are [here](https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview#setapplicationname),
89
-
including a work-around where you de-normalize the path. Then, in .NET 7.0, this change was reverted. The solution is
90
-
always to specify an explicit application name, and if you have old keys that were generated without an explicit
91
-
application name, you need to set your application name to match the default behavior that produced the keys you want
92
-
to be able to read.
93
-
4. If you host on IIS, special configuration is needed for data protection. In most default
94
-
deployments, IIS lacks the permissions required to persist data protection keys, and falls back to using an ephemeral
95
-
key generated every time the site starts up. Microsoft's docs on this issue
96
-
are [here](https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/advanced?view=aspnetcore-7.0#data-protection).
85
+
3. Data protection derives keys isolated per application name from the generated key material. If you don't specify a name,
86
+
the content root path of the application will be used. In .NET 6.0, Microsoft introduced a breaking change: they changed
87
+
how ASP.NET Core sets the content root path, which can cause Data Protection issues. This change was reverted in .NET 7.0,
88
+
and Microsoft has [documented a workaround in case your application has to restore the correct application name](https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview#set-the-application-name-setapplicationname).
89
+
A better solution is to always specify an explicit application name, but know that changing the application name will
90
+
cause all existing data protected with the previous application name to become unreadable.
91
+
4. When hosting your web application on Microsoft IIS, [special configuration may be required for data protection](https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/advanced#data-protection).
92
+
In most default deployments, IIS falls back to using an ephemeral storage for data protection keys, which means that
93
+
new keys are generated every time the application pool restarts. We recommend storing data protection keys in a shared location,
94
+
such as a protected file share or database, and configuring IIS to use that location for data protection.
0 commit comments