aspnetcore: DataProtection - Wrong activation time
Describe the bug
Activation time is ahead of the creation time and causing (Cookies was not authenticated. Failure message: Unprotect ticket failed)
To Reproduce
Multiple service is deployed with the below code to protect the cookies. Everything works as expected. From yesterday, suddenly facing this error (Cookies was not authenticated. Failure message: Unprotect ticket failed) in one service, were the other services works as expected. On further analysis, found activate date is ahead of the creation date in the blob stored XML.
var dataProtectionBuilder = services.AddDataProtection()
.PersistKeysToAzureBlobStorage(environmentVariable.AzureBlobStorage, "secret", "secretkey.xml")
.SetApplicationName("cookiename");
dataProtectionBuilder?.ProtectKeysWithCertificate(x509ClientCertificate);
Below is the active key in the blob stored xml file.
<creationDate>2021-05-26T09:35:20.9324376Z</creationDate>
<activationDate>2021-05-26T09:35:20.078957Z</activationDate
<expirationDate>2021-08-24T09:35:20.078957Z</expirationDate>
Exceptions (if any)
Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler[7] Cookies was not authenticated. Failure message: Unprotect ticket failed
Further technical details
- ASP.NET Core version - 3.1
- Microsoft.AspNetCore.DataProtection, Version=3.1.0.0
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 22 (5 by maintainers)
@JarrodJ83 Sorry for the late reply - this wasn’t the main tracking issue for Data Protection races. There are multiple races in this area, especially prior to 9.0, and most effort to date has been focused on making these exceptions rarer (vs eliminating them).
An approach we’ve been exploring for addressing the root cause has been to have a separate component that is responsible for all key generation and disabling key generation in app instances. If there’s only one writer, there’s no race. Unfortunately, the approach isn’t mature enough for us to have a doc or a sample at this point, but let me know if you have questions.