-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for dynamic OIDC JWK set resolution #36935
Support for dynamic OIDC JWK set resolution #36935
Conversation
d161990
to
c2483bb
Compare
c2483bb
to
0e35374
Compare
Dear reviewers, please wait till Monday or so before starting reviewing, in case I may change something, will ping you, thanks |
I'll be on vacation until Nov 29th, so I'll leave it to the experts 😉 |
This comment has been minimized.
This comment has been minimized.
Super, have a great time off, @gastaldi 👍 |
0e35374
to
6befdce
Compare
@pedroigor @michalvavrik I've added a Also made it easier to extract token in the OIDC request context properties. So as described in the issue description, the use case is as follows: OIDC connection is initialized but JSON web keys must not be fetched just yet, but only when a token (ID token or access token) is already available, so the only main thing this PR does is just optionally delaying fetching the keys, nearly the same case as refreshing them. Then once the token is available, it must be available to the OIDC request filter which will use this token to create an authentication token to the JWKS endpoint to make sure the right keys are returned. PR is ready for review |
Sorry, I've rerun the affected test but obviously something else got broken |
Hmm it is the memory cache test which was passing for me |
6befdce
to
4a6db62
Compare
Giving the await condition a couple of extra seconds seems to stabilize it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to follow code the best I could, but I'm not able to foresee all consequences of your changes, for I don't know OIDC well enough. I'll let @pedroigor to review alone or please find additional reviewer. Thanks
extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/MemoryCache.java
Outdated
Show resolved
Hide resolved
extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/MemoryCache.java
Outdated
Show resolved
Hide resolved
extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/MemoryCache.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sberyozkin LGTM.
This comment has been minimized.
This comment has been minimized.
Thanks @pedroigor , let me do a few minor updates as proposed by @michalvavrik and I'll merge, cheers |
@michalvavrik Thanks for the review, I'll apply minor changes tomorrow as I have no laptop right now. |
@michalvavrik FYI, as far as OIDC is concerned, there are no any fundamental changes, tokens have to be verified by public keys fetched from OIDC keys endpoint which is done at the OIDC connection and discovery time, but the use case is to delay it until the token is available. So if this requirement is enabled then we simply retrieve keys at the token verification time |
4a6db62
to
af65f8a
Compare
✔️ The latest workflow run for the pull request has completed successfully. It should be safe to merge provided you have a look at the other checks in the summary. |
Fixes #36563
PR to support resolving keys at the moment when the token is available, with token claims or headers containing the information required to fetch correct verification keys as well as additionally affect an optional JWKS endpoint specific authentication.
Typically, JSON web keys are resolved early from the
public
endpoint, when the OIDC connection is established, when the JWKS endpoint address is discovered or manually configured. In the use case which this PR targeting, it is impossible because the JWKS endpoint authentication is required and the authentication credentials for the key retrieval is derived from the token - which is not available.So this PR does the following:
quarkus.oidc.jwks.resolve-early
configuration property,true
by default, setting it tofalse
enables a dynamic, just in time JWK resolution.read-once
approach at the initialization time, caching resolved keys is necessary, so the defautt in-memory cache support is providedquarkus.oidc.jwks.resolve-early=false
then the keys are simply resolved at the token verification timeMemoryCache
class and remove a ton of duplicated code - this is also an early step toward supporting customizing cache support only for all of these featuresCC @calvernaz