Skip to content

fix(cli): devcontainer auto-deploy reaches the keyring and the Minikube it started, or is dropped for a printed deploy-stack command #1368

Closed

Description

@dan-petty

Problem

The owner split this out of #868 on 2026-10-08. Checked on release/v0.2.29 at 910b823.

devops devcontainer bootstrap-k8s deploys by default (--deploy/--no-deploy, src/devops_cli/commands/devcontainer.py:1670-1672), and this repository's devcontainer sets DEVOPS_K8S_AUTO_DEPLOY=true (.devcontainer/devcontainer.json:44). #741 (v0.2.26) fixed the argv: _auto_deploy_k8s_stack now runs ["devops", "k8s", "deploy-stack", "--stack", stack] (commands/devcontainer.py:962-978). The call still cannot deploy anything:

  1. The child never reaches the keyring. _auto_deploy_k8s_stack calls run_subprocess with its default isolate_env=True (core/process.py:357). The env allowlist (DEFAULT_ALLOWED_ENV_VARS, core/process.py:45-96) drops DBUS_SESSION_BUS_ADDRESS and XDG_RUNTIME_DIR. Measured in the devcontainer, with the parent connected to a session bus: build_subprocess_env() holds neither key, and a Python child started with that env gets keyring.backends.fail.Keyring. deploy-stack runs require_keyring_for_push() before it checks the cluster (commands/k8s/stack_lifecycle.py:1032-1037). With the fail backend it stops with no encrypted OS keyring backend is available (found keyring.backends.fail.Keyring) ... (config/settings.py:824), even when the keyring is unlocked. The code already re-allows the bus for gh children: CONST_GH_LOGIN_ENV_VARS (config/constants.py:1006-1008) and _GH_ENV (k8s/secret_push.py:50, passed at :325).
  2. No --context. bootstrap-k8s starts Minikube and runs minikube update-context (commands/devcontainer.py:994-1006). deploy-stack, though, gets no --context, so it resolves the configured k8s.context (resolve_effective_context, commands/k8s/cluster_runtime.py:134-144), and the config reaches the child through the DEVOPS_CLI_ prefix the allowlist keeps (core/process.py:97-98). Post-start spawns the bootstrap by default only when that context is minikube (should_autostart_minikube, cluster_runtime.py:110-131), so on that path both agree. A hand-run bootstrap-k8s --stack <stack> --deploy, or post-start with DEVOPS_MINIKUBE_AUTOSTART=true, deploys to whatever context is configured. Post-start step 9 deliberately realigns kubectl to that configured context (_apply_configured_k8s_context, devcontainer.py:1196-1200). Where it is an Argo-managed cluster, a deploy that got past the keyring would push Secrets and write Argo overrides there (_handle_argo_managed_deployment, stack_lifecycle.py:902-922), and Minikube would stay empty.
  3. Post-start spawns the bootstrap before the session bus starts. _run_post_start_lifecycle spawns it at devcontainer.py:1148-1161 and starts the D-Bus session bus later, at :1191-1194. The keyring is also normally locked until a person unlocks it. Since 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, a locked keyring stops deploy-stack before it touches the cluster, so an unattended post-start deploy stops at that gate in the normal case.

The failure is easy to miss:

  • run_subprocess(check=False, quiet=True) captures output by default (core/process.py:352), so deploy-stack's own error never reaches the terminal or /tmp/devops-k8s-bootstrap.log.
  • MESSAGES.devcontainer.auto_deploy_failed (lang/en/messages.py:895-898) gives no exit status and blames a locked keyring, which is not the cause in case 1.
  • test_post_start_autodeploy_k8s_stack and test_bootstrap_k8s_autodeploy_k8s_stack (tests/test_devcontainer.py:771-821) use the stack observability, which deploy-stack rejects (VALID_STACKS is infra, llm, logging, devops, all; commands/k8s/networking.py:60-72). Both assert only the mock's success.
  • run_subprocess catches only FileNotFoundError (core/process.py:403). A deploy-stack that outruns the default 1800 s timeout therefore crashes bootstrap-k8s with a TimeoutExpired traceback.

This is the third change to the same ten-line function (#741, then #868's original call-site half). Per the stop-and-re-scope rule, the owner decides the direction before more code is added.

Two options:

  • A. Keep auto-deploy and make it work. Pass --context with the Minikube context minikube update-context writes. Pass the keyring session env through run_subprocess's allowed env. Run deploy-stack uncaptured, with the exit status in the warning. Spawn the bootstrap after the session bus starts, and skip the deploy with the unlock hint while the keyring is locked.
  • B. Drop auto-deploy. Remove --deploy/--no-deploy, _auto_deploy_k8s_stack, DEVOPS_K8S_AUTO_DEPLOY and auto_deploy_failed with no shim. bootstrap-k8s starts Minikube and prints the deploy-stack command, with --stack and --context, to run once the keyring is unlocked.

Acceptance criteria

  • The owner's choice between A and B is recorded on this issue before work starts.
  • (A) _auto_deploy_k8s_stack runs deploy-stack with --stack <stack> and --context set to a Minikube-context constant. It passes the session-bus keys the Secret Service backend reads through extra_allowed_env. A test with run_subprocess patched asserts the exact argv and the allowed keys. A build_subprocess_env(extra_allowed_keys=...) test keeps DBUS_SESSION_BUS_ADDRESS.
  • (A) deploy-stack runs with capture_output=False. On a non-zero exit, the warning names the stack and the exit status and quotes no deploy-stack text. A test returns exit 2 with the real stderr shape: the Typer usage panel (╭─ Error ─╮ │ Got unexpected extra argument(s) (infra) │ ╰─╯) followed by Elapsed: 0.5s. It asserts the warning has the stack and exit 2, and has neither Elapsed nor ╰.
  • (A) Post-start spawns the bootstrap after the session bus is up. While the keyring is locked, the deploy step skips with the unlock hint and the exact deploy-stack command instead of reporting a failure. A deploy-stack timeout becomes a warning, not a traceback. Tests double only the process edges.
  • (B) bootstrap-k8s and post-start no longer deploy. The deploy option, _auto_deploy_k8s_stack, DEVOPS_K8S_AUTO_DEPLOY (.devcontainer/devcontainer.json:44) and MESSAGES.devcontainer.auto_deploy_failed are removed with no shim. bootstrap-k8s prints devops k8s deploy-stack --stack <stack> --context minikube. A test resolves the printed command with resolve_devops_argv and gets None.
  • Either way, test_post_start_autodeploy_k8s_stack and test_bootstrap_k8s_autodeploy_k8s_stack use a stack deploy-stack accepts. They assert the argv that ran or the command that was printed, not only a mock's success.
  • Every test runs offline, with no network, no DNS and no real keyring, kubectl, helm or minikube. Each test call phase stays under 1 s, --dry-run makes zero requests, and uv run devops ci passes.
  • Pending a person (A): in the devcontainer with Minikube running and the keyring unlocked, run devops devcontainer bootstrap-k8s --stack infra --deploy. deploy-stack's Installing ... lines appear, it prints Auto-deployed Kubernetes stack 'infra', and helm list -A --kube-context minikube lists the infra releases. With the keyring locked, the same command skips the deploy and prints the unlock hint.
  • Pending a person (B): run devops devcontainer bootstrap-k8s --stack infra. Minikube starts and nothing is deployed. Run devops devcontainer unlock-keyring, then the printed command; it deploys the infra stack to Minikube.

Key questions

  • Keep post-start auto-deploy (A) or drop it (B)? (proposed) B. Since 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, deploy-stack needs an unlocked keyring, and a person unlocks it after the container starts, so an unattended deploy at post-start stops at that gate in the normal case. Printing the command costs nothing and removes the env, context and ordering coupling. A keeps a convenience that works only when the keyring happens to be unlocked, and it needs four changes to one call site.
  • (A) Which env keys pass through? (proposed) A dedicated constant with the session-bus keys, not a reuse of CONST_GH_LOGIN_ENV_VARS, which also carries gh's config directories.
  • (A or B) Which context? (proposed) minikube, as a constant: the context minikube update-context writes. The deploy then targets the cluster bootstrap-k8s started, whatever k8s.context says (fail closed).
  • Should bootstrap-k8s reject a stack deploy-stack would reject? (proposed) No. With A, deploy-stack's own Invalid stack: '<stack>'. Supported stacks: infra, llm, logging, devops, all line appears uncaptured. With B, the printed command fails the same way when run.

Strategic alignment


Split from #868 by the owner's scope decision of 2026-10-08 (borrow reason: split). Filed directly because local intake could not reach the model gateway; the roadmap service's intake sets Priority, Value and Effort.

Update 2026-10-08: refinement

The code is unchanged since 910b823; the A/B choice is open. (B) also changes the template (templates/devcontainer.json.j2:44), the spawn argv (commands/devcontainer.py:1029-1032), four tests, the help text and docs/DEVCONTAINER_USAGE.md:334.

  • (B) git grep finds no DEVOPS_K8S_AUTO_DEPLOY, _auto_deploy_k8s_stack or --no-deploy outside task files.

Activity

  1. added
    type/bug
    scope/k8s
    scope/cli
    source/agent
    on Oct 8, 2026
  2. dan-petty-bot commented on Oct 8, 2026

    @dan-petty-bot
    Collaborator

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

    • Priority: P2-Medium. The primary dev-environment deploy path is non-functional, but a manual 'devops k8s deploy-stack' workaround exists and no data or security is at risk.
    • Value: High. Every developer using the devcontainer loses the one-command deploy workflow and must manually invoke deploy-stack with the correct context and keyring access.
    • Effort: Medium. Three separate code paths need fixes (env allowlist for keyring, --context propagation, post-start ordering) plus test corrections, but each is localized and well-identified.
  3. dan-petty commented on Oct 25, 2026

    @dan-petty
    OwnerAuthor

    Decision: Option B (drop auto-deploy). bootstrap-k8s and post-start will no longer deploy, removing --deploy/--no-deploy, _auto_deploy_k8s_stack, DEVOPS_K8S_AUTO_DEPLOY, and auto_deploy_failed without shim, and printing devops k8s deploy-stack --stack --context minikube.

  4. added a commit that references this issue on Oct 25, 2026
    de2b9aa
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

    scope/cliscope/k8ssource/agenttype/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions