Skip to content

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

Closed

Description

@dan-petty

Friction

Most repo-owned workloads mount a Kubernetes API token they never use. Only the devops namespace applies the README's "holds no Kubernetes API token" principle. Today the tokens grant only discovery, but an attacker in any of these containers (including the internet-facing cloudflared pods, whose NetworkPolicy allows the API server on 6443) gets a valid cluster identity for free, and any future RoleBinding to a namespace's default ServiceAccount would silently reach all of them.

Evidence

Live, read-only, 2026-10-17 (main = 3dd7fa6):

  • A kube-api-access volume, with automountServiceAccountToken unset on the pod, on cloudflared x2, registry, llm-gateway, portkey, valkey, valkey-runs, ollama-48gib, ollama-48gib-slow and ollama-64gib (SA default), gpu-feature-discovery x3 (SA default in default), qdrant-0 (SA qdrant), loki-0 and loki-canary x3 (the chart sets automount true).
  • SAs llm/default, llm/qdrant, cloudflared/default, registry/default and default/default leave automount unset; no RoleBinding or ClusterRoleBinding names any of them.
  • kubectl auth can-i --list --as=system:serviceaccount:<ns>:<sa> for cloudflared:default, llm:default, registry:default, default:default, llm:qdrant and logging:loki-canary shows only self-reviews and discovery GETs.
  • None needs the API: gpu-feature-discovery v0.16.2 runs in file-output mode (no USE_NODE_FEATURE_API); Loki's rules sidecar is disabled (k8s/logging/loki-values.yaml:87-89) and loki-clusterrole has no rules.
  • Opt-outs already live: devops (SA and pods), llm/open-webui-0, monitoring/dcgm-exporter, the k8s-monitoring node-exporter pods.

Repo:

Remedy

  1. Test first, next to test_service_account_mounts_no_token in tests/test_k8s_devops_runtime.py: parse every pod-template manifest under k8s/ and the chart values the stacks install, and assert each workload sets automountServiceAccountToken: false or names a ServiceAccount that a RoleBinding or ClusterRoleBinding in the repo binds. Named exceptions live in src/devops_cli/config/constants.py with a reason.
  2. Add automountServiceAccountToken: false to the pod templates listed above.
  3. k8s/logging/loki-values.yaml: serviceAccount.automountServiceAccountToken: false (covers loki, loki-0 and loki-canary).
  4. Qdrant: list it as a named exception with the reason (no chart option), and propose serviceAccount.automountServiceAccountToken upstream to qdrant-helm; drop the exception when a release ships it. No home-grown post-render step for this alone.
  5. Deployed by the Argo CD Applications and deploy-stack that own each file.
    Verification after the sync: kubectl get pods -A -o json shows no kube-api-access volume on these pods, and each workload stays Ready.

Priority: P3. Severity low: defence in depth; today's tokens grant only discovery.

Proposed design

Problem statement

Most repo-owned workloads mount a Kubernetes API service account token they never use. An attacker in any of these containers gets a valid cluster identity for free. Today the tokens grant only discovery, but any future RoleBinding to a namespace's default ServiceAccount would silently reach all of them. The fix adds automountServiceAccountToken: false to every pod template that does not need the API, adds a test that enforces this, and records the one exception (Qdrant) that the chart cannot fix.

Acceptance criteria

  • Criterion 1: A test in tests/test_k8s_devops_runtime.py parses every pod-template manifest under k8s/ and asserts each workload sets automountServiceAccountToken: false or names a ServiceAccount bound by a RoleBinding or ClusterRoleBinding in the repo.
    Verification: Run pytest tests/test_k8s_devops_runtime.py::test_service_account_mounts_no_token and confirm it passes. Remove automountServiceAccountToken: false from one pod template and confirm the test fails.
  • Criterion 2: automountServiceAccountToken: false is present in the pod spec of cloudflared, registry, llm-gateway, portkey, valkey, valkey-runs, all ollama profile DaemonSets, and gpu-feature-discovery.
    Verification: grep -r 'automountServiceAccountToken: false' k8s/cloudflared/deployment.yaml k8s/registry/deployment.yaml k8s/llm/gateway/deployment.yaml k8s/llm/portkey/deployment.yaml k8s/llm/valkey.yaml k8s/llm/valkey-runs.yaml k8s/llm/profiles/ollama-profiles.yaml k8s/gpu-feature-discovery/daemonset.yaml returns a match in each file.
  • Criterion 3: k8s/logging/loki-values.yaml sets serviceAccount.automountServiceAccountToken: false, covering loki, loki-0 and loki-canary.
    Verification: grep 'automountServiceAccountToken' k8s/logging/loki-values.yaml shows the value false.
  • Criterion 4: Qdrant is listed as a named exception in src/devops_cli/config/constants.py with the reason that the chart exposes no automount option.
    Verification: grep -i 'qdrant' src/devops_cli/config/constants.py shows the exception entry with a reason string.
  • Criterion 5: After Argo CD sync, no affected pod mounts a kube-api-access volume and each workload stays Ready.
    Verification: Run kubectl get pods -A -o json and confirm no pod in cloudflared, registry, llm, default, or logging namespaces has a volume named kube-api-access. Run kubectl get pods -A and confirm all affected pods are Ready.

Key questions

  • Where does the enforcement test live and what is its name?: It lives in tests/test_k8s_devops_runtime.py, next to the existing test_service_account_mounts_no_token function at line 58. [sources: tests/test_k8s_devops_runtime.py:58]
  • Where are named exceptions stored?: In src/devops_cli/config/constants.py, each with a reason string. [sources: src/devops_cli/config/constants.py]
  • Does the Qdrant Helm chart (1.19.1 or 1.19.2) expose a serviceAccount.automountServiceAccountToken value?: No. The chart values.yaml line 234 offers only annotations. The body records this as the reason for the named exception. [sources: k8s/llm/values-qdrant.yaml]
  • Does gpu-feature-discovery v0.16.2 need the Kubernetes API?: No. It runs in file-output mode with no USE_NODE_FEATURE_API, so it does not call the API. [sources: k8s/gpu-feature-discovery/daemonset.yaml]
  • Does Loki need the Kubernetes API for its rules sidecar?: No. The rules sidecar is disabled in k8s/logging/loki-values.yaml lines 87-89, and loki-clusterrole has no rules. [sources: k8s/logging/loki-values.yaml:87]
  • Should a home-grown post-render step be added for Qdrant?: No. The body states: no home-grown post-render step for this alone. Qdrant is a named exception until the chart ships the option. (proposed)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/security
    on Oct 18, 2026
  2. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Type: type/security. The candidate addresses a security concern by preventing unnecessary Kubernetes API token mounting.
    • Priority: P3-Low. The issue is described as low severity with defense-in-depth benefits.
    • Value: High. Improves cluster security by reducing attack surface through proper service account token handling.
    • Effort: Medium. Requires updating multiple deployment files and potentially chart configurations, plus adding tests.
  3. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at bb46660 (see proposed design in issue body).

  4. added
    priority/p3-low
    status/ready
    effort/medium
    value/high
    on Oct 28, 2026
  5. removed
    status/ready
    on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p3-lowsource/agenttype/securityvalue/high

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions