Repository navigation
fix(security): pass the passthrough token to helm, istio, argo and cilium, not only kubectl - #114
Open
braghettos wants to merge 1 commit into
Open
braghettos wants to merge 1 commit into
braghettos wants to merge 1 commit into
Conversation
…lium, not only kubectl With TOKEN_PASSTHROUGH=true only the kubectl tools in pkg/k8s sent the caller's bearer token. helm, istioctl, cilium and kubectl argo rollouts ran with the server's configured kubeconfig, which in a passthrough deployment has no usable credentials, so every helm call failed with "the server has asked for the client to provide credentials" while kubectl succeeded. The token resolution moves to one place, internal/mcp (next to Header): ResolvePassthroughToken(passthrough, headers) keeps the kubectl semantics exactly (passthrough on: the Authorization: Bearer token, or "Bearer token required when TOKEN_PASSTHROUGH is true"; passthrough off: no token), and PassthroughToken(headers) reads TOKEN_PASSTHROUGH the way pkg/k8s does. pkg/k8s now uses it, unchanged in behaviour. helm, istio, argo and cilium resolve the token from the request and pass it to CommandBuilder.WithToken, so the per-call kubeconfig from kagent-dev#107 carries it; it is never on argv, in logs or in error text. A call that reaches the cluster is refused without a token before any command runs. Calls that stay local need none: helm repo add/update, istioctl manifest generate and waypoint generate (YAML only), and the argo plugin version check. The per-call kubeconfig test helpers from pkg/k8s move to internal/commands/commandstest, with a shared suite every provider runs: token through the per-call kubeconfig, refusal without one, local tools without one, and passthrough off ignoring it. Kubescape builds a client-go client at startup and still uses the server's identity; it is not covered here. Signed-off-by: Diego Braga <diego.braga86@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TLFnUd6g7xhDXDvaho4rDW
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.
Problem
With
TOKEN_PASSTHROUGH=true, only the kubectl tools inpkg/k8ssend the caller's bearer token. helm, istioctl, cilium andkubectl argo rolloutsrun with the server's configured kubeconfig instead.In a passthrough deployment that kubeconfig has no usable credentials. On ours, every helm call failed with
Error: kubernetes cluster unreachable: the server has asked for the client to provide credentials: 7 of 7 in 30 hours, while 70 of 70 kubectl calls from the same agents succeeded. Where the server's kubeconfig does have credentials, those tools instead act as the server, not the caller, which is what passthrough exists to prevent.Change
internal/mcp/passthrough.go(next tomcp.Header).ResolvePassthroughToken(passthrough, headers)keeps the existing kubectl semantics exactly:Authorization: Bearertoken, orBearer token required when TOKEN_PASSTHROUGH is true;pkg/k8snow uses it, with no change in behaviour.CommandBuilder.WithToken, so the per-call kubeconfig from fix(security): pass the passthrough token via a per-call kubeconfig, never argv #107 carries it. It's never on argv, in logs or in error text. A cluster call without a token is refused before any command runs.helm repo add/update,istioctl manifest generateandwaypoint generate(they only render YAML; the tool never passes--cluster-specific), and the argo plugin version check.pkg/k8stointernal/commands/commandstest, with a shared suite that every provider runs:There are also table tests for the resolver. Removing
WithTokenfrom helm makes all four helm cluster tools fail the suite.Notes for review
tools.k8s.tokenPassthroughnow governs every CLI provider. I only updated its comment; a top-level name may be preferable.cilium clustermesh connect --destination-contextcan't work under passthrough: one token, one context. It didn't work before either.Checks
go build ./...,go vet ./...andgofmt -l: clean.make lint(golangci-lint v2.15.0): 0 issues.go test -tags=test ./pkg/... ./internal/... ./cmd/...: all pass.make e2e, which needs Kind) was not run locally.🤖 Generated with Claude Code
https://claude.ai/code/session_01TLFnUd6g7xhDXDvaho4rDW