Kubernetes
kubectl in the agent container works against a real cluster, while the cluster's address, its CA, the client certificate and its private key stay out of the sandbox. The agent's kubeconfig holds markers and working stand-ins; the proxy puts the real values back on the way to the API server.
Setting it up#
Mount the kubeconfig as a credential file and allow the API server:
shell
redactproxy launch -workspace . -policy-file policy.json \
-mount ~/.kube/sandbox-config:/home/node/.kube/configpolicy.json
{"allow": ["kubernetes.docker.internal:6443"]}- kubectl must be in the agent image. The default base image doesn't have it; build one that does and pass it with
-agent-base. - The allowlist names the real host and port; the agent only ever sees the marker.
- The server must be reachable from the proxy container. For Docker Desktop's cluster that is
https://kubernetes.docker.internal:6443, not the127.0.0.1its kubeconfig names. A kind cluster on127.0.0.1:<port>is not reachable. - Mount a kubeconfig with only the contexts the agent should use: every cluster in it gets stand-ins and is usable from the sandbox.
- The mount is read-only, so
kubectl config use-contextandset-contextfail. Use--contextand-n, or copy it to a writable file and pointKUBECONFIGthere.
kubectl auth whoami in the sandbox shows the identity the cluster sees: the real one.
What the agent's kubeconfig holds#
| Field | In the sandbox |
|---|---|
server | https://<marker>:6443: a hostname or IP marker, scheme and port kept |
certificate-authority-data | The proxy CA (stand-in) |
client-certificate-data, client-key-data | A dummy pair signed by the proxy CA (stand-in) |
token | One marker for the whole token |
Base64 values stay base64, so kubectl loads the file without complaint.
How a request reaches the cluster#
- kubectl resolves the server's marker. The sinkhole answers with a synthetic address, and the gateway maps it back to the real host.
- The proxy terminates kubectl's TLS with a certificate for the marker name, signed by the proxy CA, which kubectl trusts through its kubeconfig.
- kubectl presents the dummy client certificate. The proxy presents the real certificate and key in its own handshake with the API server, and verifies the server against the real CA.
- A token's marker in
Authorization: Beareris replaced by the real token, like any marker in a credential header.
What the agent sees#
- Secrets. A Secret from the API server never brings its data into the sandbox: each data value becomes base64 of a marker, so kubectl and other clients still decode it. The last-applied annotation stays JSON with its data redacted. The output of
get,describe,createoreditof secrets, and ofhelm get values|manifest|allandhelm template, is scanned under the stricter profile on its way to the model. - Environment values. In a pod or deployment spec, a value whose name is a secret's (
DB_PASSWORD,API_TOKEN) is redacted, in the API's JSON and in kubectl's YAML. - Addresses and names in the cluster's answers (node addresses,
*.svc.cluster.local) become markers. Short object names don't. - Protobuf. kubectl asks for protobuf in some commands; the proxy asks the API server for JSON, which it can redact.
- Watches and followed logs (
get -w,rollout status,wait,logs -f) stream as they come, each line redacted like a whole response.
What was tested#
- Tested with a live cluster (Docker Desktop, client-certificate auth):
get nodes,get pods -A,auth whoami. - Through the proxy in tests: watches and followed logs, Secret reads, Tables, large Secret lists, a Secret read and applied back,
describe's protobuf fallback, token kubeconfigs, server-side apply bodies. - Not yet run against a live cluster: writes (
apply,create,patch,delete,scale). They go through the same inspected path.
Known limits#
- No
exec,attach,port-forward,cp,run -itordebug. They upgrade the connection to a two-way stream the proxy can't redact, and the proxy refuses upgrades. - No exec credential plugins (EKS, GKE, kubelogin): request signing and identity brokers are not supported.
- A certificate and key in separate files (minikube's layout) get no stand-in; kubectl can't load the markers.
- A client certificate from an intermediate CA, or a server that sends no list of accepted CAs, doesn't get the real certificate.
- Two clusters with the same CA name (every kubeadm CA is
CN=kubernetes) can't be told apart when both are allowlisted. tls-server-namein a kubeconfig is refused.- Applying a scrubbed manifest stores the real data: a marker inside base64 in a request is put back like one in clear. A manifest holding a value the store knows in real form is blocked and queued for approval.
kubectl create secretsends protobuf, so it can't carry markers. A client that asks for protobuf alone gets it, scanned only for known values.- Helm's releases are Secrets helm must read back, so their data reaches the sandbox;
helm getoutput is redacted on its way to the model. - A Secret or SecretList over 64 MiB is cut off rather than passed through unredacted; page with
--chunk-size. - Paranoid mode doesn't bind a kubeconfig token to its API server: its first use waits for approval.