JWT: add optional KeySetSearcher callback to Validator#187
Merged
Conversation
jimlambrt
requested changes
Apr 15, 2026
Collaborator
jimlambrt
left a comment
There was a problem hiding this comment.
Do we want explicit tests for error cases for things like multi-signatures, missing kids, malformed token?
Collaborator
Author
Yep, added tests for those cases. Thanks for calling it out! |
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.
Adds an optional
KeySetSearchercallback to the JWT Validator to support dynamic KeySet lookup based on the JWT's key ID (kid) header. When provided, the Validator extracts the kid from the JWT header and calls the callback to retrieve the appropriate KeySet, instead of the default sequential KeySet verification.Motivation:
Vault's JWT auth plugin uses CAP for JWT validation, which delegates signature verification to
go-oidc. The current flow checks each keyset's cache and if the key is not found, fetches from the JWKS URL before moving to the next keyset. This sequential fetch-per-keyset behavior was causing a performance issue for a customer with multiple JWKS endpoints configured.This change adds a
KeySetSearchercallback to CAP's Validator, allowing the plugin to implement custom KeySet lookup logic. The Validator handles all JWT parsing and security validation (extracting the kid from the JWT header, verifying the signature with the returned KeySet), while the callback provides the logic for locating the appropriate KeySet. This enables implementations to check all caches before refreshing any keys from remote JWKS URLs.The
NewValidatorWithKeySetSearcherconstructor has been added to avoid modifying the existingNewValidator. Existing callers usingNewValidatorare completely unaffected.PCI review checklist
I have documented a clear reason for, and description of, the change I am making.
If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.
If applicable, I've documented the impact of any changes to security controls.
Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.