Skip to content

Allow customization of the DataProtection PersistKeysToDbContext key ring store #26786

@JoeMarkov

Description

@JoeMarkov

As a good developer I should configure the Data Protection API so that I store the key ring outside my service. So obviously you try to

            services.AddDataProtection()
                .PersistKeysToDbContext<DataProtectionContext>();

Great! it works! Simple and awesome! You end up with a table and an entry like this:

image

But, if I now want to do a micro-service style architecture with a shared database for infrastructure things like this, I get into trouble because the Data Protection API just takes the first available key ring in this table. So clearly we have a race condition if I want to let multiple applications share this table.

I am not using my database for much else and creating a separate database just to keep the key rings apart feels a bit stupid.

So my proposal is to allow the user to define the name of the key ring to look for. So that I can keep multiple independent key rings in the same shared table.

            services.AddDataProtection()
                .PersistKeysToDbContext<DataProtectionContext>(applicationName: "PaymentAPI" );

and another app like

            services.AddDataProtection()
                .PersistKeysToDbContext<DataProtectionContext>(applicationName: "InvoiceAPI" );

This would then store two rows in the [DataProtectionKeys] table.

Is your feature request related to a problem? Please describe.

Yes, I try to keep all my Data Protection key rings in one table. But that does not work under current implementation. I either have to create a separate context per service or hack the implementation of PersistKeysToDbContext.

Describe the solution you'd like

Passing a key ring name to the PersistKeysToDbContext would help me a lot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    affected-fewThis issue impacts only small number of customersarea-dataprotectionIncludes: DataProtectionenhancementThis issue represents an ask for new feature or an enhancement to an existing oneseverity-majorThis label is used by an internal tool

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions