Repository navigation
fix(k8s): a pod that does not call the Kubernetes API mounts no service account token - #2522
Conversation
Plan #1652 as the change 1652-no-unused-service-account-token. The change turns off the Kubernetes API token of each pod that does not call the API, adds a test that holds the rule for manifest pods and chart pods, and names Qdrant and the CoreDNS patch as exceptions with their reasons.
…e.py The local-path placement test held its own readers of the manifests and chart values under k8s/. The service account token test of #1652 needs the same readers, and a test imports only from tests/support/. The readers move to tests/support/k8s_tree.py, and the placement test uses them.
…not use Each pod that a manifest under k8s/ declares, or that a chart of an Argo CD Application makes, mounts no ServiceAccount token, or a role binds its ServiceAccount, or a named exception gives the reason. The table CHART_TOKENS names the pods of each chart, the value that turns the token off, and the role that the chart binds. A chart that the table does not name fails, and so does a stale exception. The tests fail before the fix: 15 manifest pods and 7 chart pods mount a token that no role binds (#1652).
…ce account token Most pods that the repository deploys mounted a token of their ServiceAccount that they did not use. An attacker in one of these containers got a valid cluster identity. The internet-facing cloudflared pods were among them (#1652). - The pod templates of cloudflared, gpu-feature-discovery, llm-gateway, portkey, valkey, valkey-runs and the nine Ollama tiers set automountServiceAccountToken: false. - The chart values turn the token off for Loki, Tempo, the OpenTelemetry collector, Alertmanager, and the Argo CD repo server and Redis. Loki chart 20.0.2 sets the pod field from defaults.automountServiceAccountToken, which wins over the field of the ServiceAccount, so the values set both keys. - Gitea gets its own ServiceAccount, which has no token. - CONST_K8S_SERVICE_ACCOUNT_TOKEN_EXCEPTIONS names Qdrant, whose chart 1.19.1 has no value for the field (qdrant/qdrant-helm#506), and the CoreDNS patch, whose Deployment and binding k3s makes. Each entry has its reason.
k8s/README.md, Service Account Tokens, gives the rule of #1652: a pod that does not call the Kubernetes API mounts no token. It names the values that turn the token off, the test that holds the rule, and the two named exceptions with their reasons.
… a token The token check read only the field automountServiceAccountToken of the pod and of its ServiceAccount. A pod can also mount a token as a volume: a projected serviceAccountToken source, or a Secret of type kubernetes.io/service-account-token. The API server accepts that token, and the field does not stop it. Thus a cloudflared pod with such a volume passed every token test. mounts_token() now reports a token when a volume of the pod holds one. The manifest reader gives it the token Secrets under k8s/ in the pod's namespace. The spec delta has a second requirement for how the check finds a token, and the design and k8s/README.md state the rule.
… it was read from The table of chart pods was keyed by the chart name only. A chart bump that moved the value that sets the pod field passed the test, and the pod got its token back. Loki did this in 20.0.2 (#1632), which moved the pod field from serviceAccount.automountServiceAccountToken to defaults.automountServiceAccountToken. Each key is now the chart and the version that helm template read. The test fails when an Application pins another version, or when an entry names a chart that no Application installs. tests/support/k8s_tree.py reads the pinned versions with pinned_charts(). The spec delta, the design, the proposal and k8s/README.md state the rule.
…tree readers do not see The readers of tests/support/k8s_tree.py read the files under k8s/ and the values files of the Applications. Argo CD also takes chart values from helm.values, helm.valuesObject and helm.parameters, and Kustomize changes objects with patches. Thus an inline value in an Application, or a JSON patch in a kustomization, could give a pod its token back, and every token test passed. A test now fails when an Application source has an option that the readers do not read, or when a kustomization has a key that changes objects or patches a workload, a ServiceAccount, a Secret, a binding or a claim. Literal cases pin both checks. The guard also keeps the claim check of tests/test_k8s_local_path_placement.py correct, because it uses the same readers. The design records why the readers do not render with kubectl kustomize.
…tests that read them CONST_K8S_SERVICE_ACCOUNT_TOKEN_EXCEPTIONS and CONST_K8S_CONTROL_PLANE_CLAIM_EXEMPTIONS were in src/devops_cli/config/constants.py, but only one test reads each. CONTRIBUTING.md puts a table beside its one reader, and moves a table out of config/ when a change edits its owner. docs/TESTING.md says that product code holds nothing for tests. The token exceptions are now _TOKEN_EXCEPTIONS in tests/invariants/test_k8s_manifests.py, and the claim exemptions are _CONTROL_PLANE_CLAIM_EXEMPTIONS in tests/test_k8s_local_path_placement.py. The other new tables of the token test also take the leading underscore. Criterion 4 of the issue asked for the table in constants.py; the design records why the change departs from it. The change has a MODIFIED delta of local-path-volume-placement, whose requirement named the old constant, and k8s/README.md names the new tables.
…d write the change in short sentences The proposal cited the pull request #2464 for the pinned Trivy scanner. An artifact names no pull request number, so the proposal now names tools.lock and the issue #2214. The known limit of the design gave dex as a pod that the table does not name, but the table names it. It also said that a switch change of an optional pod fails the test. It does not: dex and notifications have a role, and the commit server, the Loki canary and the gateway have no token by default. The limit now says that the checks read each of these pods when a values change turns it on. It also names the extra volumes of a chart pod, which the table does not read. The design no longer says that a test starts no program, because the test floor admits kubectl kustomize. The proposal, the design, the tasks, both spec deltas and the Service Account Tokens section of k8s/README.md now use sentences of 25 words or fewer (ASD-STE100).
Test results (local, on the branch after the rebase onto
|
🤖 I have created a release *beep* *boop* --- ## [0.11.0](v0.10.1...v0.11.0) (2026-10-28) ### Features * **monitoring:** the roadmap Service's identity refusals, failing and stalled jobs, restarts, and GitHub and model request volume raise alerts ([#2496](#2496)) ([0137f23](0137f23)), closes [#2472](#2472) * **service:** roadmap-service runs at one replica, and each model call in the cluster is sent at most two times ([#2500](#2500)) ([2d32dae](2d32dae)), closes [#2494](#2494) ### Bug Fixes * **cli:** every command reports a DevOpsCLIError through one exit seam ([#2502](#2502)) ([eadd55f](eadd55f)), closes [#2487](#2487) * **github:** pr monitor waits until the checks settle and names every blocker, and pr ready reads the merge-readiness verdict ([#2498](#2498)) ([43326ea](43326ea)) * **k8s:** a pod that does not call the Kubernetes API mounts no service account token ([#2522](#2522)) ([305d3ba](305d3ba)) * **k8s:** the cloudflared tunnel replicas prefer different nodes and keep one up through a drain ([#2499](#2499)) ([d4edaf6](d4edaf6)), closes [#1023](#1023) * **k8s:** the grafana, prometheus, argo cd and loki clients dial through the egress-checked factory, and their pre-flight address checks go ([#2497](#2497)) ([e7ca1d5](e7ca1d5)) * **monitoring:** the roadmap Service alerts count a series that starts in the hour, and a lane of a new pod can stall ([#2514](#2514)) ([c7692b2](c7692b2)), closes [#2505](#2505) * **review:** a review's scanners leave out the rules that never gave a valid finding here ([#2508](#2508)) ([fe953ac](fe953ac)) * **roadmap:** a refine round leaves an outside account issue to a person, and refine neutralizes comment openers, www links and cross-repository references ([#2507](#2507)) ([e6230dc](e6230dc)), closes [#2478](#2478) * **sandbox:** the metrics scrape and the whitelist NetworkPolicy resolve each host one time, through the egress check ([#2521](#2521)) ([7c01426](7c01426)) * **security:** the subprocess environment guard refuses the zsh and interpreter keys that make a child run code ([#2510](#2510)) ([459621a](459621a)) * **service:** a restart keeps the halt, the budget window and the failure ledger, and a rate limit or a suspended installation stops every worker ([#2515](#2515)) ([3630de1](3630de1)), closes [#2474](#2474) ### Code Refactoring * **config:** settings resolve in one declared order through pydantic-settings sources ([#2518](#2518)) ([6a5447a](6a5447a)), closes [#2445](#2445) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Most pods that the repository deploys mounted a Kubernetes API token that they did not use. An attacker in one of these containers got a valid cluster identity. The internet-facing
cloudflaredpods were among them, and their NetworkPolicy allows the API server. A later RoleBinding to thedefaultServiceAccount of a namespace would give its rights to each pod of that namespace, with no warning.cloudflared,gpu-feature-discovery,llm-gateway,portkey,valkey,valkey-runsand the nine Ollama tiers setautomountServiceAccountToken: false.tests/invariants/test_k8s_manifests.pyreads each pod that a manifest underk8s/declares, and each pod that a chart of an Argo CD Application makes. Each pod mounts no token, or a role binds its ServiceAccount, or the table_TOKEN_EXCEPTIONSnames it with a reason. Qdrant is an exception, because its chart has no value for the token (qdrant/qdrant-helm#506). The CoreDNS patch is an exception, because k3s owns its Deployment.k8s/tree move intotests/support/k8s_tree.py, andtests/test_k8s_local_path_placement.pyuses them too. Its table of exemptions moves fromsrc/devops_cli/config/constants.pyinto that test, its one reader.k8s/README.md(Service Account Tokens) documents the rule and the exceptions.Trivy and kube-linter, which the gate runs, have no check for a pod that does not set the token field. Kubescape has one, but the repository does not pin it, and it does not render the charts of the Applications.
Closes #1652
Change:
openspec/changes/archive/2026-10-28-1652-no-unused-service-account-token/