Repository navigation
Description
Ready: implementation plan (refined 2026-10-17 at 3dd7fa6)
This section supersedes any text below that conflicts with it.
Decisions
- Scope: this issue delivers the two slices that wait on nothing, and it closes when they merge. (a) is the
DEVOPS_CLI_AI_GATEWAY_URLvariable, the grant-aware 401 hint and the Claude Code deny rules. (b) is thek8s/agents/identity, its Argo CD Application and the orphan-ignore foragent-grant-*Secrets. The grant itself (devops agent env,execandlist, the grant table, the record and the audit) moves to a new item, because it needs gateway virtual keys and the gateway has no database. Both new items are drafted (see Dependencies). The person applying this plan retitles the issue to: "feat(agent): agent sessions get a gateway URL variable, a grant-aware 401 hint, Claude Code deny rules and a read-only kube identity in k8s/agents". - 401 hint wording: when
DEVOPS_CLI_AGENT_GRANTis set,credentials_error(src/devops_cli/ai/client/models.py:95) says the gateway rejected agent grant<id>, that the grant expired or was revoked, and that a person issues a new one. This replaces the generic "Set DEVOPS_CLI_AI_API_KEY" hint. It does not namedevops agent envyet, because that command does not exist until the grant item, and the grant item adds the command name. The id is cut to 256 characters. Both callers get the hint:src/devops_cli/ai/client/base.py:127andsrc/devops_cli/ai/gateway.py:266. DEVOPS_CLI_AGENT_GRANTis declared as an environment-only constant insrc/devops_cli/config/env.py, likeENV_DEVOPS_CLI_CONFIG(env.py:12). It is not a settings option.- Precedence of
DEVOPS_CLI_AI_GATEWAY_URL: it setsai.gateway_urllike every other option variable. A task's ownai.tasks.<task>.api_base_urlstill wins for that task (src/devops_cli/config/settings.py:570-584), as it already wins over the config value. No special case is added. - Deny rules: all three land now, in
permissions.denyof the checked-in.claude/settings.json:Read(//**/.claude/settings.local.json),Read(~/.claude/settings.json)andRead(~/.kube/**).~/.kube/configholds the person's admin credentials today, and a person may already have pasted a key into a settings file'senvblock. The cost is that Claude Code's own settings skills can no longer read those two files, so a person edits them. The rules stop accidental reads only, notprintenvor a script; the issue's Key questions already say so. - Where the
agentsnamespace lives: ink8s/namespaces.yaml, with the other namespaces, which thebaseApplication owns. It gets the same labels andPrune=false,Delete=falseannotation asdevops(k8s/namespaces.yaml:88-98), with Pod Securityrestricted. - Argo CD:
k8s/agents/gets its own Application,k8s/argocd/apps/agents.yaml(projecthomelab, destination namespaceagents, automated prune and self-heal, and the same finalizer and retry ask8s/argocd/apps/devops.yaml). ThedevopsApplication also carries Image Updater and host overrides, and the agent identity should not be coupled to them. ThehomelabAppProject's destinations gainagents. - deploy-stack: both manifests join
_MANIFESTS_BY_STACK["devops"](src/devops_cli/commands/k8s/stack_lifecycle.py:194-203). AGENTS.md requiresdevops k8s deploy-stack --stack allto deploy every manifest, and the identity serves devops-cli's agents. Teardown deletes them in reverse, as it does the rest of the list. - No NetworkPolicy in
agents: nothing runs there, and the identity cannot create pods anywhere. - Orphan-ignore:
{group: '', kind: Secret, name: agent-grant-*}joins thehomelabproject's list (k8s/argocd/apps/projects.yaml:39-79), following thesh.helm.release.v1.*glob. Grant Secrets are runtime objects that the grant item creates. Without the entry, Argo CD warns about every live grant. Prune never touches untracked objects either way. - The open question about live reloads (does Claude Code apply an edited
envblock to a running session?): it moves to the grant item as a person check. Until it is confirmed, the grant command tells the person to start a new session. It does not affect (a) or (b).
Delivery
-
PR 1 (S): the gateway URL variable, the grant-aware 401 hint and the deny rules. Refs feat(agent):
devops agent envgives an agent session its own expiring gateway key, run-index access and a read-only kube identity, written to its settings file or a child process and never printed, with--revokeand an audit of every grant #1154. Tests first:tests/test_config_env_overrides.py:DEVOPS_CLI_AI_GATEWAY_URL=https://example.com/v1makesload_settings().ai.gateway_urlequal that URL, andget_all_env_var_specs()lists the variable as not secret.tests/test_ai_gateway.py: withDEVOPS_CLI_AGENT_GRANT=g-123set, a 401 from the gateway raisesAICredentialsErrorwhose message namesg-123and notDEVOPS_CLI_AI_API_KEY. Without the variable, the message is unchanged. A 300-character id is cut to 256.tests/test_claude_code_settings.py(new):.claude/settings.jsonparses, and itspermissions.denyholds the three rules.
Files:
src/devops_cli/config/options.py(AI_GATEWAY_URL = "ai.gateway_url"besideAI_API_BASE_URLat:24, and in the list at:150),src/devops_cli/config/env.py(constant,OPTION_TO_ENV_VARentry beside:125,EnvVarSpecbeside:329-334, andENV_AGENT_GRANT),src/devops_cli/ai/client/models.py,.claude/settings.json, the regenerateddocs/ENV_VARS.mdanddocs/CONFIGURATION.md, the three test files,changelog.d/1154.md(### Addedand### Security) anddocs/agent/tasks/task-1154-agent-session-prerequisites.md(In Progress, (a) ticked). -
PR 2 (S): the read-only agent identity under GitOps. Closes feat(agent):
devops agent envgives an agent session its own expiring gateway key, run-index access and a read-only kube identity, written to its settings file or a child process and never printed, with--revokeand an audit of every grant #1154. Tests first:tests/test_k8s_agents_manifests.py(new): theagentsnamespace ink8s/namespaces.yamlenforcesrestricted. ServiceAccountagents/devops-agenthasautomountServiceAccountToken: false. ClusterRoleBindingdevops-agent-viewhas roleRefClusterRole/viewand that one subject. No other Role, ClusterRole, RoleBinding or ClusterRoleBinding underk8s/namesdevops-agent.audit_rbac(src/devops_cli/k8s/rbac.py:170) returns no violation for the parsed bindings._MANIFESTS_BY_STACK["devops"]lists both files.tests/test_k8s_argocd_apps.py:test_projects_whitelists_and_orphaned_resources(:177) expects("", "Secret", "agent-grant-*")and theagentsdestination.test_rendered_raw_objects_single_ownership(:217) andtest_namespace_and_pvc_data_safety(:277) includek8s/agents.
Files:
k8s/namespaces.yaml,k8s/agents/kustomization.yaml,k8s/agents/serviceaccount.yaml,k8s/agents/clusterrolebinding.yaml,k8s/argocd/apps/agents.yaml,k8s/argocd/apps/projects.yaml,src/devops_cli/commands/k8s/stack_lifecycle.pyandk8s/README.md. The README changes are: a new "Agent sessions" section on what the identity can and cannot do and how it is applied;agents/in the Directory Structure; and the leaf Application counts at:396and:631going from 22 (8 raw) to 23 (9 raw). Also the two test files, the PR's lines inchangelog.d/1154.md(### Added), and the task file set to Done with (b) ticked.
Acceptance criteria
-
DEVOPS_CLI_AI_GATEWAY_URLsetsai.gateway_url, the env spec lists it as not secret, anddocs/ENV_VARS.mdshows it. - With
DEVOPS_CLI_AGENT_GRANTset, a gateway 401 names the grant id and says a person issues a new grant. Without it, the hint is unchanged. -
.claude/settings.jsondeniesRead(//**/.claude/settings.local.json),Read(~/.claude/settings.json)andRead(~/.kube/**). -
k8s/agents/holds only ServiceAccountdevops-agent(automount off) and ClusterRoleBindingdevops-agent-viewto the built-inview. Nothing else ink8s/grants that ServiceAccount a role, andaudit_rbacreports no violation. - Namespace
agentsisrestrictedand carriesPrune=false,Delete=false. - Argo CD Application
agentssyncsk8s/agents, thehomelabproject admits theagentsdestination, andagent-grant-*Secrets are ignored orphans. -
devops k8s deploy-stack --stack devops(and--stack all) applies both manifests on a cluster without Argo CD, and the dry run lists them. - No test touches a cluster or the network, and each new test's call phase is under 1 s.
-
uv run devops docs checkpasses.CHANGELOG.mdanddocs/ROADMAP.mdare not edited. -
uv run devops cipasses. - Pending a person: after Argo CD syncs the merge (or after
uv run devops k8s deploy-stack --stack devopson a cluster without Argo CD), these printno:kubectl auth can-i get secrets -A --as=system:serviceaccount:agents:devops-agent,kubectl auth can-i create pods/exec -n llm --as=system:serviceaccount:agents:devops-agentandkubectl auth can-i create jobs -n devops --as=system:serviceaccount:agents:devops-agent. Andkubectl auth can-i list pods -A --as=system:serviceaccount:agents:devops-agentprintsyes.
Current references
ai.gateway_urlfield:src/devops_cli/config/settings.py:470- Option-to-variable map, with no gateway entry:
src/devops_cli/config/env.py:109 - The run index variables (the pattern to follow):
src/devops_cli/config/env.py:71-72, mapped at:159-160 credentials_error:src/devops_cli/ai/client/models.py:95-108- Its callers:
src/devops_cli/ai/client/base.py:127,src/devops_cli/ai/gateway.py:266 - Task endpoint folding:
src/devops_cli/config/settings.py:570-584 .claude/ignore rules:.gitignore:75-76.claude/settings.json: haspermissions.allowonly, with nodenyand noenvhomelabAppProject destinations and orphan-ignore list:k8s/argocd/apps/projects.yaml:22-38,:39-79- The
devopsApplication (the template foragents):k8s/argocd/apps/devops.yaml devopsnamespace (the template foragents):k8s/namespaces.yaml:88-98devopsstack manifest list:src/devops_cli/commands/k8s/stack_lifecycle.py:194-203- Manifest-exists invariant:
tests/test_architectural_invariants.py:1410 audit_rbac:src/devops_cli/k8s/rbac.py:170. The privileged roles it flags:src/devops_cli/config/constants.py:729-731
Dependencies and order
- feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741, feat(k8s): argo cd keeps the homelab cluster at the current release branch, with automated sync, prune and self-heal that never delete data #755, refactor(github): one github session per identity owning token, quota and transport #767 and feat(roadmap): agent filing quota: release credit, ratio throttle, borrowing and per-release tuning #1153: closed.
- feat(k8s): the homelab runs gitea under argo cd as a read-write internal forge, served in-cluster over http and to workstations at https://git.<domain> through the cloudflare tunnel, with its admin secret pushed from the keyring #1081 (Gitea): open. It affects only the grant item's Gitea row, not this issue.
- The gateway database item: not filed. Its draft is
.data/agent/scratch/refine/1154-intake-gateway-database.md. A person files it withdevops roadmap intake --confirm, becauseroadmap-serviceis suspended (chore(service): the roadmap service stays at 0 replicas, and its development is blocked, while its machine account is suspended #1562). - The grant item (
devops agent env,execandlist): not filed. Its draft is.data/agent/scratch/refine/1154-intake-agent-grant.md. It waits on the database item and on both PRs here. - refactor(config): a settings field is the one declaration, and the option, env and config-show registries become views of it #1000 (v0.2.37; option and env registries become views of the settings fields): whichever merges second rebases. If refactor(config): a settings field is the one declaration, and the option, env and config-show registries become views of it #1000 merges first, PR 1 declares the variable on the settings field the way refactor(config): a settings field is the one declaration, and the option, env and config-show registries become views of it #1000 does.
- refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001 (v0.2.37; one model seam): it may move
credentials_error's callers. Whichever merges second keeps the grant-aware hint. - docs(agents): task files carry no status, milestone or priority and are written only by the delivering pr #879 (v0.2.37; task file rules): if it merges first, the task file follows its rule.
- PR 1 and PR 2 share only
changelog.d/1154.mdand the task file. PR 1 merges first; PR 2 merges second and closes the issue.
Problem
The owner's direction of 2026-10-04: once push-secrets works, the credentials can be read with kubectl, but devops-cli should get the functionality that sets up an agent environment.
An agent session (Claude Code in the devcontainer) runs devops from its shell. Today:
-
No gateway credential in the session. Model calls to
https://ai.<domain>/v1answer 401. The only gateway credential is LiteLLM's master key (general_settings.master_key: os.environ/LITELLM_MASTER_KEY, k8s/llm/gateway/configmap.yaml, fromllm/llm-gateway-secretsmaster-key, k8s/llm/gateway/deployment.yaml:52-56). The master key is the proxy admin key: whoever holds it can mint and delete keys and call every model without limit. -
The owner's rule. Agents never read, print or copy a credential value into a conversation. Today the only ways to give a session the key are a person pasting it into a shell or a settings file, or the agent copying it from the keyring or the cluster. Each of these breaks the rule or hands over the master key.
-
The keyring wins over the environment.
build_default_resolverorders the providers keyring, Vault, environment, settings (src/devops_cli/security/secrets.py:338). Inside the devcontainer, the agent shares the person's keyring (one home volume = one identity). SoDEVOPS_CLI_AI_API_KEYset for the agent is ignored whenever the keyring is unlocked and holdsai_api_key. That key is the person's key, which may belong to another provider. -
No environment variable for the gateway URL.
ai.gateway_url(src/devops_cli/config/settings.py:457, defaulthttp://localhost:4000/v1) has no entry inOPTION_TO_ENV_VAR(src/devops_cli/config/env.py:109). The run index has one:DEVOPS_CLI_RUNS_INDEX_URLandDEVOPS_CLI_RUNS_INDEX_PASSWORD(env.py:80-81). -
The run index password lives only in the person's settings and keyring.
devops ai runs connectreads it fromllm/valkey-runs-authand stores it there (src/devops_cli/commands/ai_runs.py:155-170). It usessecret_value(src/devops_cli/k8s/node_port.py:86), which decodes one Secret key and never logs it. That Secret is not live yet; feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741 creates it. -
Kube access is the person's admin kubeconfig.
kubectl auth can-i --listin the devcontainer shows*.*with every verb (read 2026-10-04). An agent can read every Secret, exec into every pod and delete anything. Cluster: Kubernetes v1.31 (k3s), so bound service-account tokens (kubectl create token --bound-object-kind Secret) are available. -
The gateway cannot issue virtual keys yet. LiteLLM's virtual keys (
/key/generatewithduration,max_budget,rpm_limit,tpm_limit,max_parallel_requests,models,key_alias,metadata) need a Postgres database throughDATABASE_URL. The gateway sets none:- The live Deployment's env names are
LITELLM_MASTER_KEY,LITELLM_LOCAL_MODEL_COST_MAP,LITELLM_TELEMETRY,LITELLM_REDIS_HOSTandLITELLM_REDIS_PORT(read 2026-10-04), the same as k8s/llm/gateway/deployment.yaml:47-65. The config'sgeneral_settingsholds onlymaster_key,store_model_in_db: falseandproxy_batch_write_at(configmap.yaml:196-199). - No Postgres runs in the cluster (no database image in any pod, read 2026-10-04).
- The gateway's NetworkPolicy allows egress only to the inference backends, Valkey and DNS (k8s/llm/gateway/networkpolicy.yaml).
- The container has
readOnlyRootFilesystem: truewith only/tmpwritable (deployment.yaml:36, :74-75). LiteLLM runsprisma migrate deployat start-up onceDATABASE_URLis set, and its production guide asks forLITELLM_MIGRATION_DIRon a writableemptyDirunder a read-only root filesystem.
LiteLLM offers no per-client scoped key without the database, so the database is a prerequisite item (see Key questions). It is not an option to hand a session the master key.
- The live Deployment's env names are
-
Budgets do not bind on local models. The gateway config sets no
input_cost_per_tokenoroutput_cost_per_token, and its models are Ollama models with no cost in the bundled cost map (LITELLM_LOCAL_MODEL_COST_MAP=True). Somax_budgetlimits spend only on models with a cost. On the local tiers, the limits arerpm_limit,tpm_limitandmax_parallel_requests. The gateway runs one replica (deployment.yaml:12), so those counters hold in its process.LITELLM_REDIS_HOSTis not a name in LiteLLM's documented settings (it readsREDIS_HOST), and the config has nocacheorrouter_settings.redis_host. So no shared counter store should be assumed if the gateway is scaled out. -
Switching the session to the keyring library's null backend (the fix below) hides every keyring credential, not only
ai_api_key.KEYRING_KEYS(src/devops_cli/config/options.py:242) also holdsgithub_token,grafana_token,grafana_password,argocd_token,argocd_password,qdrant_api_key,valkey_password,runs_index_password,logfire_tokenandcloudflare_api_token. Under the null backend_keyring_getreturns nothing (_ensure_keyring_backend, src/devops_cli/config/settings.py:123-141, rejects a backend with priority 0 or less). GitHub still works throughgh auth token(get_github_token, settings.py:1051). Commands that need Qdrant, Grafana, Argo CD or Cloudflare credentials stop working in a session that holds a grant. -
Claude Code reads an
envblock from~/.claude/settings.json(user scope) and.claude/settings.local.json(project-local scope, at the repository root; in a worktree, the main checkout's). It applies the block to the session and its tool subprocesses. Claude Code watches its settings files and applies most edits to a running session;envis not among the keys its documentation says are read only at start-up, but that has not been tried here..claude/*is git-ignored here except.claude/settings.json(.gitignore:71-72). The checked-in.claude/settings.jsonhas noenvblock and nodenyrules today. -
Permission rules cover file commands only. Claude Code applies
Readdeny rules to its file tools and to the file commands it recognises in Bash (cat,head,tail,sed), but not toprintenv,envor a script that opens the file itself. In a rule,./pathis relative to the current directory and/pathto the settings file's project, so a worktree session needs an absolute pattern to reach the main checkout'ssettings.local.json. -
Existing pieces to reuse:
secret_value(src/devops_cli/k8s/node_port.py:86) andfetch_secret_data(src/devops_cli/k8s/credentials.py:60) for reading cluster Secrets;node_port_address(node_port.py:77) for the run index URL;record_audit_event(src/devops_cli/core/audit.py:35, a 0600 JSONL log); the temp-file-and-os.replacewrite insave_settings(src/devops_cli/config/settings.py:1017, which sets no file mode, so the settings writer here sets 0600 itself);audit_rbac(src/devops_cli/k8s/rbac.py, behinddevops k8s rbac-audit);CONST_KEYRING_SERVICE(src/devops_cli/config/constants.py:22,devops-cli); and thekubernetes==36.0.3,httpx2==2.13.0andkeyring==25.7.0dependencies (pyproject.toml).
Proposed solution
A new command group, devops agent, issues each agent session its own credentials. These are a grant: an id, an agent name, an expiry, and the credentials minted for it. The command writes them where the agent's process reads them and never prints them. One table, held as data like #741's Secret table, lists the environment variables a grant sets, where each value comes from, and which item adds it.
What a grant contains
| Env name | Value | Source when a person runs it (keyring unlocked) | Source from the cluster (--source cluster) |
Lifetime |
|---|---|---|---|---|
DEVOPS_CLI_AI_API_KEY |
a new LiteLLM virtual key, alias agent-<name>-<grant id> |
minted with the master key from keyring llm_gateway_master_key (#741) |
minted with llm/llm-gateway-secrets master-key, read with secret_value |
--ttl (LiteLLM duration) |
DEVOPS_CLI_AI_PROVIDER |
gateway |
literal | literal | none |
DEVOPS_CLI_AI_GATEWAY_URL (new) |
ai.gateway_url |
settings | settings | none |
DEVOPS_CLI_RUNS_INDEX_URL |
runs.index_url, else node_port_address as in ai runs connect |
settings | cluster | none |
DEVOPS_CLI_RUNS_INDEX_PASSWORD |
the run index password | keyring runs_index_password |
llm/valkey-runs-auth password |
shared, see Key questions |
KUBECONFIG |
path of a 0600 kubeconfig holding a bound token for ServiceAccount agents/devops-agent |
token from the TokenRequest API, made with the caller's context | same | --ttl |
PYTHON_KEYRING_BACKEND |
keyring.backends.null.Keyring |
literal | literal | none |
DEVOPS_CLI_AGENT_GRANT |
the grant id (not a secret) | generated | generated | none |
- The master key never leaves the command. It is used for one
POST /key/generateand onePOST /key/deleteon revoke, and is never written anywhere. It is sent to the gateway's admin routes at the root ofai.gateway_url, over the same tunnel HTTPS host the CLI already uses. Before minting, the command reads the gateway's/health/readinessand stops when itsdbfield does not report a connected database, so a gateway without the database is named before any key is sent. - The person's keyring stays out of the session.
PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyringis the keyring library's own null backend, sodevopsin the agent session resolves credentials only from the environment. It never reads the person'sai_api_key, and feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741'spush-secretsrefuses to run there because the backend is not an encrypted one.ghkeeps its own store and is not affected. The other keyring credentials are hidden too (see Problem); the command's output lists theKEYRING_KEYSentries the session will not see. - Kube access. New manifests under
k8s/agents/(namespaceagents, Pod Securityrestricted):- ServiceAccount
devops-agent,automountServiceAccountToken: false. - ClusterRoleBinding
devops-agent-viewto the built-inviewClusterRole. On this cluster it aggregates onlysystem:aggregate-to-viewand the metrics reader (read 2026-10-04). It allows reads, includingpods/logand ConfigMaps in every namespace, and no Secrets,serviceaccounts/token,pods/exec,pods/portforwardor writes. A scan of the live ConfigMaps and pod env on 2026-10-04 found no literal credential (the matches werebearer_token_filepaths). - No write access, and in particular no Job creation. feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741's cluster Jobs run
ENTRYPOINT ["devops"]with thedevops-cliSecret (the master key asDEVOPS_CLI_AI_API_KEY, andGH_TOKEN) and egress to any public address on 443. Only the Job'sargschange, butargsalone run any devops command with those credentials: unlimited model calls under the master key, outside every grant limit, and any GitHub write the CLI offers as the machine account, with the output readable throughpods/log. Whether any command forwards the key to a host named in its args has not been audited; the CLI has many URL options. An admission policy oncommand,envor volumes does not close any of this. Sodevops k8s run-jobstays with the person's context, and agent Job creation waits for the follow-up in Key questions. - The token comes from
kubectl create token devops-agent -n agents --duration <ttl> --bound-object-kind Secret --bound-object-name agent-grant-<id> --bound-object-uid <uid>. The bound object is an empty Secret,agents/agent-grant-<id>, labelled with the grant id and agent name, created just before. Deleting it invalidates the token, so each grant is revoked on its own. The token is read from kubectl's captured stdout. - The kubeconfig copies only the server and CA of the caller's context, read with
kubectl config view --minify --flatten -o jsonpath='{.clusters[0].cluster}', so the caller's client credentials are never read. It is written by Python as YAML at mode 0600, never withkubectl config set-credentials --token, which would put the token in argv.
- ServiceAccount
Commands
devops agent env NAME [--target local|user] [--ttl 8h] [--rpm N] [--tpm N] [--max-parallel N] [--budget USD] [--models M]... [--kube/--no-kube] [--runs/--no-runs] [--source auto|keyring|cluster] [--context CTX] [--revoke] [--dry-run]
-
--target local(the default) merges the grant's names into theenvblock of the repository's.claude/settings.local.json.--target useruses~/.claude/settings.json.- The file is read as JSON, and only the grant's keys are added or replaced. Other keys and other
enventries stay as they were. - It is written atomically (temp file in the same directory,
os.replace) with mode 0600, and an existing file's mode is tightened to 0600. - A file that is not valid JSON exits 1 and is left as it is.
- The file is read as JSON, and only the grant's keys are added or replaced. Other keys and other
-
--source.autouses the keyring when it has an encrypted, unlocked backend. Otherwise it reads the cluster Secrets with the caller's context.keyringandclusterforce one source. A locked keyring under--source keyringexits 1 namingdevops devcontainer unlock-keyring, as in feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741. -
Re-running for the same NAME refreshes the grant. It mints the new grant first, writes it, then revokes the old one, so the session is never left without a working key.
-
Limits. The defaults are
--ttl 8h,--rpm 60and--max-parallel 2, plus--modelswith the gateway'sdevops-*groups, the pinned review groupsqwen3-coder:30bandgpt-oss:20b, and the embedding groupbge-m3:latest(configmap.yaml).--ttlis capped at7d.--budgetis passed asmax_budgetand only binds on models with a cost; the help text says so. -
--no-kubeand--no-runsleave those rows out. A namespace or Secret that does not exist (agentsbefore the manifests are applied, orllm/valkey-runs-authbefore feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741) leaves its row out with a warning naming the command that creates it. The gateway key row is required. -
Output. One line per env name with its source and state (
minted,written,unchanged,revoked,skipped), followed by the target path, the expiry in UTC and the key alias. Never a value. -
--dry-runreads settings and runs onlykubectl geton names. It mints nothing, writes nothing, and prints the same lines aswould …. -
--revoke:- calls
POST /key/deletewith the grant's key alias (key_aliases); - deletes
agents/agent-grant-<id>, which invalidates the token; - deletes the kubeconfig file;
- removes the grant's names from the target file's
envblock, but only when they still hold the grant's values. The comparison is in memory, so a later grant or a person's own edit is not removed.
Each step runs even when an earlier one failed, and the output names any step that did not complete.
- calls
devops agent exec NAME [same limits] -- CMD... mints a grant, runs CMD with the grant in its environment (os.environ plus the grant, passed to subprocess.run(env=...)), and revokes the grant when CMD exits, including on Ctrl-C. The values are never written to disk, except the kubeconfig, which is deleted on exit. If revocation fails, the expiry still ends the grant. The command exits with CMD's exit code.
devops agent list prints each grant from the local record: name, id, target, env names, expiry, key alias, and whether the grant's Secret still exists. --spend adds each key's spend and request count from LiteLLM, looked up by alias with the master key and printed as numbers only.
Record and audit
- Local record. Each grant is recorded in
<data dir>/agents/grants.json(0600) with the id, name, target path, env names, key alias, bound Secret name, kubeconfig path, expiry, the issuing user and the source. No values.--revokeandlistread this record. - Audit log. Every mint, refresh and revoke writes one
record_audit_evententry (agent.env.grant,agent.env.revoke,agent.exec) with the same fields, also without values. - On the gateway, the key's
metadatacarriesdevops_cli_grant,agentandissued_by. LiteLLM's own spend logs then attribute each request to the grant. - In the cluster, the grant Secret carries the grant id, agent name and expiry as labels and annotations. The API server's audit log then names the ServiceAccount.
A 401 names the fix
When DEVOPS_CLI_AGENT_GRANT is set and the gateway answers 401, the AI client's error names devops agent env <name> to refresh the grant. It no longer gives the generic missing-key hint.
Other changes
DEVOPS_CLI_AI_GATEWAY_URLjoinsOPTION_TO_ENV_VARforai.gateway_url, with an env spec entry.- The grant table is a frozen dataclass table in
src/devops_cli/agent/grant.py. Later items add rows: the Gitea row (feat(k8s): the homelab runs gitea under argo cd as a read-write internal forge, served in-cluster over http and to workstations at https://git.<domain> through the cloudflare tunnel, with its admin secret pushed from the keyring #1081), and any further service an agent reaches. - The gateway calls use the existing
httpx2client with the master key in theAuthorizationheader. The key is never placed in a URL. Secret reads usesecret_valueorfetch_secret_data. Tokens are made by kubectl, with output captured and never echoed. - The project's checked-in
.claude/settings.jsongainsdenyrules forRead(//**/.claude/settings.local.json),Read(~/.claude/settings.json)andRead(~/.kube/**). The absolute pattern also reaches the main checkout's file from a worktree session. Claude Code applies them to its file tools and tocat,head,tailandsedin Bash, not toprintenvor a script, so they stop accidental reads only. - Help strings are added in
lang/en/help.py, and the docs are regenerated. Thek8s/README.mdsection "Agent sessions" describes applyingk8s/agents/and the person checks. - The PR adds
changelog.d/<n>.mdand the task filedocs/agent/tasks/task-<n>-agent-env.md. CHANGELOG.md and docs/ROADMAP.md are not edited.
Acceptance criteria
In the gate. No network and no cluster. The tests use an httpx2 mock transport for the gateway, a patched subprocess runner for kubectl, a stub keyring and tmp_path homes. Together they take under 1 s, measured with uv run pytest tests/test_agent_env.py tests/test_k8s_agents_manifests.py --durations=0.
- Grant,
--target local:.claude/settings.local.jsongains exactly the grant table's env names and keeps every other key.- The file mode is 0600, including when an existing file was 0644.
- Invalid JSON exits 1, and the file is left byte-for-byte unchanged.
- Gateway key. One
POST /key/generate:- It goes to the gateway root (no
/v1), withAuthorization: Bearer <master key>. - Its body carries
key_alias,durationequal to--ttl,rpm_limit,max_parallel_requests,modelsandmetadata.devops_cli_grant. - The written
DEVOPS_CLI_AI_API_KEYis the key the response returned, and it is not the master key.
- It goes to the gateway root (no
- Master key nowhere.
- The master key is not in the settings file, the record, the audit log or the kubeconfig.
- No recorded argv, log record (caplog), stdout or stderr contains any test value: the master key, the virtual key, the run index password or the token.
- Keyring isolation.
- The env block sets
PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring. - With that variable set and
DEVOPS_CLI_AI_API_KEYset,get_ai_api_key(load_settings())returns the environment value, even though the stub keyring holds a differentai_api_key.
- The env block sets
- Sources.
--source keyringreadsllm_gateway_master_keyandruns_index_passwordand runs nokubectl get secret.--source clusterreads the two Secrets throughsecret_valueand touches no keyring.autowith a locked stub keyring falls back to the cluster.--source keyringwith a locked keyring exits 1 with the unlock hint and makes no gateway call.
- Kube token.
- Exactly one
kubectl create token devops-agent -n agents --duration 8h --bound-object-kind Secret --bound-object-name agent-grant-<id> --bound-object-uid <uid>runs, after the grant Secret is created, and its argv holds no token. - The only
kubectl config viewcall is the--minify --flatten -o jsonpath='{.clusters[0].cluster}'read. The kubeconfig's user holds only the token, and its cluster entry equals the caller's server and CA. Nokubectl config set-credentialsruns. --no-kuberuns neither command and writes noKUBECONFIG.
- Exactly one
- Refresh. A second run for the same name mints, writes, then deletes the old alias and the old grant Secret, in that order.
- Revoke.
--revoke NAMErunsPOST /key/deletewith the alias,kubectl delete secret agent-grant-<id> -n agentsand the kubeconfig unlink, and removes the env names.- A gateway failure still runs the other steps and exits 1 naming the failed step.
- A name whose value was replaced since the grant is left in the file.
- exec.
- The child receives the grant in its
envargument. - No settings file is written.
- The grant is revoked after the child exits, including when the child raises
KeyboardInterrupt. - The command exits with the child's exit code (3 in the test).
- The child receives the grant in its
- Missing pieces.
- With no
agentsnamespace, the kube row is skipped with a warning namingdevops k8s apply k8s/agents/ --template. - With no
valkey-runs-auth, the runs rows are skipped, with a warning namingdevops k8s push-secrets. - A gateway whose
/health/readinessreports no connected database exits 1 before anyPOST. The message names the database prerequisite item. Nothing is written, and no fallback to the master key happens. A/key/generatethat still fails the same way gets the same message.
- With no
-
--dry-runmakes no POST, no write and nocreate/delete, and prints names and states only. - Record and audit.
grants.jsonand one audit entry per action hold the id, name, alias, env names and expiry.- A test that searches both files for every test value finds none.
- Manifests (tests/test_k8s_agents_manifests.py):
- The namespace
agentsisrestricted, and the ServiceAccount has automount off. - The ClusterRoleBinding's roleRef is the built-in
view. - No other Role, ClusterRole or binding names the ServiceAccount, so it has no write verb anywhere and no
createonbatch/jobs. audit_rbac(the check behinddevops k8s rbac-audit) reports no violation for the parsed manifests.
- The namespace
- Env spec.
DEVOPS_CLI_AI_GATEWAY_URLsetsai.gateway_url, and the env spec test lists it. - 401 hint. With
DEVOPS_CLI_AGENT_GRANTset, a 401 from the gateway namesdevops agent env. -
uv run devops agent --helplistsenv,execandlist, anduv run devops docs checkpasses. -
uv run devops cipasses within its 5-minute budget.
Pending a person (keyring unlocked, after #741 and the gateway database item):
-
uv run devops k8s apply k8s/agents/ --template --context <context>. -
uv run devops agent env reviewer --dry-runlists every row aswould mintorwould write, with no value. -
uv run devops agent env reviewerexits 0.stat -c %a .claude/settings.local.jsonprints600. -
In a new Claude Code session in the repository, run these:
uv run devops ai gateway status --format jsonreports"healthy": true;- a one-line
devops aicall succeeds; kubectl auth can-i get secrets -Aprintsno;kubectl auth can-i create pods/exec -n llmprintsno.
The agent runs these without reading or printing any value.
-
From that session,
kubectl auth can-i create jobs -n devopsprintsno, anduv run devops k8s run-job -- --versionfails as forbidden. The same command from the person's own shell still succeeds. -
uv run devops agent list --spendshows the grant with a request count. -
uv run devops agent env reviewer --revoke. After it:- the next model call from the session answers 401, and its message names
devops agent env reviewer; kubectl --kubeconfig <path> get podsfails, or the file is gone.
- the next model call from the session answers 401, and its message names
-
uv run devops agent exec reviewer -- uv run devops ai gateway statussucceeds. After it,uv run devops agent listshows no live grant forreviewer.
Constraints. These hold for every command:
- No value reaches argv, a log, stdout, stderr, the record or the audit log. A dry run shows names only.
- The master key is used only inside the command and is never given to a session.
- The kube identity a grant writes cannot read Secrets, exec, port-forward, or write anything, Jobs included.
- These are limits on what a grant hands out, not a boundary against the session itself: the session runs as the person's user, beside the person's
~/.kube/configand keyring (see Key questions). - Every grant expires. Revoking one grant leaves the others working.
Key questions
-
Command name? Proposed: a top-level
devops agentgroup withenv,execandlist.devops ai agentsalready exists and writes AGENTS.md (src/devops_cli/commands/ai.py:853), so anaisubcommand would be confusing.devops k8scovers only one of the four credentials.
-
Does the virtual key need the gateway database first, and in which item? Proposed: a separate prerequisite item, "the LiteLLM gateway keeps keys in Postgres". It covers:
- a single-instance Postgres from the official
postgresimage, as a StatefulSet inllmon a protected PVC with backups, under GitOps; DATABASE_URLandLITELLM_SALT_KEYas new rows in feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741's Secret table, with values generated and adopted like the master key;- a gateway egress rule to the database on 5432, and a database NetworkPolicy that admits only the gateway (a namespace-selector-only peer where kube-router needs it, as feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741 found);
- keeping
readOnlyRootFilesystem: true: LiteLLM runsprisma migrate deployat start-up, and its production guide setsLITELLM_MIGRATION_DIRto a writableemptyDirfor this case. Whether the pinnedv1.103.0image needs further writable paths is untested; - deciding
general_settings.allow_requests_on_db_unavailable.
This item depends on it. Until it lands,
devops agent envexits 1 naming that item. It never falls back to handing out the master key. Alternatives:- an operator (CloudNativePG) is one more controller;
- a hosted database would send key hashes out of the cluster.
- a single-instance Postgres from the official
-
Can the agent read its own grant, or step around it? Yes to both. The agent runs as the same user as the file and the process environment, so
printenvor a script would show the values; the Read deny rules stop onlycat-style reads and the file tools. It also shares the person's home volume (one home volume = one identity): it could unsetKUBECONFIGandPYTHON_KEYRING_BACKENDfor one command and reach the person's admin~/.kube/configand, while unlocked, the keyring. The design does not rely on hiding anything:- No command prints a value, so none reaches the conversation unless the agent goes looking. The owner's rule forbids that, and the deny rules block the obvious paths.
- Each credential is limited, expires, and can be revoked on its own, so a leaked value is worth little.
- The grant makes the scoped identity the default one, so ordinary
devopsandkubectlcalls stop using admin credentials.
Proposed: separation that the system enforces is a separate devcontainer with its own home volume for agents (a separate home volume is a separate identity). That is out of scope here.
-
Settings file or child process? Proposed: both.
--target localis the default because Claude Code is usually started by a person, not bydevops.execkeeps values off disk for scripted and workflow runs. Claude Code's documentation says it reloads changed settings files in a running session and does not listenvamong the start-up-only keys, but this has not been tried. The person check starts a new session, and the output says to. -
Default limits? Proposed:
--ttl 8h, capped at7d;--rpm 60;--max-parallel 2, because the background tier serves one request at a time (configmap.yaml comments ondevops-background); and models limited to thedevops-*groups, the pinned review groups and the embedding group.--budgethas no default, because local models carry no cost. -
Who may mint?
- Proposed: whoever can read the master key, which today is a person with the keyring unlocked or an admin context.
- A narrower issuer role is listed in Out of scope. It would be
geton the two named Secrets,createonserviceaccounts/tokenfordevops-agent, andcreate/deleteon Secrets inagents. - A session holding a grant cannot mint with what the grant gives it: its keyring is the null backend, and its kubeconfig cannot read Secrets. Stepping around the grant (above) is not prevented.
- There is no MCP tool, because an MCP tool would let an agent mint its own credentials.
-
Why a bound Secret for the kube token?
- Bound tokens from
kubectl create tokenexpire and leave no Secret holding the token. - Binding each token to an empty per-grant Secret is the Kubernetes mechanism that revokes one token without rotating the ServiceAccount.
- The Secrets sit in their own namespace,
agents, so an issuer never needs write access todevops, wheredevops-cli's Secret lives.
- Bound tokens from
-
Why
viewonly, without Job creation?viewis the maintained built-in read-only role, and it excludes Secrets, tokens and exec.- Creating a Job from feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741's CronJob template runs any devops command with the master key and the machine account's
GH_TOKEN, with 443 egress to any public host. AValidatingAdmissionPolicycan forbidcommand,envand volumes, butargsare the point ofrun-job, and they reach every command that uses those credentials. Allow-listing args in CEL would be a hand-rolled command filter. - Proposed: agent Job creation is a follow-up. It becomes safe once the cluster Jobs' key is a scoped virtual key (below) and
GH_TOKENbelongs to a narrowly scoped identity (refactor(github): one github session per identity owning token, quota and transport #767). Until then, the person runsrun-job.
-
The run index password is shared. Valkey ACL users could give each agent its own user. Proposed: out of scope. The grant passes the shared password,
listshows which sessions hold it, and rotation goes through feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741'spush-secrets --rotate. -
Gitea? feat(k8s): the homelab runs gitea under argo cd as a read-write internal forge, served in-cluster over http and to workstations at https://git.<domain> through the cloudflare tunnel, with its admin secret pushed from the keyring #1081 is not deployed. Proposed: the Gitea row is added by feat(k8s): the homelab runs gitea under argo cd as a read-write internal forge, served in-cluster over http and to workstations at https://git.<domain> through the cloudflare tunnel, with its admin secret pushed from the keyring #1081 or its follow-up. It would be a scoped token minted through Gitea's token API or stored as a managed credential, with git reaching it through a credential helper rather than an env value. The grant table here takes that row without changes.
-
Should cluster Jobs also use a virtual key? feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741's
devops/devops-cliputs the master key intoDEVOPS_CLI_AI_API_KEYfor every cluster Job. Proposed: once the database item lands, a follow-up switches that row to a long-lived virtual key without an expiry, minted bypush-secrets, so no workload holds the master key except the gateway and Open WebUI. The same follow-up can then give the agent identitycreateon Jobs indevops. -
Which other keyring credentials should a grant carry? The null backend hides
qdrant_api_key,valkey_password, the Grafana, Argo CD and Cloudflare credentials andlogfire_tokenfrom the session. Proposed: none in this item. A Qdrant row (DEVOPS_CLI_QDRANT_API_KEYfromllm/qdrant-api-keyapi-key) would be a shared admin key like the run index password; Qdrant's own read-only JWTs are the scoped option and a separate item. Grafana, Argo CD and Cloudflare stay out of agent sessions. -
Interplay with feat(roadmap): agent filing quota: release credit, ratio throttle, borrowing and per-release tuning #1153? feat(roadmap): agent filing quota: release credit, ratio throttle, borrowing and per-release tuning #1153 is the agents' GitHub filing quota (release credit, ratio throttle). It is separate: this item issues no GitHub credential and enforces no filing limit. The grant's agent name could later serve feat(roadmap): agent filing quota: release credit, ratio throttle, borrowing and per-release tuning #1153 as the identity a quota is charged to.
-
GitOps (feat(k8s): argo cd keeps the homelab cluster at the current release branch, with automated sync, prune and self-heal that never delete data #755)?
k8s/agents/is in git and joins thedevopsApplication, or gets its own Application, when feat(k8s): argo cd keeps the homelab cluster at the current release branch, with automated sync, prune and self-heal that never delete data #755 lands. Until then it is applied withdevops k8s apply --template. Grant Secrets are runtime objects labelledapp.kubernetes.io/managed-by: devops-cliand listed as ignored orphans, as feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741's Secrets are, so prune never removes a live grant.
Out of scope
- The gateway's database (the prerequisite item above), switching feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741's cluster-Job key to a virtual key, and Job creation for the agent identity.
- Per-agent Valkey ACL users, Qdrant read-only JWTs, and a narrower issuer role for non-person minting.
- A separate devcontainer or home volume per agent.
- Gitea tokens (feat(k8s): the homelab runs gitea under argo cd as a read-write internal forge, served in-cluster over http and to workstations at https://git.<domain> through the cloudflare tunnel, with its admin secret pushed from the keyring #1081), the GitHub identity (refactor(github): one github session per identity owning token, quota and transport #767) and agent filing quotas (feat(roadmap): agent filing quota: release credit, ratio throttle, borrowing and per-release tuning #1153).
- An MCP tool for minting.
- Edits to CHANGELOG.md and docs/ROADMAP.md.
Strategic alignment
- Milestone. Proposed: v0.2.27, after feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741 (v0.2.26) and beside feat(k8s): argo cd keeps the homelab cluster at the current release branch, with automated sync, prune and self-heal that never delete data #755, which syncs
k8s/agents/. Placement is open for the owner. - Priority: P1. It carries out the owner's direction of 2026-10-04: agent sessions get scoped, expiring credentials without a person pasting them, and their default kube identity and gateway key stop being the admin kubeconfig and the master key. Value: High. Effort: Medium to high: about 350 lines of product code (the grant table, the minting and revoke paths, the settings merge, the record, exec) plus the manifests and tests. No admission policy is needed.
- Depends on:
- feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741, for the keyring key
llm_gateway_master_key(the keyring source) and the Secretllm/valkey-runs-auth(the runs rows), both from its Secret table.llm/llm-gateway-secretsexists today, so--source clustercan mint before feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741; the runs rows are skipped with a warning untilvalkey-runs-authexists; - the gateway database item, to be filed with this one. Without it no grant can be minted.
- feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741, for the keyring key
- Related: feat(k8s): argo cd keeps the homelab cluster at the current release branch, with automated sync, prune and self-heal that never delete data #755 (GitOps for
k8s/agents/), feat(roadmap): agent filing quota: release credit, ratio throttle, borrowing and per-release tuning #1153 (separate agent quota), feat(k8s): the homelab runs gitea under argo cd as a read-write internal forge, served in-cluster over http and to workstations at https://git.<domain> through the cloudflare tunnel, with its admin secret pushed from the keyring #1081 (Gitea row), refactor(github): one github session per identity owning token, quota and transport #767 (GitHub identity).
Proposed design
Problem statement
The current devops agent environment setup lacks secure, expiring credentials for agent sessions. Agents run with the master key or the person's admin kubeconfig, which poses security risks. The solution is to implement a new devops agent command group that issues each agent session its own expiring gateway key, run-index access and a read-only kube identity, all written to settings files or child processes without printing any values.
Acceptance criteria
- Criterion 1:
DEVOPS_CLI_AI_GATEWAY_URLsetsai.gateway_url, the env spec lists it as not secret, anddocs/ENV_VARS.mdshows it.
Verification: Runuv run pytest tests/test_config_env_overrides.pyto verify thatDEVOPS_CLI_AI_GATEWAY_URL=https://example.com/v1`` makesload_settings().ai.gateway_urlequal that URL, andget_all_env_var_specs()lists the variable as not secret. - Criterion 2: With
DEVOPS_CLI_AGENT_GRANTset, a gateway 401 names the grant id and says a person issues a new grant. Without it, the hint is unchanged.
Verification: Runuv run pytest tests/test_ai_gateway.pyto verify that withDEVOPS_CLI_AGENT_GRANT=g-123set, a 401 from the gateway raisesAICredentialsErrorwhose message namesg-123and notDEVOPS_CLI_AI_API_KEY. Without the variable, the message is unchanged. A 300-character id is cut to 256. - Criterion 3: .claude/settings.json denies
Read(//**/.claude/settings.local.json),Read(~/.claude/settings.json)andRead(~/.kube/**).
Verification: Runuv run pytest tests/test_claude_code_settings.pyto verify that.claude/settings.jsonparses, and itspermissions.denyholds the three rules. - Criterion 4:
k8s/agents/holds only ServiceAccountdevops-agent(automount off) and ClusterRoleBindingdevops-agent-viewto the built-inview. Nothing else ink8s/grants that ServiceAccount a role, andaudit_rbacreports no violation.
Verification: Runuv run pytest tests/test_k8s_agents_manifests.pyto verify that theagentsnamespace ink8s/namespaces.yamlenforcesrestricted. ServiceAccountagents/devops-agenthasautomountServiceAccountToken: false. ClusterRoleBindingdevops-agent-viewhas roleRefClusterRole/viewand that one subject. No other Role, ClusterRole, RoleBinding or ClusterRoleBinding underk8s/namesdevops-agent.audit_rbac(src/devops_cli/k8s/rbac.py:170) returns no violation for the parsed bindings. - Criterion 5: Namespace
agentsisrestrictedand carriesPrune=false,Delete=false.
Verification: Verify thatk8s/namespaces.yamlcontains theagentsnamespace withpod-security.kubernetes.io/enforce: restrictedandargocd.argoproj.io/sync-options: Prune=false,Delete=falseannotations. - Criterion 6: Argo CD Application
agentssyncsk8s/agents, thehomelabproject admits theagentsdestination, andagent-grant-*Secrets are ignored orphans.
Verification: Runuv run pytest tests/test_k8s_argocd_apps.pyto verify thattest_projects_whitelists_and_orphaned_resources(:177) expects("", "Secret", "agent-grant-*")and theagentsdestination. Also, verify thatk8s/argocd/apps/projects.yamlcontainsagentsin the destinations list. - Criterion 7:
devops k8s deploy-stack --stack devops(and--stack all) applies both manifests on a cluster without Argo CD, and the dry run lists them.
Verification: Rundevops k8s deploy-stack --stack devopsand verify that it applies both manifests on a cluster without Argo CD. Also, check that the dry run lists them. - Criterion 8: No test touches a cluster or the network, and each new test's call phase is under 1 s.
Verification: Runuv run pytest tests/test_agent_env.py tests/test_k8s_agents_manifests.py --durations=0to verify that all tests use mocks for network and cluster access and that the call phase of each test is under 1 second. - Criterion 9:
uv run devops docs checkpasses.CHANGELOG.mdanddocs/ROADMAP.mdare not edited.
Verification: Runuv run devops docs checkand ensure it passes without any errors. - Criterion 10:
uv run devops cipasses.
Verification: Runuv run devops cito verify that all CI checks pass.
Key questions
- Should the command name be
devops agent?: Yes, proposed to be a top-level group withenv,execandlist. (proposed) - Does the virtual key need the gateway database first?: Yes, a separate prerequisite item is needed for 'the LiteLLM gateway keeps keys in Postgres'. (proposed)
- Can agents read their own grants or step around them?: Yes, agents can read their own grants through
printenvor scripts, but the design relies on limits, expirations and revocation rather than hiding values. (proposed) - Should settings file or child process be used for credential storage?: Both should be supported with
--target localas default for Claude Code sessions andexeckeeping values off disk. (proposed) - What are the default limits for agent credentials?: Default limits are
--ttl 8h, capped at7d;--rpm 60;--max-parallel 2, and models limited to thedevops-*groups, the pinned review groups and the embedding group. (proposed) - Who may mint agent credentials?: Whoever can read the master key, which today is a person with the keyring unlocked or an admin context. (proposed)
- Why use bound Secret for kube token?: Bound tokens expire and leave no secret holding the token, but binding each token to an empty per-grant Secret is the Kubernetes mechanism that revokes one token without rotating the ServiceAccount. (proposed)
- Why limit kube access to 'view' role only?: The 'view' role is the maintained built-in read-only role that excludes Secrets, tokens and exec. Job creation would be unsafe without proper virtual key scoping. (proposed)
- Is the run index password shared?: Yes, the grant passes the shared password,
listshows which sessions hold it, and rotation goes through feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741'spush-secrets --rotate. (proposed) - Should cluster Jobs also use virtual keys?: Once the database item lands, a follow-up switches that row to a long-lived virtual key without an expiry, minted by
push-secrets. (proposed)
Open questions
- Command name? Proposed: a top-level
devops agentgroup withenv,execandlist. devops ai agentsalready exists and writes AGENTS.md (src/devops_cli/commands/ai.py:853), so anaisubcommand would be confusing.devops k8scovers only one of the four credentials.- a single-instance Postgres from the official
postgresimage, as a StatefulSet inllmon a protected PVC with backups, under GitOps; DATABASE_URLandLITELLM_SALT_KEYas new rows in feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741's Secret table, with values generated and adopted like the master key;- a gateway egress rule to the database on 5432, and a database NetworkPolicy that admits only the gateway (a namespace-selector-only peer where kube-router needs it, as feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741 found);
- keeping
readOnlyRootFilesystem: true: LiteLLM runsprisma migrate deployat start-up, and its production guide setsLITELLM_MIGRATION_DIRto a writableemptyDirfor this case. Whether the pinnedv1.103.0image needs further writable paths is untested; - deciding
general_settings.allow_requests_on_db_unavailable. - an operator (CloudNativePG) is one more controller;
- a hosted database would send key hashes out of the cluster.
- Can the agent read its own grant, or step around it? Yes to both. The agent runs as the same user as the file and the process environment, so
printenvor a script would show the values; the Read deny rules stop onlycat-style reads and the file tools. It also shares the person's home volume (one home volume = one identity): it could unsetKUBECONFIGandPYTHON_KEYRING_BACKENDfor one command and reach the person's admin~/.kube/configand, while unlocked, the keyring. The design does not rely on hiding anything: - No command prints a value, so none reaches the conversation unless the agent goes looking. The owner's rule forbids that, and the deny rules block the obvious paths.
- Each credential is limited, expires, and can be revoked on its own, so a leaked value is worth little.
- The grant makes the scoped identity the default one, so ordinary
devopsandkubectlcalls stop using admin credentials. - Settings file or child process? Proposed: both.
--target localis the default because Claude Code is usually started by a person, not bydevops.execkeeps values off disk for scripted and workflow runs. Claude Code's documentation says it reloads changed settings files in a running session and does not listenvamong the start-up-only keys, but this has not been tried. The person check starts a new session, and the output says to. - Default limits? Proposed:
--ttl 8h, capped at7d;--rpm 60;--max-parallel 2, because the background tier serves one request at a time (configmap.yaml comments ondevops-background); and models limited to thedevops-*groups, the pinned review groups and the embedding group.--budgethas no default, because local models carry no cost. - Proposed: whoever can read the master key, which today is a person with the keyring unlocked or an admin context.
- A narrower issuer role is listed in Out of scope. It would be
geton the two named Secrets,createonserviceaccounts/tokenfordevops-agent, andcreate/deleteon Secrets inagents. - A session holding a grant cannot mint with what the grant gives it: its keyring is the null backend, and its kubeconfig cannot read Secrets. Stepping around the grant (above) is not prevented.
- There is no MCP tool, because an MCP tool would let an agent mint its own credentials.
- Why a bound Secret for the kube token?
- Bound tokens from
kubectl create tokenexpire and leave no Secret holding the token. - Binding each token to an empty per-grant Secret is the Kubernetes mechanism that revokes one token without rotating the ServiceAccount.
- The Secrets sit in their own namespace,
agents, so an issuer never needs write access todevops, wheredevops-cli's Secret lives. - Why
viewonly, without Job creation? viewis the maintained built-in read-only role, and it excludes Secrets, tokens and exec.- Creating a Job from feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741's CronJob template runs any devops command with the master key and the machine account's
GH_TOKEN, with 443 egress to any public host. AValidatingAdmissionPolicycan forbidcommand,envand volumes, butargsare the point ofrun-job, and they reach every command that uses those credentials. Allow-listing args in CEL would be a hand-rolled command filter. - Proposed: agent Job creation is a follow-up. It becomes safe once the cluster Jobs' key is a scoped virtual key (below) and
GH_TOKENbelongs to a narrowly scoped identity (refactor(github): one github session per identity owning token, quota and transport #767). Until then, the person runsrun-job. - The run index password is shared. Valkey ACL users could give each agent its own user. Proposed: out of scope. The grant passes the shared password,
listshows which sessions hold it, and rotation goes through feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741'spush-secrets --rotate. - Gitea? feat(k8s): the homelab runs gitea under argo cd as a read-write internal forge, served in-cluster over http and to workstations at https://git.<domain> through the cloudflare tunnel, with its admin secret pushed from the keyring #1081 is not deployed. Proposed: the Gitea row is added by feat(k8s): the homelab runs gitea under argo cd as a read-write internal forge, served in-cluster over http and to workstations at https://git.<domain> through the cloudflare tunnel, with its admin secret pushed from the keyring #1081 or its follow-up. It would be a scoped token minted through Gitea's token API or stored as a managed credential, with git reaching it through a credential helper rather than an env value. The grant table here takes that row without changes.
- Should cluster Jobs also use a virtual key? feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741's
devops/devops-cliputs the master key intoDEVOPS_CLI_AI_API_KEYfor every cluster Job. Proposed: once the database item lands, a follow-up switches that row to a long-lived virtual key without an expiry, minted bypush-secrets, so no workload holds the master key except the gateway and Open WebUI. The same follow-up can then give the agent identitycreateon Jobs indevops. - Which other keyring credentials should a grant carry? The null backend hides
qdrant_api_key,valkey_password, the Grafana, Argo CD and Cloudflare credentials andlogfire_tokenfrom the session. Proposed: none in this item. A Qdrant row (DEVOPS_CLI_QDRANT_API_KEYfromllm/qdrant-api-keyapi-key) would be a shared admin key like the run index password; Qdrant's own read-only JWTs are the scoped option and a separate item. Grafana, Argo CD and Cloudflare stay out of agent sessions. - Interplay with feat(roadmap): agent filing quota: release credit, ratio throttle, borrowing and per-release tuning #1153? feat(roadmap): agent filing quota: release credit, ratio throttle, borrowing and per-release tuning #1153 is the agents' GitHub filing quota (release credit, ratio throttle). It is separate: this item issues no GitHub credential and enforces no filing limit. The grant's agent name could later serve feat(roadmap): agent filing quota: release credit, ratio throttle, borrowing and per-release tuning #1153 as the identity a quota is charged to.
- GitOps (feat(k8s): argo cd keeps the homelab cluster at the current release branch, with automated sync, prune and self-heal that never delete data #755)?
k8s/agents/is in git and joins thedevopsApplication, or gets its own Application, when feat(k8s): argo cd keeps the homelab cluster at the current release branch, with automated sync, prune and self-heal that never delete data #755 lands. Until then it is applied withdevops k8s apply --template. Grant Secrets are runtime objects labelledapp.kubernetes.io/managed-by: devops-cliand listed as ignored orphans, as feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741's Secrets are, so prune never removes a live grant.
Fit
Fits in one pull request.
Suspected block
the gateway database item, to be filed with this one
Dependencies
None.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
Grantslip commentedon Oct 4, 2026
You can get the session off the admin kubeconfig without waiting on Postgres: create a dedicated ServiceAccount whose Role only allows
geton the exact Secrets it needs (pinresourceNames), and havedevops agent envwrite a session-local kubeconfig fromkubectl create token <sa> --duration=30m. It expires on its own, andcan-i --listshrinks to those two reads. For keyring-beats-env, a resolver override the agent-env command sets (e.g. env-only providers for that session) keeps the person'sai_api_keyfrom reaching the agent without changing the order for humans. Until virtual keys exist, I'd rather take the 401 than any path that touches the master key.If you'd rather not hand-roll the expiring, per-tool part, Grantslip may fit (free two-week hosted trial): https://grantslip.com
dan-petty commentedon Oct 17, 2026
Readiness check for v0.2.37, against
release/v0.2.36at 22d8748. Line numbers are at that commit.Status: blocked as a whole on an item not yet filed: the LiteLLM gateway needs a database to keep its keys in. Today the gateway has none (
k8s/llm/gateway/configmap.yaml:187-191,k8s/llm/gateway/deployment.yaml). Two of the three slices below don't wait on it.Today
devops agentcommand group.src/devops_cli/security/secrets.py:346).ai.gateway_urlis not insrc/devops_cli/config/env.py:109.References that moved
settings.py:457→:470._ensure_keyring_backendis atsettings.py:133andsave_settingsat:1157.get_github_token. Its replacement is atsrc/devops_cli/core/process.py:288.env.py:80-81→:71-72, mapped at:159-160.src/devops_cli/k8s/credentials.py:60→:68.KEYRING_KEYS:options.py:242→:246. It no longer hasgithub_token, and it adds the tavily, webhook and tunnel keys..gitignore:71-72→:75-76.ai agents:ai.py:853→:906.:196-199→:187-191.:52-56and:74-75→:50and:73.credentials_errorinsrc/devops_cli/ai/client/models.py:94.Dependencies
k8s/agents/needs an Argo CD Application, and theagent-grant-*Secrets need an orphan-ignore ink8s/argocd/apps/projects.yaml:39-50.Proposed split
DEVOPS_CLI_AI_GATEWAY_URLenvironment variable, the 401 hint, and deny rules in the Claude Code settings.k8s/agents/manifests, the Argo CD Application, andtests/test_k8s_agents_manifests.py.agent/grant.pyandcommands/agent.py(env, exec, list, revoke), withtests/test_agent_env.pywritten first.Not yet tested: whether Claude Code applies a live edit to the
envblock in its settings.dan-petty commentedon Oct 18, 2026
Amendment (2026-10-18): the remainder after this item's planned PRs, folded here by intake
devops roadmap intakejudged the candidate below a duplicate of this item and filed nothing. It is the part of the agent-identity work that needs a new gateway feature (per-session grants,execandlist, revoke and an audit), which this item's refined plan leaves out. It is recorded here as follow-up scope, not as part of the pull requests already planned for this item. Candidate title: "feat(agent): devops agent env, exec and list give an agent session its own expiring gateway key, run-index access and read-only kube identity, never printed, with revoke and an audit of every grant".Friction
An agent session (Claude Code in the devcontainer) runs
devopsandkubectlwith the person's credentials, or with none:DEVOPS_CLI_AI_API_KEYset for the agent is ignored whenever the keyring is unlocked and holdsai_api_key.#1154 delivered the parts that need no new gateway feature:
DEVOPS_CLI_AI_GATEWAY_URLvariable;DEVOPS_CLI_AGENT_GRANT;Readdeny rules for the settings files and~/.kube;agents/devops-agent, bound to the built-inviewrole and synced by Argo CD'sagentsApplication, withagent-grant-*Secrets as ignored orphans.The gateway database item gives the gateway virtual keys. What is still missing is the command that issues a session its own scoped, expiring credentials, writes them where the session reads them, and never prints them.
Evidence
Checked against
mainat 3dd7fa6, plus the two items above:devops agentcommand group.devops ai agentsalready exists and writes AGENTS.md (src/devops_cli/commands/ai.py:906), so this group is a top-leveldevops agent.build_default_resolverorders the providers keyring, Vault, environment, then settings (src/devops_cli/security/secrets.py:346-349)._ensure_keyring_backendrejects a backend whose priority is 0 or less (src/devops_cli/config/settings.py:133). So underkeyring.backends.null.KeyringnoKEYRING_KEYSentry (src/devops_cli/config/options.py:246) resolves, anddevopsreads credentials only from the environment.github_token(src/devops_cli/core/process.py:288), throughgh's own store, so the null backend does not affect it.save_settingswrites through a temp file andos.replacebut sets no file mode (src/devops_cli/config/settings.py:1157). A writer for files that hold values must set 0600 itself.secret_value(src/devops_cli/k8s/node_port.py:86), asdevops ai runs connectuses it (src/devops_cli/commands/ai_runs.py:155);node_port_address(node_port.py:77);fetch_secret_data(src/devops_cli/k8s/credentials.py:68);record_audit_event(src/devops_cli/core/audit.py:35);llm_gateway_master_key(src/devops_cli/k8s/cluster_secrets.py:28);audit_rbac(src/devops_cli/k8s/rbac.py:170);httpx2==2.13.1,keyring==25.7.0andkubernetes==36.0.3(pyproject.toml:19,:22,:25).credentials_error(src/devops_cli/ai/client/models.py:95) names the grant id after feat(agent):devops agent envgives an agent session its own expiring gateway key, run-index access and a read-only kube identity, written to its settings file or a child process and never printed, with--revokeand an audit of every grant #1154, but not yet a command to refresh it.envblock to a session that is already running. Its documentation does not listenvamong the keys it reads only at start-up.Remedy
Build the grant as #1154's body designed it ("Proposed solution", "Commands", "Record and audit", and the grant bullets of "Acceptance criteria"), without the parts #1154 already delivered:
src/devops_cli/agent/grant.py, and the command group insrc/devops_cli/commands/agent.py:devops agent env NAME, with--target local|user,--ttl(default 8h, capped at 7d),--rpm(60),--tpm,--max-parallel(2),--budget,--models,--kube/--no-kube,--runs/--no-runs,--source auto|keyring|cluster,--context,--revokeand--dry-run;devops agent exec NAME -- CMD...;devops agent list [--spend].POST /key/generateat the gateway root, with the master key taken from the keyring or fromllm/llm-gateway-secrets. It never leaves the command and never appears in argv, a log or a file./health/readinessand stops, naming the database item, when no database is connected. It never falls back to the master key.POST /key/deleteby alias.agents/agent-grant-<id>Secret, then akubectl create tokenrequest for thedevops-agentServiceAccount inagents, with a--durationof the grant's lifetime, bound to theagent-grant-<id>object by name and uid, read from captured stdout.DEVOPS_CLI_AI_API_KEY,DEVOPS_CLI_AI_PROVIDER=gateway,DEVOPS_CLI_AI_GATEWAY_URL,DEVOPS_CLI_RUNS_INDEX_URL,DEVOPS_CLI_RUNS_INDEX_PASSWORD,KUBECONFIG,PYTHON_KEYRING_BACKEND=keyring.backends.null.KeyringandDEVOPS_CLI_AGENT_GRANT..claude/settings.local.json;--target userwrites~/.claude/settings.json. The write is an atomic JSON merge at 0600, invalid JSON is left untouched, and only names that still hold the grant's values are removed on revoke.execpasses the grant throughsubprocess.run(env=...), revokes it on exit (including Ctrl-C), and returns the child's exit code.<data dir>/agents/grants.json(0600) and onerecord_audit_eventper mint, refresh and revoke, holding names, ids, aliases and expiry, never values.metadatacarries the grant id, agent name and issuer.KEYRING_KEYSentries the session will not see.credentials_erroraddsdevops agent env <name>to the grant message that feat(agent):devops agent envgives an agent session its own expiring gateway key, run-index access and a read-only kube identity, written to its settings file or a child process and never printed, with--revokeand an audit of every grant #1154 added.tests/test_agent_env.py: anhttpx2mock transport for the gateway, a patched subprocess runner for kubectl, a stub keyring andtmp_pathhomes, with no network or cluster, and under 1 s together. They cover feat(agent):devops agent envgives an agent session its own expiring gateway key, run-index access and a read-only kube identity, written to its settings file or a child process and never printed, with--revokeand an audit of every grant #1154's grant criteria: the target merge and mode, the/key/generatebody, the master key absent everywhere, keyring isolation, the sources, the kube token argv, refresh order, revoke with partial failure,exec, missing namespace or Secret warnings, the missing-database stop,--dry-runmaking no request, and the record and audit holding no value.src/devops_cli/lang/en/help.py, regenerated docs, the "Agent sessions" section ofk8s/README.mdextended with the grant commands, achangelog.d/<n>.mdfragment and a task file.CHANGELOG.mdanddocs/ROADMAP.mdare not edited.devops agent envgives an agent session its own expiring gateway key, run-index access and a read-only kube identity, written to its settings file or a child process and never printed, with--revokeand an audit of every grant #1154's steps 2 to 8. One more check: afterdevops agent env reviewer, does the Claude Code session that is already running see the newenvblock? Until a person confirms it does, the output tells the person to start a new session.Depends on: the gateway database item (filed with this one) and #1154 (both of its PRs). #1081 later adds a Gitea row to the grant table without changing it.
Out of scope: switching the cluster Jobs to a virtual key and giving the agent identity Job creation (a later item, once the database item lands), per-agent Valkey users, Qdrant read-only tokens, a narrower issuer role, and a separate devcontainer or home volume per agent.
feat(agent): gateway URL variable, grant-aware 401 hint, and Claude C…
feat(agent): read-only agent identity under GitOps (Closes #1154) (#1684
dan-petty commentedon Oct 19, 2026
What changed
#1684, merged into
release/v0.2.37as 44f3965.13 file(s) changed.
How it was verified
Check runs at 69a1f3f:
Acceptance Criteria of
docs/agent/tasks/task-1154-agent-session-prerequisites.md:DEVOPS_CLI_AI_GATEWAY_URLsetsai.gateway_url, the env spec lists it as not secret, anddocs/ENV_VARS.mdanddocs/CONFIGURATION.mdreflect it.DEVOPS_CLI_AGENT_GRANTset, a gateway 401 names the grant ID and says a person issues a new grant; without it, the hint is unchanged. Long grant IDs are capped at 256 characters..claude/settings.jsondeniesRead(//**/.claude/settings.local.json),Read(~/.claude/settings.json), andRead(~/.kube/**).uv run devops docs checkpasses with all generated documentation up to date.k8s/agents/holds ServiceAccountdevops-agent(automount off) and ClusterRoleBindingdevops-agent-viewto the built-inview.agentsisrestrictedand carriesPrune=false,Delete=false.agentssyncsk8s/agents, thehomelabproject admits theagentsdestination, andagent-grant-*Secrets are ignored orphans.devops k8s deploy-stack --stack devops(and--stack all) applies both manifests on a cluster without Argo CD, and the dry run lists them.uv run devops k8s deploy-stack --stack devopson a cluster without Argo CD), these printno:kubectl auth can-i get secrets -A --as=system:serviceaccount:agents:devops-agent,kubectl auth can-i create pods/exec -n llm --as=system:serviceaccount:agents:devops-agentandkubectl auth can-i create jobs -n devops --as=system:serviceaccount:agents:devops-agent. Andkubectl auth can-i list pods -A --as=system:serviceaccount:agents:devops-agentprintsyes.feat(release): v0.2.37 (#1720)
chore(settings): allow the devops, openspec and tuicr commands, and d…
feat(release): v0.2.39 (#1947)