Skip to content

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

Closed

Description

@dan-petty

Problem

Agents run devops from the devcontainer, so every command that needs a credential reads it from the person's keyring (KEYRING_KEYS, src/devops_cli/config/options.py:242). For example, ai.api_key comes from keyring ai_api_key or from DEVOPS_CLI_AI_API_KEY (src/devops_cli/security/secrets.py:423).

Every model call from the workstation reaches the gateway through the Cloudflare route ai.<domain> (k8s/ingress/ingress-routes.yaml:59). That route sits behind the tunnel and Access (k8s/README.md:218, :249-254), and it cuts long calls at the edge at about 125 s. This is the owner's finding of 2026-10-03, on the path #1069 measures.

The owner decided on 2026-10-03 that:

  • devops-cli runs in the homelab cluster;
  • its credentials live in Kubernetes Secrets, which are encrypted at rest (homelab commit 550636f);
  • agents drive it with kubectl and never handle keys;
  • one devops-cli command, run from a shell with the keyring unlocked, creates and updates the cluster's Secrets, and devops k8s deploy-stack runs it automatically.

The roadmap service becomes one workload on this runtime (#1083).

At release/v0.2.25 (dcafadf; the current tip, 132ecc5, changes none of the lines cited here):

  • No image yet. feat(release): production service image for scheduled jobs and webhook handlers #753 adds ghcr.io/dan-petty/devops-cli/service:

    • ENTRYPOINT ["devops"], UID 1000;
    • HOME=/home/devops, DEVOPS_CLI_DATA_DIR=/home/devops/.data;
    • a read-only root filesystem, with gh and git installed.

    Its smoke test expects /tmp and /home/devops to be writable. GHCR may create the package as private on the first push (feat(release): production service image for scheduled jobs and webhook handlers #753).

  • Every Secret the stacks read is made by hand, or leaks on the way in. The manifests and values under k8s/ reference four Secrets, and no command writes three of them:

    • llm/llm-gateway-secrets (master-key): read by the gateway (k8s/llm/gateway/deployment.yaml:52-56) and by Open WebUI (openaiApiKeyExistingSecret, k8s/llm/values-open-webui.yaml:29-30). It is created with kubectl create secret generic … --from-literal (deployment.yaml:48-51, k8s/README.md:79-80).
    • llm/valkey-runs-auth (password): read by the run index (k8s/llm/valkey-runs.yaml:83-87), created with --from-literal (valkey-runs.yaml:9-11, k8s/README.md:69). devops ai runs connect then copies it cluster → keyring (runs_index_password, src/devops_cli/commands/ai_runs.py:155). It is not live on the homelab (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's read of 2026-10-03).
    • cloudflared/cloudflared-token (token): read by cloudflared (k8s/cloudflared/deployment.yaml:40-44), created with --from-literal (k8s/cloudflared/secret.example.yaml:3-6, k8s/README.md:258-263).
    • llm/qdrant-api-key (api-key): read by Qdrant (k8s/llm/values-qdrant.yaml:20-25). deploy-stack's _ensure_qdrant_api_key_secret (src/devops_cli/commands/k8s/stack_lifecycle.py:450) pipes a manifest to a client-side kubectl apply -f -. That copies stringData into the kubectl.kubernetes.io/last-applied-configuration annotation. When the Secret already exists, it copies the live key into the keyring instead (:464-469), so the keyring holds whichever cluster was deployed last.

    --from-literal puts the value in the process list and the shell history.

  • Chart-generated Secrets flow the other way. devops k8s sync-secrets (stack_lifecycle.py:801) copies cluster → keyring: Argo CD's argocd-initial-admin-secret, Grafana's chart Secret (grafana, since k8s/monitoring/grafana-values.yaml:27 sets adminPassword: "") and qdrant-api-key (src/devops_cli/k8s/credentials.py:561-586). deploy-stack runs the same sync after installing (_post_deploy_credentials, stack_lifecycle.py:647).

  • deploy-stack's order (stack_lifecycle.py:695-798): cluster check; kubectl apply -k k8s/ (namespaces, cloudflared, registry, :770-772); Helm repos; the stack's raw manifests (:778), which include the gateway Deployment; then each Helm release, with Qdrant's Secret ensured just before its release (:604-612). It also runs from devops k8s bootstrap (src/devops_cli/commands/k8s/bootstrap.py:62), from the devcontainer's auto-deploy (src/devops_cli/commands/devcontainer.py:960-972) and from the MCP tool k8s_deploy_stack (src/devops_cli/ai/mcp/server.py:313).

    • The auto-deploy passes the stack as a positional argument (devops k8s deploy-stack infra, devcontainer.py:964), but deploy-stack only takes --stack, so that call fails today.
    • The auto-deploy runs at post-start, when DEVOPS_K8S_AUTO_DEPLOY is set (devcontainer.py:1146; the template sets it, templates/devcontainer.json.j2:44). The keyring is unlocked later, by a hook in the first interactive shell (devcontainer.py:750-761), so the auto-deploy can run while the keyring is still locked.
    • _ensure_qdrant_api_key_secret is re-exported from src/devops_cli/commands/k8s/__init__.py (:80, :140). Its helper fetch_qdrant_api_key (src/devops_cli/k8s/credentials.py:187) has one other caller, sync_k8s_credentials (:584).
  • Consumers read their Secret only at start. Every reference above is an env secretKeyRef. Open WebUI uses the gateway key only on its first start and keeps the connection in its database afterwards (k8s/llm/values-open-webui.yaml:24-26, k8s/README.md:129).

  • The keyring hides a locked state. _keyring_get returns None when the keyring is locked or has no backend, the same as for a missing entry (src/devops_cli/config/settings.py:666-685). Without a usable backend, or with DEVOPS_CLI_HEADLESS_AUTH, _keyring_set writes to an in-memory store (:710-727), so a value generated then would be lost when the process exits.

  • No way to store a credential without argv. devops config set KEY VALUE takes the value as an argument (src/devops_cli/commands/config.py:184-188). Only config init prompts with hidden input (:247).

  • The machine account's token.

  • kubectl alone cannot run an arbitrary devops command safely.

    • kubectl create job --from=cronjob/<name> copies a CronJob's template but cannot change its args.
    • kubectl run and kubectl create job --image set no security context, so a restricted namespace rejects them.
  • In-cluster gateway.

    • It is http://llm-gateway.llm.svc.cluster.local:4000/v1 (k8s/llm/gateway/service.yaml). Its policy admits any source on 4000 (k8s/llm/gateway/networkpolicy.yaml:18-24).
    • With provider gateway, the client refuses a URL that resolves to a private address unless ai.allow_private_network is true. That setting defaults to false (src/devops_cli/config/settings.py:464).
    • The default provider is ollama (src/devops_cli/config/defaults.py:63).
  • kube-router. On this cluster, kube-router refused an egress rule that pairs a namespace+pod selector peer with ports: (k8s/cloudflared/networkpolicy.yaml:44-48). A namespace-selector-only peer with ports: works: Prometheus reaches llm that way (k8s/monitoring/networkpolicy.yaml:102-116). Blocked connections fail as "connection refused" (fix(k8s): cloudflared egress NetworkPolicy silently blocks Traefik traffic #725).

  • Deploy paths.

  • Release tooling.

    • devops release prepare bumps pyproject.toml and __init__.py (src/devops_cli/commands/release.py:747-757), and _verify_release_versions (:1215) compares them.
    • The cut stages only _release_paths (:522-537): pyproject.toml, __init__.py, CHANGELOG.md, README.md, docs/ and changelog.d/. A file the bump edits outside that list is not committed.
  • Policy tests. tests/test_k8s_network_policies.py checks each namespace in TARGET_NAMESPACES (:16).

Proposed solution

A devops namespace under k8s/devops/ holds the in-cluster devops-cli:

  • a config;
  • a suspended CronJob devops-cli, the template for every cluster job;
  • a service account with no API token;
  • a default-deny perimeter.

One Secret, devops-cli, holds its credentials under environment-variable names and reaches every pod through envFrom.

Two commands:

  • devops k8s push-secrets (workstation → cluster) writes every Secret the stacks need from the OS keyring. One table, held as data, says for each Secret key where its value comes from, whether it is required, and whether a value may be generated. It server-side applies from stdin and restarts the workloads whose Secret changed. devops k8s deploy-stack runs the same code for the stacks it deploys, before their manifests and Helm releases.
  • devops k8s run-job -- <devops args> creates a Job from the CronJob's template with only the args changed, follows its log, and exits with the container's exit code.

devops config set KEY prompts with hidden input for a credential.

Scope

k8s/devops/. It is applied with devops k8s apply k8s/devops/ --template until #755's devops Application syncs it. It is not in the root kustomization.

  • namespace.yaml: devops, with Pod Security restricted for enforce, warn and audit (as k8s/namespaces.yaml:30-32). It carries argocd.argoproj.io/sync-options: Prune=false,Delete=false (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).

  • serviceaccount.yaml: devops-cli, automountServiceAccountToken: false, no Role.

  • configmap.yaml: devops-cli-config, key devops-cli.yaml. It sets:

    • ai.provider: gateway;
    • ai.gateway_url: http://llm-gateway.llm.svc.cluster.local:4000/v1;
    • ai.allow_private_network: true;
    • the task models.

    It holds no credential.

  • cronjob.yaml: CronJob devops-cli, suspend: true.

    • jobTemplate: backoffLimit: 0, ttlSecondsAfterFinished: 86400, activeDeadlineSeconds: 7200, restartPolicy: Never, serviceAccountName: devops-cli.
    • Pod and container security context as in k8s/llm/gateway/deployment.yaml:22-39.
    • One container, devops-cli: image ghcr.io/dan-petty/devops-cli/service, args ["--version"], envFrom: [{secretRef: {name: devops-cli}}].
    • Env: DEVOPS_CLI_CONFIG=/config/devops-cli.yaml and DEVOPS_CLI_DATA_DIR=/home/devops/.data.
    • Volumes: an emptyDir on /tmp and on /home/devops; the ConfigMap read-only on /config.
    • Requests 100m CPU / 256Mi; limits 1 CPU / 1Gi.
  • networkpolicy.yaml: devops-default-perimeter, podSelector: {}, both policyTypes, no ingress rule. Egress goes to:

    • DNS;
    • namespace llm (namespaceSelector only, no podSelector) on TCP 4000, the shape the monitoring policy already uses (k8s/monitoring/networkpolicy.yaml:102-116);
    • TCP 443 to 0.0.0.0/0 except 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 and 169.254.169.254/32.
  • kustomization.yaml: the resources above, and images: for ghcr.io/dan-petty/devops-cli/service with newTag: v0.2.26, the first release that publishes the image.

The Secret table (src/devops_cli/k8s/cluster_secrets.py), held as data: frozen dataclasses, one per Secret, each with namespace, name, stack, labels, its entries and the workloads that read it. An entry has a key, a source (a keyring key, the gh account, a non-secret setting, or a literal for non-secret keys such as a URL), required or optional, an optional generator (secrets.token_hex or token_urlsafe, with a prefix), and the Secret key a missing keyring value may be adopted from (its own key by default). This item's rows:

Secret Key Source Required When the keyring has no value Stack Restarted when it changes
llm/llm-gateway-secrets master-key keyring llm_gateway_master_key (new) yes adopt the live value; else generate sk- + 48 hex llm deployment/llm-gateway
llm/qdrant-api-key api-key keyring qdrant_api_key (qdrant.api_key) yes adopt; else generate (token_urlsafe(32), as stack_lifecycle.py:471 does today) llm statefulset/qdrant
llm/valkey-runs-auth password keyring runs_index_password (runs.index_password) yes adopt; else generate 64 hex llm deployment/valkey-runs
cloudflared/cloudflared-token token keyring cloudflare_tunnel_token (new credential cloudflare.tunnel_token) no adopt; else skip the key with a warning base deployment/cloudflared
devops/devops-cli GH_TOKEN gh's keyring, account --github-account, else setting k8s.github_account yes fail devops none (each Job reads it at start)
devops/devops-cli DEVOPS_CLI_AI_API_KEY keyring llm_gateway_master_key yes adopt from llm/llm-gateway-secrets master-key; never generated here devops none

devops k8s push-secrets [--stack STACK] [--only NS/NAME]... [--github-account LOGIN] [--rotate] [--restart/--no-restart] [--context CTX] [--dry-run]

  • Selection. --stack is a stack the table names (base, infra, llm, logging, devops, and those later items add, such as gitea) or all (the default). --only NS/NAME is repeatable and replaces --stack; an unknown name exits 2 and lists the table's names. Only the selected Secrets' sources are read.

  • Keyring first. Before any read, the command checks that the keyring has an encrypted backend, is unlocked, and is not the in-memory store. Otherwise it exits 1 with nothing read or written: a locked keyring names devops devcontainer unlock-keyring, and no backend names the missing backend. Keyring reads in this command raise on a locked keyring instead of returning None.

  • Plan, then write. For each selected entry it resolves the value in memory:

    1. The keyring has it, and the live key is absent or equal: create, or leave unchanged.
    2. The keyring has it, and the live key differs: without --rotate the command exits 1 before writing anything, naming each such NS/NAME key and both ways on (--rotate, or delete the keyring entry to adopt the live value). With --rotate the keyring value replaces it.
    3. The keyring lacks it, and the live Secret (the entry's adopt-from key) has it: adopt it into the keyring.
    4. Neither has it: generate it if the entry has a generator. Otherwise a required entry fails and an optional one is skipped with a warning naming the key and the command that stores it.

    The live values are read once per selected Secret with the existing fetch_secret_data (credentials.py:60). A missing namespace skips that Secret with a warning under --stack, and fails under --only. The namespaces are checked before any source is resolved, so a skipped Secret's sources are neither read nor required: on a cluster without devops, a bare push-secrets needs no GitHub account.

  • Failures. Every missing required source is listed in one message naming its keyring key, option, or --github-account and k8s.github_account, and nothing is written. Otherwise adopted and generated values are stored in the keyring first, and then the cluster is written.

  • gh account. GH_TOKEN is read with gh auth token --hostname github.com --user LOGIN in an environment without GH_TOKEN, GITHUB_TOKEN and DEVOPS_CLI_GITHUB_TOKEN. run_subprocess puts those back into every gh call (_inject_gh_credentials, src/devops_cli/core/process.py:206-215, called at :248), so this call opts out of that injection. One GET /user then confirms that the login equals LOGIN. A missing account, or gh keeping LOGIN's token in its config file instead of the keyring, fails like any required source.

  • Validation. master-key and DEVOPS_CLI_AI_API_KEY must start with sk- (LiteLLM's rule, deployment.yaml:48-49); a keyring value without it fails naming the key.

  • Apply. All selected Secrets go as one v1 List, built as a dict and serialised with json.dumps, on stdin to kubectl apply --server-side --field-manager=devops-cli --force-conflicts -f -, with -o jsonpath printing only namespace, name and resourceVersion.

    • Values go in data, base64-encoded with the standard library, not in stringData. With data, the field manager owns exactly the stored keys. stringData is write-only and folded into data by the API server, so whether server-side apply would remove a dropped key is unclear (untested); data avoids the question, and the person check confirms the ownership.
    • A value is never in argv, a file, an annotation, a log record or the command's output.
    • Keys the table drops are removed on the next push, unless another field manager also owns them (for example a key first written by kubectl create, whose value equals the pushed one).
  • Leaked copies. A selected Secret that carries kubectl.kubernetes.io/last-applied-configuration has it removed with kubectl annotate secret NAME -n NS kubectl.kubernetes.io/last-applied-configuration-. This is the copy the old Qdrant path left. It was readable only by those who can read the Secret, so the key needs no rotation.

  • Restarts. For each Secret that already existed and whose data changed (a key added, changed or removed), the command runs kubectl rollout restart on its listed workloads that exist. A newly created Secret restarts nothing: a pod waiting on it starts once it exists. An added key does count, because envFrom starts a pod without a missing key. --no-restart prints those commands instead. A changed gateway key prints that Open WebUI keeps its stored connection (k8s/README.md:129).

  • Empty Secrets. A Secret whose every key is skipped is not applied, so no empty Secret is created.

  • Output. One line per Secret: namespace/name, then each key with its source and state (created, unchanged, adopted, generated, rotated, skipped), and the restarted workloads. Never a value.

  • --dry-run reads the keyring and, with kubectl get only, the live Secrets. It prints the same lines as would …, writes nothing to the keyring or the cluster, and restarts nothing.

  • The help string says the direction: workstation keyring → cluster, the reverse of sync-secrets.

deploy-stack

  • After kubectl apply -k k8s/ (namespaces) and before the Helm repos, raw manifests and Helm releases, deploy-stack pushes:

    • the base rows and those of its selected stacks;
    • the rows of stacks deploy-stack never deploys (devops, and later gitea) when the namespace of the same name exists. So once k8s/devops/ is applied, every deploy-stack run also creates or updates devops/devops-cli.

    It calls the same function as push-secrets, with --stack semantics, no --rotate and restarts on.

    • A failure (locked keyring, a missing required source, a differing live value) exits 1 before any manifest or Helm release is applied.
    • The cloudflared Deployment from the root kustomization waits in CreateContainerConfigError for the few seconds until its Secret exists.
  • --push-secrets/--no-push-secrets (default on) skips the push, for a minikube with no keyring.

  • --dry-run adds the Secrets and their key names, from the table alone, to its details; the devops and later rows are listed as pushed only if their namespace exists.

  • _ensure_qdrant_api_key_secret, its re-exports and the Qdrant special case in _install_single_release (stack_lifecycle.py:604-612) are removed. _post_deploy_credentials and sync_k8s_credentials stop copying qdrant-api-key back to the keyring, fetch_qdrant_api_key goes with its last caller, and sync-secrets lists only Argo CD and Grafana. No Secret in the table is copied cluster → keyring.

  • Callers.

    • The devcontainer auto-deploy passes --stack STACK instead of the positional argument (devcontainer.py:964). If the push fails because the keyring is still locked at post-start, its warning names devops devcontainer unlock-keyring and then devops k8s deploy-stack --stack STACK.
    • devops k8s bootstrap and the MCP tool k8s_deploy_stack keep the push on. A locked keyring makes them exit 1 with the unlock hint, and nothing is applied.
  • 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 adds the Argo CD case: when Application cluster exists, deploy-stack pushes the same rows and then applies nothing else, saying so.

devops k8s run-job [--context CTX] [--wait/--no-wait] [--start-timeout SECONDS] [--dry-run] -- ARGS...

  • It reads kubectl -n devops get cronjob devops-cli -o json.
  • It builds a Job from .spec.jobTemplate that changes only:
    • container devops-cli's args, set to ARGS;
    • the name, devops-cli-<UTC yyyymmdd-hhmmss>-<4 hex>;
    • the label app.kubernetes.io/name: devops-cli-job.
  • It creates the Job with kubectl create -f -.
  • --wait (the default) waits up to 120 s for the pod to leave Pending, streams kubectl logs -f job/<name>, and exits with state.terminated.exitCode. A pod that never starts exits 1 naming kubectl -n devops describe job/<name>.
  • --no-wait prints the Job name and the kubectl -n devops logs -f job/<name> command.
  • A missing CronJob exits 1 naming devops k8s apply k8s/devops/ --template.
  • --dry-run prints the Job and creates nothing.

Other changes

  • devops config set KEY without VALUE prompts with hidden input when KEY is in SECRET_CONFIG_OPTIONS. A non-credential key still requires VALUE.
  • The --from-literal instructions go: k8s/README.md:67-69, :79-80 and :258-263, the comments at k8s/llm/gateway/deployment.yaml:48-51 and k8s/llm/valkey-runs.yaml:9-11, and k8s/cloudflared/secret.example.yaml (deleted, with its README tree line :292). Each place names devops k8s push-secrets instead.
  • devops release prepare sets the kustomization's newTag to v<version>, in a step after __init__.py (release.py:753-757; fix(release): one fail-closed release path: cut branch from the remote release tip, uv.lock bump, draft flag, required label and milestone #982 then moves the step with the bump block).
  • _release_paths (release.py:522) gains k8s/devops/kustomization.yaml.
  • devops release check fails when the tag and the version differ.
  • Help strings go in lang/en/help.py, and the docs are regenerated. There is no new MCP tool; the existing k8s_deploy_stack tool pushes through deploy-stack and prints only key names.
  • A k8s/README.md section, "devops-cli in the cluster", gives the steps of the person checks. A "Cluster Secrets" section lists the table (generated from it by devops docs, or checked against it by a test) and the rotation steps.
  • changelog.d/741.md; task file docs/agent/tasks/task-741-devops-cli-in-cluster.md. CHANGELOG.md and docs/ROADMAP.md are not edited.

Acceptance criteria

In the gate. No network and no cluster: a patched subprocess runner, a stub keyring and structural tuple assertions. Together under 1 s, measured with uv run pytest tests/test_k8s_devops_runtime.py tests/test_k8s_push_secrets.py tests/test_k8s_run_job.py tests/test_k8s_qdrant_security.py --durations=0.

  • Manifests (tests/test_k8s_devops_runtime.py):
    • The namespace is restricted and carries the sync-options annotation. The SA has automount off.
    • The CronJob is suspended, with backoffLimit 0, TTL 86400, deadline 7200 and container devops-cli.
    • The security context is runAsNonRoot, readOnlyRootFilesystem, no privilege escalation, drop: [ALL] and RuntimeDefault.
    • There is exactly one envFrom secretRef, devops-cli. No env entry has a literal value for GH_TOKEN, GITHUB_TOKEN or any env name of SECRET_CONFIG_OPTIONS.
    • The emptyDir mounts are /tmp and /home/devops, and DEVOPS_CLI_DATA_DIR starts with /home/devops.
    • The ConfigMap validates as Settings with provider gateway, the in-cluster URL, allow_private_network is True and no credential field.
    • The NetworkPolicy has no ingress rule. Its egress is exactly: DNS; a peer that is only a namespaceSelector for llm, on TCP 4000; and 443 with the four excepts.
    • The kustomization lists every manifest and carries images:. The root k8s/kustomization.yaml leaves devops out.
  • Policy suite. devops joins TARGET_NAMESPACES (tests/test_k8s_network_policies.py:16). uv run pytest tests/test_k8s_network_policies.py -k devops passes.
  • Secret table (tests/test_k8s_push_secrets.py):
    • It holds exactly this item's six entries in five Secrets, with the stacks, required flags, generators and restart targets above.
    • Every Secret named by a secretKeyRef, a secretRef or an *existingSecret* value (matched case-insensitively, so Open WebUI's openaiApiKeyExistingSecret counts) under k8s/ (manifests and values files) has a table row. A test fails on a reference without one, so a new consumer cannot ship without its row.
    • Every keyring source is either a KEYRING_KEYS value or one of the table's keyring-only keys, and the two sets are disjoint.
    • Every env-name key of devops/devops-cli equals OPTION_TO_ENV_VAR of the option it feeds (ai.api_key for DEVOPS_CLI_AI_API_KEY, although its source is llm_gateway_master_key).
    • Every restart target is a workload in a k8s/ manifest or a release in _HELM_RELEASES_BY_STACK.
    • cloudflare.tunnel_token is in SECRET_CONFIG_OPTIONS, KEYRING_KEYS, the env spec and build_secret_registry.
    • No Secret name in the table is one that sync_k8s_credentials reads.
  • push-secrets (same file):
    • Apply. One kubectl apply call, whose argv carries --server-side, --field-manager=devops-cli, --force-conflicts and -f -. Its stdin is a List whose Secrets have data keys equal to the table's, no stringData, no annotations, and the managed-by label.
    • Resolution.
      • A keyring value with no live Secret is created.
      • An equal live value is reported unchanged and restarts nothing.
      • A key added to an existing Secret restarts its workloads once; a newly created Secret restarts nothing.
      • A missing keyring value with a live one is adopted: it is stored in the keyring, and the live value is unchanged.
      • With neither, a generator stores the value in the keyring before the apply call, and the gateway key starts with sk-.
    • Rotation. A differing live value without --rotate exits 1, naming NS/NAME key and --rotate, with no keyring write and no apply. With --rotate, it is applied and each listed workload gets one kubectl rollout restart. --no-restart prints the commands and runs none.
    • Missing sources. A missing required source exits 1 naming every missing key, with no keyring write and no apply. A missing optional one prints a warning naming cloudflare.tunnel_token; since it is that Secret's only key, cloudflared-token is left out of the List.
    • Keyring. A locked keyring (the stub raises KeyringLocked) exits 1 with the unlock hint. So do no backend and DEVOPS_CLI_HEADLESS_AUTH. In each case no kubectl command runs and nothing is written.
    • Selection. --only llm/qdrant-api-key applies one Secret and reads only qdrant_api_key. An unknown --only exits 2. --stack devops reads gh and llm_gateway_master_key only. A missing namespace skips its Secret under --stack, and fails under --only. With no devops namespace, a bare push-secrets with neither --github-account nor k8s.github_account exits 0 and never calls gh.
    • gh. The env handed to subprocess.run for gh auth token (after run_subprocess builds it) has no GH_TOKEN, GITHUB_TOKEN or DEVOPS_CLI_GITHUB_TOKEN, even when the test sets all three in os.environ. The account comes from --github-account, else from k8s.github_account; with devops present and neither set, the command exits 1 naming both. A /user login mismatch exits 1 and applies nothing.
    • Leaked annotation. A live Secret with kubectl.kubernetes.io/last-applied-configuration gets one kubectl annotate … last-applied-configuration- call; one without it gets none.
    • No value anywhere. No recorded argv, log record (caplog), stdout or stderr contains any test value.
    • --dry-run runs only kubectl get, writes nothing to the keyring, and prints key names and states, no value.
  • deploy-stack (tests/test_k8s_qdrant_security.py, rewritten, and tests/test_k8s.py):
    • With --stack llm, the recorded calls are in this order: kubectl apply -k, the server-side apply of the base and llm Secrets, the raw manifests, then Helm.
    • With --stack infra, only the base rows are pushed when the stubbed kubectl get namespace devops fails. When it succeeds, devops/devops-cli is pushed too, with the account from k8s.github_account.
    • A push failure exits 1, and no manifest or Helm command runs.
    • --no-push-secrets pushes nothing.
    • --dry-run details list the Secret names and keys and run nothing.
    • _ensure_qdrant_api_key_secret and fetch_qdrant_api_key no longer exist, and sync_k8s_credentials(stack="llm") reads no Secret.
    • The devcontainer auto-deploy runs devops k8s deploy-stack --stack infra (tests/test_devcontainer.py), and a failed run's warning names devops devcontainer unlock-keyring.
  • No --from-literal. git grep -n -- --from-literal k8s/ finds nothing, and k8s/cloudflared/secret.example.yaml is gone.
  • run-job:
    • From a fixture CronJob, the created Job equals the jobTemplate except args, name and label.
    • Terminated exitCode 3 makes the command exit 3.
    • --no-wait creates the Job and prints its name.
    • --dry-run creates nothing.
    • A missing CronJob exits 1 with the apply hint.
  • config set. config set ai.api_key with input x\n stores the value through _keyring_set and never echoes x. config set ai.model without a value exits 2. Test: tests/test_config_commands.py.
  • Release tag. In tests/test_release.py, next to test_release_check_version_mismatch (:220):
    • A tmp_path test runs release prepare's bump and asserts newTag == "v<version>".
    • _release_paths(tmp_path) contains k8s/devops/kustomization.yaml.
    • With the tag out of step, release check exits 1.
  • uv run devops k8s --help lists push-secrets and run-job, and uv run devops docs check passes.
  • The PR adds changelog.d/741.md and edits neither CHANGELOG.md nor docs/ROADMAP.md, so devops pr check-readiness passes.
  • uv run devops ci passes within its 5-minute budget.

Pending a person (context homelab-k3s, keyring unlocked):

  • Machine account in gh's keyring:
    1. Run gh auth login --hostname github.com as the machine account: a classic token with scopes repo and project, expiring within a year.
    2. Run gh auth switch --hostname github.com --user <owner-login>.
    3. gh auth status --hostname github.com lists both accounts with (keyring).
  • First push, which adopts the live values:
    1. uv run devops k8s apply k8s/devops/ --template --context homelab-k3s.
    2. uv run devops config set k8s.github_account <machine-login>.
    3. uv run devops k8s push-secrets --context homelab-k3s --dry-run shows:
      • llm-gateway-secrets, qdrant-api-key and cloudflared-token as would adopt or unchanged;
      • valkey-runs-auth as would generate (it is not live);
      • devops-cli as would create;
      • no value, and no differs. The old deploy-stack copied each cluster's Qdrant key into the keyring, so if qdrant-api-key shows differs, the keyring holds the minikube key: delete that keyring entry with uv run keyring del devops-cli qdrant_api_key and run the dry run again, which then shows would adopt.
    4. The same without --dry-run exits 0 and restarts nothing.
    5. kubectl --context homelab-k3s get secret -A -l app.kubernetes.io/managed-by=devops-cli -o custom-columns=NS:.metadata.namespace,NAME:.metadata.name lists the five Secrets.
    6. kubectl --context homelab-k3s -n devops get secret devops-cli -o go-template='{{range $k, $v := .data}}{{$k}}{{"\n"}}{{end}}' prints exactly DEVOPS_CLI_AI_API_KEY and GH_TOKEN.
    7. kubectl --context homelab-k3s -n llm get secret qdrant-api-key -o jsonpath='{.metadata.annotations}' shows no kubectl.kubernetes.io/last-applied-configuration, and its .metadata.managedFields[*].manager includes devops-cli.
    8. A second run reports every key unchanged.
    9. curl with the gateway key still answers /v1/models (k8s/README.md:84-85), and kubectl --context homelab-k3s -n cloudflared get deploy cloudflared stays Available.
  • Keyring locked: with the keyring locked, uv run devops k8s push-secrets --context homelab-k3s exits 1 naming devops devcontainer unlock-keyring. kubectl --context homelab-k3s -n llm get secret qdrant-api-key -o jsonpath='{.metadata.resourceVersion}' is unchanged.
  • deploy-stack on the homelab: uv run devops k8s deploy-stack --stack infra --context homelab-k3s --dry-run lists cloudflared/cloudflared-token and, since namespace devops exists, devops/devops-cli, with key names only.
  • deploy-stack on minikube: on a fresh minikube, uv run devops k8s deploy-stack --stack llm --context minikube creates llm-gateway-secrets and qdrant-api-key before the gateway Deployment and Qdrant, and kubectl --context minikube -n llm rollout status deploy/llm-gateway --timeout=180s succeeds.
  • Image before v0.2.26 ships:
    1. docker build -t ghcr.io/dan-petty/devops-cli/service:pr-741 . && docker push ghcr.io/dan-petty/devops-cli/service:pr-741, with a token that has write:packages.
    2. In the package settings, make the GHCR service package public (needed once).
    3. DOCKER_CONFIG=$(mktemp -d) docker pull ghcr.io/dan-petty/devops-cli/service:pr-741 succeeds without a login.
    4. kubectl --context homelab-k3s -n devops set image cronjob/devops-cli devops-cli=ghcr.io/dan-petty/devops-cli/service:pr-741.
  • Cluster jobs:
    • uv run devops k8s run-job --context homelab-k3s -- --version prints devops-cli 0.2. and exits 0.
    • uv run devops k8s run-job --context homelab-k3s -- ai gateway status --format json prints "gateway_url": "http://llm-gateway.llm.svc.cluster.local:4000/v1" and "healthy": true.
    • uv run devops k8s run-job --context homelab-k3s -- gh rate-limit exits 0.
    • uv run devops k8s run-job --context homelab-k3s -- no-such-command; echo $? prints 2.
    • kubectl --context homelab-k3s -n devops get pods -l app.kubernetes.io/name=devops-cli-job -o jsonpath='{.items[0].spec.volumes[*].name}' names no kube-api-access-* volume.

Constraints

  • Credential values never appear in argv, files, annotations, logs or command output.
  • A locked or unavailable keyring, a missing required source or a differing live value stops the run before anything is written to the keyring or the cluster.
  • A live credential is never replaced without --rotate.
  • Cluster jobs hold no Kubernetes API token and accept no ingress.
  • New in-gate tests cost under 1 s together.

Key questions

Out of scope

Strategic alignment

Activity

  1. added this to the v0.2.25 milestone on Sep 30, 2026
  2. added
    type/feature
    scope/k8s
    priority/p1-high
    on Sep 30, 2026
  3. modified the milestones: v0.2.25, v0.2.26 on Sep 30, 2026
  4. changed the title [-]feat(k8s): scheduled roadmap runner (`devops roadmap run`) as a homelab cronjob[/-] [+]feat(k8s): deploy the roadmap service to the homelab (`devops roadmap run`)[/+] on Sep 30, 2026
  5. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Note from refining #913 (2026-10-02, now in v0.2.29). #913 adds a guard test that every namespace the stack deploys has a default-deny perimeter, with exemptions keyed by (namespace, policy name). This item adds k8s/roadmap/networkpolicy.yaml outside the root kustomization, but its body does not name the NetworkPolicy. Proposed: name it roadmap-default-perimeter, so #913's guard can list it whichever item lands first.

  6. changed the title [-]feat(k8s): deploy the roadmap service to the homelab (`devops roadmap run`)[/-] [+]feat(k8s): devops-cli runs in the homelab cluster, with its credentials pushed from the keyring into one Secret and any command run as a Job (devops k8s push-secrets, devops k8s run-job)[/+] on Oct 3, 2026
  7. changed the title [-]feat(k8s): devops-cli runs in the homelab cluster, with its credentials pushed from the keyring into one Secret and any command run as a Job (devops k8s push-secrets, devops k8s run-job)[/-] [+]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)[/+] on Oct 3, 2026
  8. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Broadened by the owner's decisions of 2026-10-03: this item is now the in-cluster runtime (devops namespace, any command as a Job with devops k8s run-job), right after #753 in v0.2.26. devops k8s push-secrets now writes every cluster Secret from the unlocked keyring (gateway, Qdrant, run index, tunnel, devops-cli, and later Grafana and Gitea), and devops k8s deploy-stack runs it before applying anything, also once Argo CD manages the cluster. It replaces the hand --from-literal steps and deploy-stack's Qdrant step, which leaked the key into the last-applied annotation. The roadmap service's Deployment, PVC, Ingress and scrape path moved to #1083 (one issue per PR); devops-default-perimeter supersedes the policy name proposed on 2026-10-02.

  9. dan-petty commented on Oct 4, 2026

    @dan-petty
    OwnerAuthor

    Closed by #1161, merged into release/v0.2.26.

    GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by devops gh issues close-merged.

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

    priority/p1-highscope/k8stype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions