Skip to content

fix(k8s): load only the needed Secret keys in runner Jobs #6518

Description

@dan-petty

Problem

The runner Job template loads the whole devops-cli Secret into the container environment with envFrom (k8s/devops/cronjob-runner.yaml:61-63). That gives every implement and fix-checks pod the GitHub App private key, the gateway key and every other key of the Secret (for example the Valkey, MCP, Mattermost and Qdrant tokens), although a Job needs only some of them. The stage Job already names single keys with secretKeyRef (k8s/devops/cronjob-stage.yaml:103-110).

The next experiment gives the Job agents a real shell (owner, 2026-11-20). Each key in the pod environment is then one command away from the agent, so a Job must hold only the keys it needs.

Change

  • cronjob-runner.yaml: replace envFrom: secretRef devops-cli with one secretKeyRef for each key that the implement and fix-checks Jobs read. Find the readers in src (settings of the runner path) and name each key and its reader in the PR.
  • Keep the keys that the Job needs; drop the rest. No new Secret and no new key name in this item, so nothing must be pushed to the cluster before the merge.
  • Follow-ups, not in this item: a per-Job gateway key with a spend limit (needs a key the owner creates), and the split of the agent container from the step that holds the App key (feat(roadmap): run the implement agent shell in a real sandbox #2695).

Proof

  • kubectl kustomize of the tree renders the runner Job with only the named keys.
  • An implement Job and a fix-checks Job run green on the cluster after the merge (Argo CD sync), with the result lines as evidence.

Proposed design

Problem statement

Each implement and fix-checks pod gets every key of Secret devops-cli through envFrom (k8s/devops/cronjob-runner.yaml:61-63). The pod then holds the App private key, the gateway key and tokens that it does not read. The change gives the runner Job only the keys that it reads, each with secretKeyRef, as k8s/devops/cronjob-stage.yaml:103-110 does. The same pull request changes policy roadmap-service-jobs, which refuses a runner Job with valueFrom in env. It updates docs/CLUSTER.md lines 5, 69 and 71.

Acceptance criteria

Requirement: Runner Job names each Secret key

The runner CronJob SHALL give each Secret key of Secret devops-cli to the container with secretKeyRef, each in the variable of the key name, and SHALL NOT use envFrom.

Scenario: The rendered runner Job holds no envFrom

  • WHEN uv run devops ci --check --only k8s runs the gate check of the runner Job on k8s/devops/cronjob-runner.yaml
  • THEN the check passes, and the rendered runner Job has no envFrom and one secretKeyRef entry for each key of the runner key constant

Requirement: One constant holds the runner keys

The runner Secret keys SHALL come from one constant in the code, as the stage Job keys do, so that the manifest and the policy read one list.

Scenario: A key outside the constant fails the check

  • WHEN the rendered runner Job names a secretKeyRef key that the runner key constant does not hold
  • THEN the gate check of the runner Job reports the key, and uv run devops ci --check --only k8s fails

Requirement: The policy admits only the runner keys

Policy roadmap-service-jobs SHALL admit a runner Job that names only the runner keys in secretKeyRef and SHALL refuse a runner Job with envFrom or with another key.

Scenario: The policy refuses an extra key

  • WHEN uv run devops ci --check --only k8s runs tests/gate/k8s_checks/job_admission_policy.py against the Job that CronJob devops-cli-runner makes
  • THEN the policy admits the Job, and refuses a copy with envFrom or with a key outside the runner key constant

Requirement: Each runner key is in the Secret generator table

Each key that the runner Job names SHALL be a key that devops k8s push-secrets writes to Secret devops-cli.

Scenario: A key outside the generator table fails the check

  • WHEN uv run devops ci --check --only k8s runs the key-reference check of tests/k8s/test_cluster_secret_key_refs.py
  • THEN the check passes, and it fails when the runner Job names a key that the generator table of src/devops_cli/k8s/cluster_secrets.py does not hold

Requirement: An implement Job and a fix-checks Job run green

An implement Job and a fix-checks Job MUST run green after Argo CD syncs the changed manifests.

Scenario: The next runner Jobs of each kind finish

  • WHEN the next implement Job and the next fix-checks Job run on the cluster after the merge and the Argo CD sync
  • THEN each Job ends green with its result line, and no pod stops at CreateContainerConfigError or at a policy refusal

Existing Tool Considered

No alternatives check has run. Kubernetes covers the need with secretKeyRef, and the open, maintained kubectl kustomize renders the Job. The project builds no code: the change edits k8s/devops/cronjob-runner.yaml, the policy and one constant. uv run devops ci --check --only k8s proves the manifest and the policy, and the API server enforces the policy.

Key questions

  • Which keys of Secret devops-cli does a runner Job read?: DEVOPS_CLI_SERVICE_GITHUB_APP_PRIVATE_KEY mints the installation token and DEVOPS_CLI_AI_API_KEY pays the gateway; the stage Job takes both. The PR names the reader of each key in src. Every other key goes, such as the Valkey, Mattermost and Qdrant tokens. [sources: k8s/devops/cronjob-stage.yaml, docs/CLUSTER.md:83, src/devops_cli/k8s/cluster_secrets.py]
  • Does the runner Job keep DEVOPS_CLI_MCP_IMPLEMENT_TOKEN?: It keeps the key only when the implement MCP client is on. The stage Job leaves its MCP key out because roadmap.stage.mcp is off, and the change that turns a client on adds its key. (best practice) [sources: SECURITY.md:64, docs/CLUSTER.md:83, k8s/devops/cronjob-stage.yaml]
    • Chosen: Keep the key only with the MCP client on. The pod then holds no token that its settings do not read.
    • Rejected: Always keep the key. An unused token stays one command away from the agent.
    • Rejected: Always drop the key. The MCP client of the implement job then fails on a missing token.
  • How does each key reach the container?: With one secretKeyRef entry in env for each key, in the variable that has the name of the key, and with no envFrom. The stage Job uses this shape. (best practice) [sources: k8s/devops/cronjob-stage.yaml, docs/CLUSTER.md:83, k8s/devops/cronjob-runner.yaml]
    • Chosen: One secretKeyRef for each key, in the variable of the key name. The stage Job does this, and the policy already admits this shape for a stage Job.
    • Rejected: Keep envFrom and add the keys. envFrom still gives the agent every other key of the Secret.
    • Rejected: Mount the Secret as a volume. The policy admits only the volumes tmp, home and config, and the agent can read a mounted file.
  • Where does the runner key list live?: In one constant in the code, as CONST_ROADMAP_STAGE_JOB_SECRET_KEYS does for the stage Job. A gate check holds the rendered Job and the policy to that constant. (best practice) [sources: docs/CLUSTER.md:83, docs/CLUSTER.md:90, tests/gate/k8s_checks/job_admission_policy.py]
    • Chosen: One constant in the code, read by the manifest check and the policy check. The stage Job keeps its keys in CONST_ROADMAP_STAGE_JOB_SECRET_KEYS, and a check holds the manifest and the policy to it.
    • Rejected: The key names in the manifest only. The policy check and the manifest can then disagree.
    • Rejected: The key names in the policy only. The same drift, and the manifest holds no single list.
  • Must the admission policy change in the same pull request?: Yes. Policy roadmap-service-jobs refuses a runner Job that has a valueFrom in env, with failurePolicy: Fail, so the Job never starts. The pull request admits the named keys in secretKeyRef, refuses envFrom, and keeps the other pins, such as the worker count. (best practice) [sources: k8s/devops/roadmap-service/admissionpolicy.yaml, docs/CLUSTER.md:71, tests/gate/k8s_checks/job_admission_policy.py]
    • Chosen: Update the policy and its gate check in this pull request. The policy refuses a runner Job with valueFrom in env, so the Job would not start.
    • Rejected: Change the template only. The Service cannot create the Job, and the implement job stops.
    • Rejected: Admit any secretKeyRef in the policy. This drops the pin, and a Job could then name any key.
  • Which documents state the envFrom that this change replaces?: docs/CLUSTER.md line 5 (each Job reads its credentials through envFrom), line 69 (the runner template uses Secret devops-cli through envFrom) and line 71 (the policy admits only envFrom and no valueFrom). The pull request updates all three. [sources: docs/CLUSTER.md:5, docs/CLUSTER.md:69, docs/CLUSTER.md:71]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/bug
    scope/k8s
    source/agent
    status/new
    effort/low
    value/high
    on Nov 20, 2026
  2. dan-petty commented on Nov 20, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 20, 2026
  4. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    Next step: the alternatives check records a verdict. See the section Proposed design of the body.

  5. added
    status/in-progress
    and removed
    status/new
    on Nov 20, 2026
  6. added
    status/in-review
    and removed
    status/in-progress
    on Nov 20, 2026
  7. removed
    status/in-review
    on Nov 20, 2026
  8. added a commit that references this issue on Nov 20, 2026
  9. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-20 17:44 UTC

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/lowpriority/p2-mediumscope/k8ssource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions