spring-projects / spring-projects/spring-security

Add option to prefetch jwks before first request, and refresh it in background

Open
#9,646 11 comments 22 reactions 1 assignee View on GitHub

@jzheaux is already working on this.

Since Apr 15, 2021.

in: oauth2 type: enhancement
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Expected Behavior

JWKS fetching should not have influence on response times on resource server. It should be fetched immediately on start and refreshed in background without affecting request (exception being when cached jwks has no matching key).

Current Behavior

JWKS fetch (for jwks-uri) is only done after it is needed (Nimbus[Reactive]JwtDecoder). This causes first request(s) to be delayed. Also when jwks expires it will block all request until new is fetched.

Context
This is similar (but different) to #9560.
While I agree that for WebClient this may be considered application-specific and left out of framework (though definitely would welcome it as option), I think for server side case is much stronger, as server performance and delays are more impactful, and this is causing intermittent delays for all servers configured with jwks-uri.

Envoy proxy has same issue and they reviewed it favorably as valid requirement for production environment: https://github.com/envoyproxy/envoy/issues/14556, https://github.com/envoyproxy/envoy/issues/14557

I think it could be reasonable default to have it enabled (with opt-out API), but opt-it API would be also ok.

There is also possibility to tie health check with jwks status, but that is separate topic maybe.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.