Stop deploy.sh running under sudo or from an outdated checkout #28

Merged
patrick merged 2 commits from feat/deploy-safety-checks into main 2026-11-01 00:49:46 +00:00
Owner

Problem

Two deploy mistakes from today that looked like something else:

  1. Run under sudo: ssh read root's ~/.ssh/config instead of the user's, so a custom Port 7625 disappeared and the deploy failed with ssh: connect to host triton port 22: Connection refused.
  2. Run from an outdated checkout: the workstation's main was two commits behind origin/main, so the redeploy shipped the 0.5.0 agent again, and the dashboard kept saying "agent 0.5.0 is older than 0.6.0" after a deploy that had looked fine.

Changes

agent/deploy.sh:

  • Refuses under sudo (running as root with SUDO_USER set), names the user to run it as, and stops before contacting any host. Nothing in it needs local root: install.sh runs under sudo on each host. A real root login is still allowed.

  • Checks the checkout before deploying: fetches its upstream branch (20s limit, no credential prompts) and, if the checkout is behind:

    • on a terminal, asks Deploy anyway? [y/N];
    • otherwise refuses with a pointer to the new --allow-outdated flag;
    • with --dry-run, only warns.

    A failed fetch warns and deploys. Being ahead of upstream, no upstream branch, or not being in a git checkout skips the check.

docs/agents.md: explains both checks and lists --allow-outdated.

Testing

  • make test: all pass, including 16 new deploy tests.
  • Sudo guard: refused under sudo (and nothing contacted), root login allowed, SUDO_USER set but not root allowed.
  • Checkout check, against real throwaway git repos (bare origin + a clone pushing a newer commit): up to date deploys quietly, behind refuses without a terminal (nothing deployed), --allow-outdated deploys with a warning, --dry-run only warns, unreachable upstream warns and deploys, ahead is fine, no upstream skips the check.
  • The existing deploy tests also run inside a git checkout, so normal flows are covered with the check active.
  • shellcheck wasn't available locally; CI runs it.

🤖 Generated with Claude Code

## Problem Two deploy mistakes from today that looked like something else: 1. **Run under sudo**: ssh read root's `~/.ssh/config` instead of the user's, so a custom `Port 7625` disappeared and the deploy failed with `ssh: connect to host triton port 22: Connection refused`. 2. **Run from an outdated checkout**: the workstation's `main` was two commits behind `origin/main`, so the redeploy shipped the 0.5.0 agent again, and the dashboard kept saying "agent 0.5.0 is older than 0.6.0" after a deploy that had looked fine. ## Changes `agent/deploy.sh`: - **Refuses under sudo** (running as root with `SUDO_USER` set), names the user to run it as, and stops before contacting any host. Nothing in it needs local root: `install.sh` runs under sudo on each host. A real root login is still allowed. - **Checks the checkout before deploying**: fetches its upstream branch (20s limit, no credential prompts) and, if the checkout is behind: - on a terminal, asks `Deploy anyway? [y/N]`; - otherwise refuses with a pointer to the new `--allow-outdated` flag; - with `--dry-run`, only warns. A failed fetch warns and deploys. Being ahead of upstream, no upstream branch, or not being in a git checkout skips the check. `docs/agents.md`: explains both checks and lists `--allow-outdated`. ## Testing - `make test`: all pass, including 16 new deploy tests. - Sudo guard: refused under sudo (and nothing contacted), root login allowed, `SUDO_USER` set but not root allowed. - Checkout check, against real throwaway git repos (bare origin + a clone pushing a newer commit): up to date deploys quietly, behind refuses without a terminal (nothing deployed), `--allow-outdated` deploys with a warning, `--dry-run` only warns, unreachable upstream warns and deploys, ahead is fine, no upstream skips the check. - The existing deploy tests also run inside a git checkout, so normal flows are covered with the check active. - shellcheck wasn't available locally; CI runs it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
patrick added 2 commits 2026-11-01 00:46:59 +00:00
Under sudo, ssh reads root's config and keys, so a custom Port silently
disappears and the deploy fails with "connect to host ... port 22:
Connection refused". deploy.sh needs no root locally (install.sh runs
under sudo on each host), so it now refuses when run as root via sudo,
naming the user to run it as. A real root login is still allowed.

Deploying from a checkout behind its upstream ships an older agent than
the server expects, and the dashboard keeps saying "agent is older" after
a deploy that looked fine. deploy.sh now fetches the upstream (20s limit)
and, if the checkout is behind, asks on a terminal or refuses otherwise;
--allow-outdated deploys anyway and --dry-run only warns. A failed fetch
warns and carries on; no checkout or no upstream skips the check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Document deploy.sh's sudo and outdated-checkout checks
CI / tests (Python 3.11) (pull_request) Successful in 34s
CI / tests (Python 3.10) (pull_request) Successful in 35s
CI / tests (Python 3.12) (pull_request) Successful in 33s
CI / tests (Python 3.13) (pull_request) Successful in 34s
CI / lint (pull_request) Successful in 2s
253ccb02f6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
patrick merged commit 249e8c2b2a into main 2026-11-01 00:49:46 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: patrick/kernel-automation#28