Repository navigation
Pass the JWKS auth token path to vMCP - #7221
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7221 +/- ##
=======================================
Coverage 81.64% 81.64%
=======================================
Files 903 903
Lines 91789 91824 +35
=======================================
+ Hits 74939 74970 +31
- Misses 16845 16849 +4
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
A VirtualMCPServer whose incomingAuth.oidcConfigRef points at a kubernetesServiceAccount MCPOIDCConfig rejected every caller with 401. The resolver sets the pod's service-account token path for OIDC discovery and JWKS requests, but the vMCP converter dropped it and the vMCP config had no field for it, so discovery against an API server that requires authentication failed with 403. Add an optional jwksAuthTokenPath to the vMCP OIDC config, map it from the resolved MCPOIDCConfig, and pass it to the token validator, the same way caBundlePath is carried. MCPServer and MCPRemoteProxy already pass this path through the runner. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reject null bytes, path traversal, and relative paths in the new incomingAuth.oidc.jwksAuthTokenPath, matching the existing caBundlePath checks. Without this, a standalone config with a relative path would resolve against the working directory. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2301949 to
7624f24
Compare
aponcedeleonch
left a comment
There was a problem hiding this comment.
Nice fix. The token path now flows from the resolver all the way to the HTTP client used for discovery and JWKS, which matches how MCPServer and MCPRemoteProxy already do it. I checked it locally: removing the AuthTokenFile line makes both new factory tests fail, so they guard the bug well.
I left two comments about edge cases where vMCP now fails to start instead of starting with broken auth. Neither is blocking, happy to see them in a follow-up.
peppescg
left a comment
There was a problem hiding this comment.
LGTM. The fix is correct and mirrors how caBundlePath is carried end to end.
Verified locally:
- Ran the three changed packages with
-race: all pass. - Removed the
AuthTokenFileline inincoming.go: both new tests fail (200 → 401), so they cover the fix. - The converter always replaces
spec.config.incomingAuth(spec.incomingAuthis required), so the new CRD field can't be set by hand to point vMCP at an arbitrary file.
The inline comments are non-blocking. One more nit: the PR body says the middleware test checks that a valid JWT is accepted only when the token file is sent, but the test covers only the positive case. A case without JWKSAuthTokenPath that expects 401 would back that up, or the sentence could be reworded.
Out of scope, and MCPServer has the same behavior: the token is read once at startup (createTokenSourceFromFile in pkg/networking/http_client.go). On clusters with --service-account-extend-token-expiration=false, the projected token expires after about an hour and JWKS refresh would start failing.
A relative or traversing jwksAuthTokenPath from an inline MCPOIDCConfig was rendered into the vMCP ConfigMap and only rejected when the pod started, so the user saw a crash loop with nothing on the VirtualMCPServer status. The operator now runs the same path checks right after conversion and reports a failure as AuthConfigured=False (AuthInvalid) without writing the ConfigMap. vMCP keeps its own check. vMCP also stats the token file before building the validator, so a configured but missing file fails with an error that names jwksAuthTokenPath and how to fix it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
df64fa9
peppescg
left a comment
There was a problem hiding this comment.
Thanks, all addressed. The operator-side ValidateOIDCFilePaths check, which sets AuthConfigured=False and skips the ConfigMap, plus the clearer startup error, go further than I asked. The condition also recovers once the path is fixed: ensureAuthSecretsValid sets it back to true on the next reconcile, and the MCPOIDCConfig watch triggers that reconcile.
Re-ran the changed packages on df64fa9 with -race, including the EnsureVmcpConfigConfigMap controller tests: all pass.
One leftover nit, take it or leave it: the PR body still says the middleware test checks that a valid JWT is accepted only when the token file is sent, but the test covers only the positive case.
Summary
incomingAuth.oidcConfigRefpoints at anMCPOIDCConfigof typekubernetesServiceAccountrejects every caller with 401. The OIDC resolver sets the pod's service-account token path (/var/run/secrets/kubernetes.io/serviceaccount/token) so OIDC discovery and JWKS requests can authenticate to the Kubernetes API server. The vMCP converter drops that path and the vMCP config has no field for it, so the request goes out unauthenticated and the vMCP pod logsoidc discovery failed after retries ... status 403. The same applies to aninlineconfig that setsjwksAuthTokenPath. MCPServer and MCPRemoteProxy are not affected: they pass the path to the token validator throughrunner.WithOIDCConfig.jwksAuthTokenPathfield to the vMCPOIDCConfig(pkg/vmcp/config).JWKSAuthTokenPathfrom the resolvedMCPOIDCConfigin the operator's vMCP converter.TokenValidatorConfig.AuthTokenFilefrom it in the vMCP incoming-auth factory.caBundlePath(no null bytes, no.., absolute path) through an exportedValidateOIDCFilePaths. The operator calls it right after conversion inensureVmcpConfigConfigMap: a bad path sets the VirtualMCPServer toFailedwithAuthConfigured=False(AuthInvalid) andObservedGeneration, returns a terminalSpecValidationError(no requeue), and the ConfigMap is not written. vMCP runs the same check when it loads its config.jwksAuthTokenPath, the path, and the fix.caBundlePathis already carried. Regenerated the VirtualMCPServer CRD anddocs/operator/crd-api.md, and described the behavior indocs/arch/09-operator-architecture.md.Type of change
Test plan
task test)task test-e2e)task lint-fix, andgo run github.com/golangci/golangci-lint/v2/cmd/[email protected] runon./pkg/vmcp/config/...,./pkg/vmcp/auth/factory/...,./cmd/thv-operator/pkg/vmcpconfig/...,./cmd/thv-operator/controllers/...; both report 0 issues)New unit tests cover the converter mapping, the factory mapping, the path checks (vMCP validator and
ValidateOIDCFilePaths), the token-file stat check, and the operator rejecting a relativejwksAuthTokenPathwith the expected status and no ConfigMap. A middleware test uses an issuer that returns 403 to discovery and JWKS requests without the bearer token, and checks that a valid JWT is accepted only when the token file is sent.Manual test on a kind cluster with default RBAC (no anonymous discovery binding), operator and vMCP images built from this branch (
task operator-deploy-local):MCPOIDCConfigof typekubernetesServiceAccountwith issuerhttps://kubernetes.default.svc.cluster.local, a VirtualMCPServer referencing it with audiencevmcp-test, and one MCPServer backend.jwksAuthTokenPath: /var/run/secrets/kubernetes.io/serviceaccount/token.initializefrom a pod using a projected token with audiencevmcp-testreturns 200. Without a token it returns 401, and with the default-audience SA token it returns 401.inlineMCPOIDCConfig withjwksAuthTokenPath: tokengoes toFailedwithAuthConfigured=False AuthInvalid(jwksAuthTokenPath must be an absolute path),observedGeneration: 1, and no ConfigMap or Deployment is created.API Compatibility
v1beta1API, OR theapi-break-allowedlabel is applied and the migration guidance is described above.The only change is a new optional field in the VirtualMCPServer
config.incomingAuth.oidcschema.Does this introduce a user-facing change?
Yes. Before: a VirtualMCPServer using a
kubernetesServiceAccountMCPOIDCConfig (or aninlineone withjwksAuthTokenPath) failed OIDC discovery with 403 and returned 401 to every request. After: vMCP sends the configured token on discovery and JWKS requests, and callers with a valid token are accepted.Upgrade note:
jwksAuthTokenPathused to be ignored by vMCP. Now:.., in aninlineMCPOIDCConfig referenced by a VirtualMCPServer used to be ignored. The VirtualMCPServer now goes toFailedwithAuthConfigured=False(AuthInvalid), and the operator does not update its ConfigMap.incomingAuth.oidc.jwksAuthTokenPath "<path>" is not accessible: .... Examples: an inline config shared with an MCPServer whose token file only that pod mounts, or a vMCP pod template withautomountServiceAccountToken: false. The fix is to mount the token into the vMCP pod, or unsetjwksAuthTokenPath(useClusterAuth: falseforkubernetesServiceAccount).Special notes for reviewers
useClusterAuth(the default forkubernetesServiceAccount) sends its pod service-account token to the issuer, JWKS, and introspection URLs the MCPOIDCConfig names, including a customissuer. This is an accepted trade-off that keeps vMCP consistent with MCPServer. Sending the token only to the in-cluster API server is a separate follow-up.🤖 Generated with Claude Code