Skip to content

AddDataProtection().PersistKeysToFileSystem() used with pods causes race condition and two data-protection keys to be generated at the same time. #28475

Closed
@Duke4848

Description

@Duke4848

Describe the bug

I use

 services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(filesharePath);

to generate data-protection keys. This produces the issue on initial application startup and possibly the same may happen during rotation of data-protection key. What essentially happens is:

  1. 2 or more instances of app on startup detect that there is no data-protection key in the fileshare
  2. 2 or more instances generate the key thus the pods have different data-protection keys for next 24 hours unless I force pods to restart. This causes for example issues with antiforgery tokens not being accepted by instances running on other pods.

The same may probably happen when the existing data-protection key is near expiration time and 2 instances running on separate pods decide do generate the new data-protection key.

Is it possible to do something about it?

To Reproduce

Use

 services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(filesharePath);

and deploy your ASP.NET Core app two few pods.

Exceptions (if any)

Further technical details

  • ASP.NET Core version 3.1

Metadata

Metadata

Assignees

Labels

Needs: Author FeedbackThe author of this issue needs to respond in order for us to continue investigating this issue.Status: No Recent Activityaffected-mediumThis issue impacts approximately half of our customersarea-dataprotectionIncludes: DataProtectionbugThis issue describes a behavior which is not expected - a bug.severity-minorThis label is used by an internal tool

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions