openiddict / openiddict-core

Flexible and versatile OAuth 2.0/OpenID Connect stack for .NET
https://openiddict.com/
Apache License 2.0
4.47k stars 528 forks source link

[Draft] Thread-safe alteration of server credentials during runtime #2190

Closed patrikwlund closed 2 months ago

patrikwlund commented 2 months ago

What we want to achieve

Without intensive changes to the library design, allow for changing signing/encryption keys during runtime. These changes will allow us to safely build key rotation around this server configuration object. We can run our own background service that updates the config when it needs to.

Changes

Draft limitations, design feedback

If these suggested changes are relevant to include in the library, I also think we should make the credential validation logic publicly/statically available. So that, in our case, the background service can validate and sort the keys before they are set in the config object. I'll gladly do that as well in this PR if you want it.

Further considerations

kevinchalet commented 2 months ago

Hey,

Thanks for your PR.

These changes will allow us to safely build key rotation around this server configuration object. We can run our own background service that updates the config when it needs to.

It's not really how things are supposed to work when using Microsoft.Extensions.Options (which is the library OpenIddict uses for all its stacks): instead of trying to mutate the options instance after it's been created, you're expected to reload it entirely and discard the old instance using an option change token source and custom option initializers.

Some resources that you may find useful:

Since it's a way more flexible approach - that allows changing all the options and not just the credentials - it's not entirely clear what benefit your approach would have compared to the standard option.

Cheers.

patrikwlund commented 2 months ago

a way more flexible approach - that allows changing all the options and not just the credentials

That does seem better, and the library seems to consistently use IOptionsMonitor. I will attempt that angle instead. Thanks!