Skip to content

fix(k8s): a pod that does not call the Kubernetes API mounts no service account token - #2522

Merged
dan-petty merged 11 commits into
mainfrom
fix/1652-no-unused-service-account-token
Oct 28, 2026
Merged

dan-petty merged 11 commits into
mainfrom
fix/1652-no-unused-service-account-token

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

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 cloudflared pods were among them, and their NetworkPolicy allows the API server. A later RoleBinding to the default ServiceAccount of a namespace would give its rights to each pod of that namespace, with no warning.

  • 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, the Argo CD repo server and Redis, and Gitea. Gitea uses the ServiceAccount of its chart, which has no token.
  • A test in tests/invariants/test_k8s_manifests.py reads each pod that a manifest under k8s/ 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_EXCEPTIONS names 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.
  • The test fails on a chart or a chart version that it does not know, and on a stale exception. It also fails on an Application value or a kustomization patch that its readers do not see.
  • The readers of the k8s/ tree move into tests/support/k8s_tree.py, and tests/test_k8s_local_path_placement.py uses them too. Its table of exemptions moves from src/devops_cli/config/constants.py into 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/

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).
@dan-petty dan-petty added scope/k8s Kubernetes commands, Helm charts, pods, services, and policies type/security Type security: a vulnerability or a leak labels Oct 28, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Test results (local, on the branch after the rebase onto origin/main at 6a5447a5)

Targeted tests. uv run devops ci test tests/invariants/test_k8s_manifests.py tests/test_k8s_local_path_placement.py tests/test_k8s.py tests/test_k8s_gitea.py tests/test_k8s_tempo.py tests/test_k8s_argo_workflows.py tests/test_k8s_valkey_stack.py tests/test_k8s_llm_gateway.py tests/test_k8s_gpu_placement.py: 259 passed in 31.22 s.

Documents. uv run devops docs check: all documentation files are up to date.

OpenSpec. uv run devops openspec archive 1652-no-unused-service-account-token: the change is archived, and every spec and change validates.

Fail-to-pass. uv run devops ci fail-to-pass --base origin/main: 3 tests failed on the base, and 40 passed. Each of the 3 tests fails with an AssertionError that lists the pods with a token. All 43 tests pass on the head.

An earlier run on the branch gave 4 failures on the base. Three of them were ImportErrors, because the exception table was then a constant in src/devops_cli/config/constants.py. The table now is _TOKEN_EXCEPTIONS in the test, so the run above replaces that run.

Fail-to-pass output
  passed on base: tests.invariants.test_k8s_manifests::test_an_application_source_option_that_the_readers_do_not_see_is_named[values]
  passed on base: tests.invariants.test_k8s_manifests::test_a_kustomization_change_that_the_readers_do_not_see_is_named[target-no-kind]
  passed on base: tests.invariants.test_k8s_manifests::test_a_token_volume_mounts_a_token_when_the_field_is_off[other-secret]
  passed on base: tests.invariants.test_k8s_manifests::test_a_kustomization_change_that_the_readers_do_not_see_is_named[strategic-merge]
  passed on base: tests.invariants.test_k8s_manifests::test_a_kustomization_change_that_the_readers_do_not_see_is_named[merge-deployment]
  passed on base: tests.invariants.test_k8s_manifests::test_the_pod_field_wins_over_the_service_account_field[no-account]
  passed on base: tests.invariants.test_k8s_manifests::test_an_application_source_option_that_the_readers_do_not_see_is_named[value-files]
  passed on base: tests.invariants.test_k8s_manifests::test_the_readers_see_each_value_and_patch_that_reaches_a_checked_object
  passed on base: tests.invariants.test_k8s_manifests::test_the_pod_field_wins_over_the_service_account_field[pod-off-wins]
  passed on base: tests.invariants.test_k8s_manifests::test_an_application_source_option_that_the_readers_do_not_see_is_named[path-kustomize]
  failed on base: tests.invariants.test_k8s_manifests::test_every_chart_pod_with_a_token_has_a_role_or_a_named_exception (AssertionError: assert ['k8s/argocd/...l:tempo', ...] == [])
  passed on base: tests.invariants.test_k8s_manifests::test_a_token_volume_mounts_a_token_when_the_field_is_off[empty-dir]
  passed on base: tests.invariants.test_k8s_manifests::test_the_pod_field_wins_over_the_service_account_field[account-unset]
  passed on base: tests.invariants.test_k8s_manifests::test_the_gateway_keeps_a_streamed_chat_reply_open_under_the_edge_timeout
  passed on base: tests.invariants.test_k8s_manifests::test_a_token_volume_mounts_a_token_when_the_field_is_off[projected-token-secret]
  passed on base: tests.invariants.test_k8s_manifests::test_every_ollama_tier_runs_one_release_that_serves_multimodal_embedding_models
  passed on base: tests.invariants.test_k8s_manifests::test_a_kustomization_change_that_the_readers_do_not_see_is_named[delete-ingress]
  passed on base: tests.invariants.test_k8s_manifests::test_a_token_volume_mounts_a_token_when_the_field_is_off[projected-token]
  passed on base: tests.invariants.test_k8s_manifests::test_the_chart_table_names_each_chart_at_the_version_that_an_application_pins
  passed on base: tests.invariants.test_k8s_manifests::test_a_kustomization_change_that_the_readers_do_not_see_is_named[target-service-account]
  passed on base: tests.invariants.test_k8s_manifests::test_an_application_source_option_that_the_readers_do_not_see_is_named[parameters]
  passed on base: tests.invariants.test_k8s_manifests::test_an_application_source_option_that_the_readers_do_not_see_is_named[values-object]
  failed on base: tests.invariants.test_k8s_manifests::test_every_manifest_pod_with_a_token_has_a_role_or_a_named_exception (AssertionError: assert ['k8s/cloudfl...a-16gib', ...] == [])
  passed on base: tests.invariants.test_k8s_manifests::test_a_kustomization_change_that_the_readers_do_not_see_is_named[replacements]
  failed on base: tests.invariants.test_k8s_manifests::test_the_pods_that_do_not_call_the_api_mount_no_token (AssertionError: assert ['k8s/argocd/...gateway', ...] == [])
  passed on base: tests.invariants.test_k8s_manifests::test_an_application_source_option_that_the_readers_do_not_see_is_named[path-helm]
  passed on base: tests.invariants.test_k8s_manifests::test_the_pod_field_wins_over_the_service_account_field[pod-on-wins]
  passed on base: tests.invariants.test_k8s_manifests::test_an_application_source_option_that_the_readers_do_not_see_is_named[path]
  passed on base: tests.invariants.test_k8s_manifests::test_the_pod_field_wins_over_the_service_account_field[pod-off]
  passed on base: tests.invariants.test_k8s_manifests::test_a_token_volume_mounts_a_token_when_the_field_is_off[token-secret]
  passed on base: tests.invariants.test_k8s_manifests::test_every_exception_names_a_pod_with_a_token_that_no_role_binds
  passed on base: tests.invariants.test_k8s_manifests::test_loki_runs_the_grafana_community_chart_whose_loki_fixes_cve_2026_21729
  passed on base: tests.invariants.test_k8s_manifests::test_the_pod_field_wins_over_the_service_account_field[account-off]
  passed on base: tests.invariants.test_k8s_manifests::test_a_token_volume_mounts_a_token_when_the_field_is_off[projected-config-map]
  passed on base: tests.test_k8s_local_path_placement::test_every_exemption_names_a_pod_on_a_claim_that_stays_on_any_node
  passed on base: tests.test_k8s_local_path_placement::test_every_manifest_pod_on_a_claim_keeps_off_the_control_plane_node
  passed on base: tests.test_k8s_local_path_placement::test_the_placement_check_needs_the_term_in_every_required_term[second-term-admits]
  passed on base: tests.test_k8s_local_path_placement::test_every_chart_pod_on_a_claim_keeps_off_the_control_plane_node
  passed on base: tests.test_k8s_local_path_placement::test_the_placement_check_needs_the_term_in_every_required_term[required]
  passed on base: tests.test_k8s_local_path_placement::test_the_placement_check_needs_the_term_in_every_required_term[pod-anti-affinity]
  passed on base: tests.test_k8s_local_path_placement::test_every_chart_an_application_installs_states_its_claims
  passed on base: tests.test_k8s_local_path_placement::test_the_placement_check_needs_the_term_in_every_required_term[preferred-only]
  passed on base: tests.test_k8s_local_path_placement::test_the_placement_check_needs_the_term_in_every_required_term[none]
3 failed on base (3 failed and 40 passed in tests/invariants/test_k8s_manifests.py, tests/test_k8s_local_path_placement.py; 0 errored).
Elapsed: 9.25s

Steps for a person after the merge

  • After Argo CD syncs the merge, kubectl get pods -A -o json shows no kube-api-access-* volume on the pods that lost their token: cloudflared, gpu-feature-discovery, llm-gateway, portkey, valkey, valkey-runs, the Ollama tiers, loki-0, tempo-0, prometheus-alertmanager-0, the OpenTelemetry collector, argocd-repo-server, argocd-redis and gitea. kubectl get pods -A shows each of them Ready.

@dan-petty
dan-petty marked this pull request as ready for review October 28, 2026 19:53
@dan-petty
dan-petty merged commit 305d3ba into main Oct 28, 2026
17 of 19 checks passed
@dan-petty
dan-petty deleted the fix/1652-no-unused-service-account-token branch October 28, 2026 19:53
dan-petty pushed a commit that referenced this pull request Oct 28, 2026
🤖 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/k8s Kubernetes commands, Helm charts, pods, services, and policies type/security Type security: a vulnerability or a leak

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(k8s): workloads that never call the kubernetes api mount no service account token

1 participant