Resolve JWKS keys in-process for embedded auth server (MCP server)#4502
Merged
tgrunnagle merged 3 commits intomainfrom Apr 2, 2026
Merged
Resolve JWKS keys in-process for embedded auth server (MCP server)#4502tgrunnagle merged 3 commits intomainfrom
tgrunnagle merged 3 commits intomainfrom
Conversation
The token validator previously fetched JWKS keys over HTTP from the proxy's own endpoint, requiring insecureAllowHTTP and jwksAllowPrivateIP workarounds. When the embedded auth server is active, resolve keys directly from the in-memory KeyProvider, falling back to HTTP for external issuers. Closes #4466 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Deduplicate signing method validation and kid extraction used by both getKeyFromLocalProvider and getKeyFromJWKS into a single helper. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4502 +/- ##
==========================================
- Coverage 69.31% 69.13% -0.19%
==========================================
Files 502 502
Lines 51632 51959 +327
==========================================
+ Hits 35791 35922 +131
- Misses 13075 13250 +175
- Partials 2766 2787 +21 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jerm-dro
requested changes
Apr 2, 2026
Contributor
jerm-dro
left a comment
There was a problem hiding this comment.
Thanks for picking this up — the overall design is great. Clean fallback behavior, solid test coverage, and this solves a real pain point for operators. I'm just being a stickler on the interface boundary to keep private key access intentional.
jerm-dro
approved these changes
Apr 2, 2026
MatteoManzoni
pushed a commit
to DocPlanner/toolhive
that referenced
this pull request
Apr 4, 2026
…tacklok#4502) When the embedded auth server is enabled, token validation currently fails silently because the token validator fetches JWKS keys over HTTP from the proxy's own endpoint. This self-referential HTTP call requires operators to set `insecureAllowHTTP` and/or `jwksAllowPrivateIP` flags — insecure workarounds that are difficult to debug when missing. This PR eliminates the self-referential HTTP fetch by wiring the embedded auth server's `KeyProvider` directly into the token validator. When both components run in the same process, JWKS keys are resolved in-memory with a graceful fallback to HTTP for cases where the local provider cannot satisfy the request. Note: this only addresses the issue for the runner and proxy runner - vMCP wiring will come in a separate change.
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.
Summary
When the embedded auth server is enabled, token validation currently fails silently because the token validator fetches JWKS keys over HTTP from the proxy's own endpoint. This self-referential HTTP call requires operators to set
insecureAllowHTTPand/orjwksAllowPrivateIPflags — insecure workarounds that are difficult to debug when missing.This PR eliminates the self-referential HTTP fetch by wiring the embedded auth server's
KeyProviderdirectly into the token validator. When both components run in the same process, JWKS keys are resolved in-memory with a graceful fallback to HTTP for cases where the local provider cannot satisfy the request.Note: this only addresses the issue for the runner and proxy runner - vMCP wiring will come in a separate PR.
Related to #4466
Type of change
Test plan
task test)task lint-fix)Changes
pkg/auth/token.gokeyProviderfield toTokenValidator,WithKeyProvideroption,getKeyFromLocalProvidermethod that resolves keys in-process before falling back to HTTP, and relax the JWKS URL requirement when a local provider is presentpkg/auth/middleware.goKeyProviderfrom runner into token validator options during middleware creationpkg/authserver/runner/embeddedauthserver.gokeyProviderfrom the auth server's key materialpkg/runner/runner.goKeyProviderfrom the embedded auth server during startup and expose it viaGetKeyProvider()pkg/transport/types/transport.goMiddlewareRunnerinterface withGetKeyProvider()pkg/transport/types/mocks/mock_transport.goMiddlewareRunnerinterfacepkg/auth/token_test.gogetKeyFromLocalProvider: kid match, kid miss (fallback), provider error (fallback), unsupported signing method, missing kidpkg/authserver/runner/embeddedauthserver_test.goKeyProvider()returns a functional provider after constructionpkg/auth/middleware_test.goGetKeyProvider()expectationDoes this introduce a user-facing change?
Yes. Operators using the embedded auth server no longer need to configure
jwksUrl,insecureAllowHTTP, orjwksAllowPrivateIPfor token validation to work. The embedded auth server's signing keys are resolved in-process automatically.Special notes for reviewers
getKeyFromLocalProviderreturns(nil, nil)to signal "fall back to HTTP" — this keeps the existing HTTP-based JWKS path untouched as a fallback and avoids breaking external OIDC providers.resolveClientSecrethelper was extracted as a standalone function during the refactor; the logic is unchanged.ErrMissingIssuerAndJWKSURLvalidation is now relaxed when akeyProvideris present, since keys can be resolved without a JWKS URL.Generated with Claude Code