Skip to content

Read-only mode: refuse proxy requests to pods, services and nodes - #7

Merged
pierreneter merged 1 commit into
p10node:mainfrom
junior:readonly-proxy
Oct 7, 2026
Merged

pierreneter merged 1 commit into
p10node:mainfrom
junior:readonly-proxy

Conversation

@junior

@junior junior commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Follow-up 2 from the review of #5.

A GET through .../pods/<name>/proxy/..., .../services/<name>/proxy/... or .../nodes/<name>/proxy/... is passed on to whatever listens behind it. Behind a node proxy is the kubelet, whose own API includes exec, so nothing sent through a proxy is known to only read. The guard only knew exec, attach and portforward, which always end the path; proxy is followed by the path it forwards, so it never matched.

streamSubresource now also looks for proxy anywhere in the path, anchored on namespaces for pods and services and on v1 for nodes. Objects that are merely named "proxy" stay readable, and so does an API server served under a path prefix. The refusal names what it refused ("pod exec", "node proxy"). k10s itself never sends these requests, so nothing visible changes.

Tests: new rows in TestCheckReadOnlyAllowsOnlyReads, and TestReadOnlyClientProxiesNothing drives client-go's own proxy helpers (pod and service ProxyGet, a node proxy GET) against the recording server and checks that none of them reaches it.

Checked with gofmt, go vet ./... and go test ./... on Go 1.26.8.

A GET through .../pods/<name>/proxy/..., .../services/<name>/proxy/...
or .../nodes/<name>/proxy/... is passed on to whatever listens behind
it, and behind a node proxy is the kubelet, whose own API includes
exec. The read-only transport let those through: it only knew the
stream subresources, which always end the path.

proxy is followed by the path it forwards, so the guard now looks for
it anywhere in the path, anchored on "namespaces" for pods and
services and on "v1" for nodes, which keeps objects that are merely
named "proxy" readable. k10s never sends these requests itself.

Suggested in the review of p10node#5.
@pierreneter

Copy link
Copy Markdown
Member

Reviewed, approving.

Verified locally on Go 1.27.1: gofmt, go vet ./... and go test ./... pass, and the binary builds for linux/amd64, darwin/arm64 and windows/amd64. The branch predates the #6 merge, but it merges into current main cleanly and the merged tree is green too, so no rebase needed.

I also ran the new test rows and TestReadOnlyClientProxiesNothing against main's readonly.go: all six proxy paths slip through and all three client-go proxy requests reach the recording server, so the tests pin exactly the hole this closes.

The anchoring is right. Pod and service proxy need namespaces four segments before proxy, node proxy needs v1 three before, and the loop starting at index 3 keeps every lookback in range. The prefix-path and "object named proxy" rows cover the two ways a naive strings.Contains would have gone wrong. Returning "pod exec" / "node proxy" from one place instead of prefixing in checkReadOnly is cleaner than what was there.

Merging. That closes follow-up 2 from #5.

@pierreneter
pierreneter merged commit 514bdbc into p10node:main Oct 7, 2026
@junior
junior deleted the readonly-proxy branch October 8, 2026 00:22
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