Fix JWK refresh cache check#99
Open
e345ee wants to merge 1 commit into
Open
Conversation
When a caller requests a missing desired key, the cache guard used Option::map and short-circuited every Some(kid) request before checking whether the key existed. This prevented key rotation from loading new JWKS entries until restart. Use and_then so only an actual cached entry skips the fetch, and add a regression test that refreshes from a JWKS endpoint after the requested kid changes. Fixes EpicGames#78 Signed-off-by: Sadovoi Grisha <gsad1030@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fix the JWK cache short-circuit so
fetch_new_keys(Some(kid))skips the network fetch only when the requestedkidis actually present in the local cache.Why
The previous check used
desired.map(|d| cache.get(d)).is_some(), which returnstruefor everySome(kid)regardless of whether the cache contains that key. As a result, a missing or rotated JWK could never be fetched after startup, preventing key rotation from taking effect until the server restarted.Fixes #78.
How
desired.and_then(|d| cache.get(d)).is_some().old-kid, then servesnew-kid, verifying that requesting the missing key triggers a refresh.Testing
cargo +nightly fmt --all -- --checkcargo clippy -p lore-server --all-targets -- -D warnings --no-depscargo clippy --all-targets -- -D warnings --no-depscargo test