Skip to content

feat(k8s): give each job a virtual key with a spend limit #7075

Backlog

Description

@devops-cli-service

Split from #5498.

ProblemnA runner or stage pod holds DEVOPS_CLI_AI_API_KEY. src/devops_cli/k8s/cluster_secrets.py can adopt that key from key master-key of Secret llm/llm-gateway-secrets (adopt_from). If the key came from there, each pod holds the master key of the gateway.nnn## Why deferrednA person must create a virtual key for each Job and set its spend limit. No Secret value was read, so the values were not compared. #5498 narrows the GitHub token only.nnn## Acceptance criterian- uv run devops ci --check --only k8s passes and reports no Job that adopts key master-key of Secret llm/llm-gateway-secrets.n- A gate check fails when a Job template or cluster_secrets.py adopts the gateway master key.n- A live check shows that a runner Job calls the gateway with a virtual key that has a spend limit. The issue comment gives the key name and the limit, with no key value.

Proposed design

Problem statement

A runner or stage pod reads DEVOPS_CLI_AI_API_KEY from Secret devops/devops-cli. The table in src/devops_cli/k8s/cluster_secrets.py adopts that value from master-key of Secret llm/llm-gateway-secrets. Each pod then holds the gateway master key, so no spend limit applies. The change reads a LiteLLM virtual key with a spend limit from the keyring. A gate fails when a Job template or the table adopts the master key.

Acceptance criteria

Requirement: The job key is a keyring virtual key

The DEVOPS_CLI_AI_API_KEY entry of Secret devops/devops-cli SHALL read a LiteLLM virtual key from the keyring and MUST NOT adopt master-key of Secret llm/llm-gateway-secrets.

Scenario: The table has no master-key adoption

  • WHEN the unit test loads CLUSTER_SECRETS from src/devops_cli/k8s/cluster_secrets.py
  • THEN no entry has an adopt_from that names Secret llm-gateway-secrets key master-key, and the DEVOPS_CLI_AI_API_KEY entry reads KeyringSource.for_credential("runner.llm_key").

Requirement: The k8s gate reports no master-key adoption

The k8s gate check SHALL pass only when no Job template and no Secret entry adopts master-key of Secret llm/llm-gateway-secrets.

Scenario: The clean tree passes the gate

  • WHEN a person runs uv run devops ci --check --only k8s
  • THEN the command exits 0 and prints no finding that names Secret llm-gateway-secrets key master-key.

Requirement: The gate finds an adoption in the table

The k8s master-key check SHALL report one finding for a Secret entry that adopts master-key of Secret llm/llm-gateway-secrets.

Scenario: A crafted table holds an adoption

  • WHEN the unit test runs the master-key check on a ClusterSecret whose entry has adopt_from of llm/llm-gateway-secrets key master-key
  • THEN the check returns one finding that names the Secret and the key master-key.

Requirement: The gate finds an adoption in a Job template

The k8s master-key check SHALL report one finding for a Job template that sets DEVOPS_CLI_AI_API_KEY from master-key of Secret llm/llm-gateway-secrets.

Scenario: A fixture Job template holds an adoption

  • WHEN the unit test runs the master-key check on a fixture directory that holds a Job template with secretKeyRef to Secret llm-gateway-secrets key master-key
  • THEN the check returns one finding that names the fixture file and the key master-key.

Requirement: Pending a person after the merge

A runner Job SHALL call the gateway with a virtual key that has a spend limit.

Scenario: The key info after one runner Job

  • WHEN a person mints the Job virtual key with a spend limit, stores it in the keyring under runner.llm_key, pushes the Secrets, runs one runner Job, and runs curl -s -H "Authorization: Bearer $LITELLM_MASTER_KEY" "$LLM_GATEWAY_URL/key/info?key=$RUNNER_KEY"
  • THEN the response shows the key alias, the max_budget that the issue comment records, and a spend above zero.

Existing Tool Considered

No alternatives check has run. LiteLLM, the gateway that the cluster already runs, covers the need. Its virtual keys carry max_budget, budget_duration and rpm_limit. The repository already uses one for the Service (devops/roadmap-service-llm-key, #3685). LiteLLM lacks a way to keep its own master key out of a pod. The project's table and gate do that. This change adds them. LiteLLM also needs a person to mint the key and set the budget, because its admin API needs the master key or a management key. The change writes one table row and one gate check. It builds no budget code, because the gateway enforces the limit.

Key questions

  • Which table entry adopts the gateway master key today?: The DEVOPS_CLI_AI_API_KEY entry of Secret devops/devops-cli sets adopt_from=SecretKeyRef("llm", "llm-gateway-secrets", "master-key"). It also sets value_prefix=LITELLM_KEY_PREFIX. [sources: src/devops_cli/k8s/cluster_secrets.py]
  • How does a Job pod get a virtual key with a spend limit?: The table reads a person-minted LiteLLM virtual key from the keyring under runner.llm_key, with required=False and value_prefix="sk-", and drops the master-key adoption. The gateway enforces the spend limit on the key, so the pod holds no budget code. The change registers runner.llm_key as a managed credential, so a person stores the value with devops config set. (best practice) [sources: src/devops_cli/k8s/cluster_secrets.py]
    • Chosen: Read a keyring virtual key for the Job pods. LiteLLM enforces max_budget and budget_duration on the key. The repository already uses this pattern for the Service (feat(service): the roadmap Service uses its own gateway key #3685).
    • Rejected: Adopt the master key and set a gateway-wide budget. The master key creates and deletes keys and reads every key. A pod with it bypasses each per-key budget.
    • Rejected: Make the Service mint one key per Job object. It needs a management key, a per-Job Secret and cleanup. The issue records one key name and one limit.
  • How does the gate catch a return of the master-key adoption?: The k8s check scans the Job templates under k8s/ and the CLUSTER_SECRETS table for llm/llm-gateway-secrets key master-key, and reports one finding for each adoption. Unit tests run the check on a fixture Job template and on a crafted table, so a check that stops catching the adoption fails. (best practice) [sources: src/devops_cli/k8s/cluster_secrets.py, docs/adr/0004-ci-is-the-authoritative-gate.md]
    • Chosen: Add the scan to uv run devops ci --check --only k8s and test it. The required check Static Analysis runs the gate, so a return fails CI.
    • Rejected: Rely on review. A review is not a binding gate (ADR 0004).

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/feature
    scope/k8s
    source/agent
    status/new
    value/medium
    effort/medium
    on Nov 25, 2026
  2. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    ContributorAuthor
  3. changed the title [-]feat(k8s): give each roadmap Job a virtual gateway key with a spend limit[/-] [+]feat(k8s): give each job a virtual key with a spend limit[/+] on Nov 25, 2026
  4. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    ContributorAuthor

    The job shortened the title of this item. The summary had 62 characters, and the limit is 60. The type and the scope stay.

    • Before: feat(k8s): give each roadmap Job a virtual gateway key with a spend limit
    • After: feat(k8s): give each job a virtual key with a spend limit
    • Source of the summary: the background model
  5. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    ContributorAuthor

    Owner question: See the first point of Open questions in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  6. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    ContributorAuthor

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

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/p2-mediumscope/k8ssource/agentstatus/newtype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions