Repository navigation
Send KSA service account token only to the in-cluster API server - #7248
Merged
Merged
Conversation
For kubernetesServiceAccount MCPOIDCConfigs, useClusterAuth defaults to true and attached the workload's own service account token to every OIDC discovery, JWKS and introspection request, whatever host the issuer, jwksUrl or introspectionUrl named. The token was added so workloads could fetch the API server's JWKS, but it carries the workload's Role (statefulset management for the proxy runner, secret reads for vMCP), so it should not reach any other host. With useClusterAuth unset, attach the token only when the issuer and any explicit JWKS or introspection URL are https URLs on the exact in-cluster API server names. The CA bundle and private-IP allowance are unchanged. An explicit useClusterAuth: true keeps sending the token everywhere, for issuers behind a custom cluster domain, and false still sends nothing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7248 +/- ##
==========================================
- Coverage 81.69% 81.66% -0.03%
==========================================
Files 903 904 +1
Lines 91789 91838 +49
==========================================
+ Hits 74985 74998 +13
- Misses 16799 16835 +36
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jhrozek
reviewed
Nov 23, 2026
jhrozek
left a comment
Contributor
There was a problem hiding this comment.
Nice change overall, the exact host match and the comment explaining why are good. Two things inline: the gate checks a couple of URLs that never actually get the token, which breaks an external-issuer + in-cluster-jwksUrl setup, and the field doc wording is a bit stronger than what the code guarantees.
When jwksUrl is set the validator skips discovery and never contacts the issuer, so requiring an in-cluster issuer as well withheld the token from an in-cluster JWKS endpoint configured with an external issuer. Introspection never carries the token for these configs, because they have no client credentials. Check jwksUrl when set, otherwise the issuer, and describe the guarantee as what the code checks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 tasks done
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
For an
MCPOIDCConfigof typekubernetesServiceAccount,useClusterAuthdefaults to true. The workload's own service account token was then attached to every OIDC discovery, JWKS and introspection request, whatever host theissuer,jwksUrlorintrospectionUrlnamed. The token was added so a workload could fetch JWKS from the Kubernetes API server, which needs authentication (#978). But the token carries the workload's Role: StatefulSet management for the MCPServer proxy runner, and Secret reads for vMCP in discovered mode. So it should not go to any other host, such as a custom or external issuer.useClusterAuthunset, the resolver attaches the token only when the URL the validator actually fetches is anhttpsURL whose host is exactlykubernetes.default.svcorkubernetes.default.svc.cluster.local. That URL isjwksUrlwhen set, since the validator then skips discovery and never contacts the issuer; otherwise it is the issuer used for discovery. Ajwks_uriadvertised by the in-cluster API server's discovery document is trusted.introspectionUrlis not part of the check. AkubernetesServiceAccountconfig has no client credentials, so the validator's introspection client never carries the token.jwks_uri.useClusterAuth: truesends the token unconditionally. This is the opt-in for an issuer that requires it but sits behind other names, such as a custom cluster domain.falsesends nothing, as before.useClusterAuthfield docs anddocs/arch/09-operator-architecture.mddescribe the rules.Type of change
Test plan
resolver_configref_test.gofor in-cluster issuer and JWKS (token sent); in-clusterjwksUrlwith an external issuer (token sent); external issuer, externaljwksUrl, a lookalikekubernetes.default.svc.example.comhost and a plain-httpissuer (token withheld); externalintrospectionUrl(ignored, token still sent); explicittruewith an external issuer (token sent). The operatorpkg/...andcontrollerspackages pass.test-integration/mcp-oidc-config(35/35) andtest-integration/mcp-server(103/103).go run github.com/golangci/golangci-lint/v2/cmd/[email protected] runon the touched packages: 0 issues).API Compatibility
v1beta1API. Only theuseClusterAuthfield docs change; no schema change.Does this introduce a user-facing change?
Yes.
useClusterAuthunset, the workload's service account token was sent to whatever discovery and JWKS hosts the config named.useClusterAuthunset, the token is sent only when the fetched URL (jwksUrl, or the issuer ifjwksUrlis unset) is on the in-cluster API server (https://kubernetes.default.svc[.cluster.local]).Upgrade impact:
jwksUrl: no change.useClusterAuth: trueis set explicitly.Special notes for reviewers
kubernetes.default.svc.would also acceptkubernetes.default.svc.example.com, which cluster DNS forwards upstream. The resolver cannot see the cluster domain, so custom domains use the explicit opt-in.inlineconfigs are unchanged. TheirjwksAuthTokenPathis a path the author sets explicitly.jwks_uri. The gate checks the configured URL only. A cross-host redirect, or ajwks_uriadvertised by discovery, would still carry the token. Both require the in-cluster API server to point elsewhere, so that's not a practical risk. Settingnetworking.SameHostRedirectPolicy()on the token-bearing client would close the redirect case and is left for a separate PR.JWKSAuthTokenPaththrough to vMCP and notes this trade-off as a follow-up. The two PRs touch different files and don't conflict.🤖 Generated with Claude Code