Skip to content

JWT: add optional KeySetSearcher callback to Validator#187

Merged
jimlambrt merged 5 commits intomainfrom
suraj/add-jwt-callback
Apr 15, 2026
Merged

JWT: add optional KeySetSearcher callback to Validator#187
jimlambrt merged 5 commits intomainfrom
suraj/add-jwt-callback

Conversation

@suraj-simha
Copy link
Copy Markdown
Collaborator

Adds an optional KeySetSearcher callback 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 KeySetSearcher callback 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 NewValidatorWithKeySetSearcher constructor has been added to avoid modifying the existing NewValidator. Existing callers using NewValidator are 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.

@suraj-simha suraj-simha requested a review from a team as a code owner April 15, 2026 09:49
@suraj-simha suraj-simha changed the title Suraj/add jwt callback JWT: add optional SignatureVerifier callback to Validator Apr 15, 2026
@suraj-simha suraj-simha changed the title JWT: add optional SignatureVerifier callback to Validator JWT: add optional KeySetSearcher callback to Validator Apr 15, 2026
@suraj-simha suraj-simha requested a review from jimlambrt April 15, 2026 11:05
Copy link
Copy Markdown
Collaborator

@jimlambrt jimlambrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want explicit tests for error cases for things like multi-signatures, missing kids, malformed token?

@suraj-simha
Copy link
Copy Markdown
Collaborator Author

Do we want explicit tests for error cases for things like multi-signatures, missing kids, malformed token?

Yep, added tests for those cases. Thanks for calling it out!

Copy link
Copy Markdown
Collaborator

@jimlambrt jimlambrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ty

@jimlambrt jimlambrt merged commit 9d4dd6d into main Apr 15, 2026
7 checks passed
@jimlambrt jimlambrt deleted the suraj/add-jwt-callback branch April 15, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants