Deploy the Semaphore server on a merge to main (CP-40) #13

Merged
pit merged 4 commits from hermes/cp40-deploy-semaphore-on-merge into main 2026-11-05 12:38:16 +00:00
Owner

Implements CP-40, the first slice of CP-39: a merge to main deploys the Semaphore server (143) through Forgejo Actions, with nobody at a terminal.

The deploy. deploy.yml on push to main, concurrency cockpit-deploy with cancel-in-progress: false, enable-email-notifications: true. It logs in as cockpit, runs make semaphore-idle (waits up to 15 minutes for Semaphore's pool to be empty, then proceeds and says why), then make prod NONINTERACTIVE=1 — snapshot guest service verify, each its own make, stopping at the first red one.

The non-interactive gate. guest plans to an artefact, judges it with the plan check's judge and applies only a judged artefact; service's check run is its gate. With NONINTERACTIVE unset, the typed word still guards.

make snapshot takes predeploy-<YYYYMMDD>-<HHMMSS> (UTC) on the vmid read from state, described with repository, commit and run, then deletes predeploy-* beyond the newest three by exact name. A failed snapshot stops the deploy before anything changes.

plan.yml on pull_request_target, no paths: filter, workflow and judge from main, the head's Guest Stack under head/ planned with -lock=false: red on any destroy or replace and on any failure to read.

roles/journal sets Storage=persistent on 143.

Docs. docs/deploy.md: the automated deploy, the plan check, the Operator's hand resolution of a conflict, rollback losses, reading a failure.

Proved against PROD, not just offline

  • make guest-plan: No changes — the first merge's Guest step is a clean no-op.
  • make guest-plan-check with the plan key and infra-ci@pve!cockpit-plan: green against real state. With a temporary unprivileged = false (reverted): red, FAIL proxmox_virtual_environment_container.semaphore would be destroyed or replaced; prevent_destroy refused the plan — the acceptance criterion's mechanism.
  • make snapshot: took predeploy-20261105-121814 on 143 through the real API; pct listsnapshot confirms it.
  • make semaphore-idle: logged in as admin, read /api/tasks, empty pool.
  • make check: green, now including make plan-test (14 cases, real OpenTofu plans of a throwaway local Stack, plus the prune at two, three and four snapshots).

Two defects came out of running it live, both fixed here: the prune deleted a snapshot when fewer than three existed, and the judge did not name a prevent_destroy refusal whose address tofu wrapped at eighty columns.

Operator actions already done

  • Repository variable PROXMOX_VE_ENDPOINT.
  • Secrets COCKPIT_GUEST_PLAN_STATE_ACCESS_KEY_ID, COCKPIT_GUEST_PLAN_STATE_SECRET_ACCESS_KEY (the existing tofu-plan-state-semaphore pair from SL-13), PROXMOX_VE_PLAN_API_TOKEN (infra-ci@pve!cockpit-plan, recorded in olympus/infra-secrets#27).

Still to come, after this merges

Marking plan / guest-plan-check (pull_request_target) required (its context exists only once the workflow is on main), and the throwaway replace/green pull requests that criterion 1–2 name.

Closes nothing: CP-40 stays open until its merge-time criteria are seen.

Implements CP-40, the first slice of CP-39: a merge to `main` deploys the Semaphore server (143) through Forgejo Actions, with nobody at a terminal. **The deploy.** `deploy.yml` on push to `main`, concurrency `cockpit-deploy` with `cancel-in-progress: false`, `enable-email-notifications: true`. It logs in as `cockpit`, runs `make semaphore-idle` (waits up to 15 minutes for Semaphore's pool to be empty, then proceeds and says why), then `make prod NONINTERACTIVE=1` — `snapshot guest service verify`, each its own make, stopping at the first red one. **The non-interactive gate.** `guest` plans to an artefact, judges it with the plan check's judge and applies only a judged artefact; `service`'s check run is its gate. With `NONINTERACTIVE` unset, the typed word still guards. **`make snapshot`** takes `predeploy-<YYYYMMDD>-<HHMMSS>` (UTC) on the vmid read from state, described with repository, commit and run, then deletes `predeploy-*` beyond the newest three by exact name. A failed snapshot stops the deploy before anything changes. **`plan.yml`** on `pull_request_target`, no `paths:` filter, workflow and judge from `main`, the head's Guest Stack under `head/` planned with `-lock=false`: red on any destroy or replace and on any failure to read. **`roles/journal`** sets `Storage=persistent` on 143. **Docs.** `docs/deploy.md`: the automated deploy, the plan check, the Operator's hand resolution of a conflict, rollback losses, reading a failure. ### Proved against PROD, not just offline - `make guest-plan`: **No changes** — the first merge's Guest step is a clean no-op. - `make guest-plan-check` with the plan key and `infra-ci@pve!cockpit-plan`: green against real state. With a temporary `unprivileged = false` (reverted): red, `FAIL proxmox_virtual_environment_container.semaphore would be destroyed or replaced; prevent_destroy refused the plan` — the acceptance criterion's mechanism. - `make snapshot`: took `predeploy-20261105-121814` on 143 through the real API; `pct listsnapshot` confirms it. - `make semaphore-idle`: logged in as admin, read `/api/tasks`, empty pool. - `make check`: green, now including `make plan-test` (14 cases, real OpenTofu plans of a throwaway local Stack, plus the prune at two, three and four snapshots). Two defects came out of running it live, both fixed here: the prune deleted a snapshot when fewer than three existed, and the judge did not name a `prevent_destroy` refusal whose address tofu wrapped at eighty columns. ### Operator actions already done - Repository variable `PROXMOX_VE_ENDPOINT`. - Secrets `COCKPIT_GUEST_PLAN_STATE_ACCESS_KEY_ID`, `COCKPIT_GUEST_PLAN_STATE_SECRET_ACCESS_KEY` (the existing `tofu-plan-state-semaphore` pair from SL-13), `PROXMOX_VE_PLAN_API_TOKEN` (`infra-ci@pve!cockpit-plan`, recorded in olympus/infra-secrets#27). ### Still to come, after this merges Marking `plan / guest-plan-check (pull_request_target)` required (its context exists only once the workflow is on `main`), and the throwaway replace/green pull requests that criterion 1–2 name. Closes nothing: CP-40 stays open until its merge-time criteria are seen.
deploy.yml runs on push to main, one at a time (concurrency cockpit-deploy,
cancel-in-progress false), mails on failure, waits up to fifteen minutes for
Semaphore to be idle, then runs `make prod NONINTERACTIVE=1`: snapshot, guest,
service, verify.

- `make prod`, and NONINTERACTIVE=1: the plan check's judge replaces the typed
  word on the Guest apply (plan to an artefact, refuse a destroy or replace,
  apply the artefact), and the check run gates the playbook.
- `make snapshot`: predeploy-<YYYYMMDD>-<HHMMSS> on the vmid read from state,
  described with repository, commit and run; deletes predeploy-* beyond the
  newest three, by name.
- `make semaphore-idle`: the admin's task pool, polled for up to 15 minutes.
- plan.yml: the plan check on pull_request_target, workflow and judge from
  main, the head's Guest Stack planned with -lock=false; red on any destroy or
  replace and on any failure to read. `make plan-test` is on `check`.
- The service layer's journal role: Storage=persistent.
- docs/deploy.md: the deploy, and the Operator's hand resolution of a conflict.
Review of 3513945 found the prune off by one below the keep count: a negative
slice end in jq counts from the other end, so with two predeploy-* snapshots
the second deploy deleted the first. The selection is now `max(length - keep,
0)`, extracted as a sourceable function and covered by the suite — two, three
and four snapshots, and names outside the exact prefix shape.

Also: the plan check's state key is the plan shape from ADR-0006 (it may take
the lock), so the docs no longer claim otherwise and `-lock=false` is explained
for what it is; one `judge_plan` define for the check and the deploy's apply;
`guest_stack_init` reused by snapshot and semaphore-idle; the judge reads stdin
only; README names the plan tests.
Against PROD's real state, tofu wraps the Guest's address at eighty columns, so
`Resource instance … has prevent_destroy set` reaches the judge across two
lines and the refusal went unnamed — red, but as "nothing was judged". The
phrase is matched across the wrap now, and a wrapped log is a case.

Found by running the two Targets against PROD: `make guest-plan-check` on a
temporary `unprivileged = false` names
proxmox_virtual_environment_container.semaphore as destroyed or replaced.
docs: name the plan check's Proxmox token (CP-40)
All checks were successful
pr-checks / check (pull_request) Successful in 17s
32240bae63
infra-ci@pve!cockpit-plan, minted for this repository's plan job: PVEAuditor on
/pool/prod and TofuDatastoreAudit on both storages, recorded in infra-secrets'
proxmox-credentials.md (olympus/infra-secrets#27).
Member

Review started (round 1/5) on 32240bae63 — reading the diff now.

**Review started** (round 1/5) on 32240bae634fc7a94b9eb99a6862c26ebd1a46a3 — reading the diff now.
bot-minos approved these changes 2026-11-05 12:37:03 +00:00
bot-minos left a comment

repo: olympus/infra-cockpit · pr: 13 · reviewed-head: 32240bae63 · round: 1/5 · verdict: approve

Recommendation: merge

Two ADVISORY findings, no BLOCKER. Neither touches behaviour; both are documentation.

Standards

Sources read: AGENTS.md (§Toolchain, §Docs), docs/agents/issue-tracker.md, docs/environment.md, plus the smell baseline. No documented-standard breach and no smell above nit level in the diff.

# Where Severity Finding
S1 AGENTS.md:44 ADVISORY The new rule ends "Nothing deploys PROD by hand", but docs/deploy.md:93-97 — added by this same PR — requires exactly that: "the Operator has done the destroy or the replacement by hand, outside the deploy", "run from a checkout with the Operator's own .env and their typed word, not NONINTERACTIVE". AGENTS.md is the file an agent reads first, so the two pages it now carries disagree about whether a hand deploy is allowed. Smallest fix: scope the AGENTS.md sentence to the ordinary path ("a merge deploys PROD; the one hand path is the conflict docs/deploy.md describes").
S2 scripts/snapshot.sh:39 ADVISORY The signature comment reads stale_names() { # listing, keep, but the function takes only <keep> and reads the listing from stdin (--argjson keep "${1:-$KEEP}", called as stale_names "$KEEP" at :129 and stale_names 3 in the tests). Called the way the comment documents, it breaks: passing the listing as $1 gives jq: error: number (4) and object ({"data":[{"…}) cannot be subtracted (rc 5) instead of the names to prune. Smallest fix: # stale_names <keep>: the listing on stdin.

Spec

Spec source: the PR body. CP-40 itself was not readable — this repo's tracker is Vikunja project 11 (docs/agents/issue-tracker.md) and no Vikunja tool is wired into this session — so the PR's own statements are the contract I held the diff to.

The PR says Where it is, in the diff Result
deploy.yml on push to main; concurrency cockpit-deploy, cancel-in-progress: false; enable-email-notifications: true .forgejo/workflows/deploy.yml:23-34 present; both keys are documented Forgejo workflow keys, and the docs confirm cancel-in-progress: false queues behind a running run rather than cancelling it
login as cockpit, then make semaphore-idle, then make prod NONINTERACTIVE=1 deploy.yml:56-63 present, in that order
semaphore-idle waits up to 15 min for an empty pool then proceeds and says why; never red scripts/semaphore-idle.sh:22,750-787, Makefile:367-371 matches (TIMEOUT=${…:-900}, every failure path is proceed, only a missing URL is exit 2)
snapshot guest service verify, each its own make, stopping at the first red one Makefile:377-382 confirmed by execution — see Verified
guest applies only a judged artefact; service's check run is its gate; without NONINTERACTIVE the typed word still guards Makefile:116-152,321-325 confirmed by execution (suite cases 10-12)
snapshot takes predeploy-<YYYYMMDD>-<HHMMSS> UTC on the vmid read from state, prunes predeploy-* beyond the newest three by exact name, and a failed snapshot stops the deploy before anything changes scripts/snapshot.sh:40-41,100,127-137, Makefile:356-361 matches; the prune never goes below three (regression case 13) and the stop-before-change is confirmed by execution
plan.yml on pull_request_target, no paths:, workflow + judge from main, head's Guest Stack under head/ planned -lock=false, red on destroy/replace and on any failure to read .forgejo/workflows/plan.yml:23-47 matches as written; refs/pull/13/head exists on the remote, so the head checkout resolves
roles/journal sets Storage=persistent on 143 semaphore/service/roles/journal/tasks/main.yml:20-27, site.yml:5 present
docs/deploy.md covers the deploy, the plan check, the Operator's conflict resolution, rollback losses, reading a failure docs/deploy.md §Before the merge, §After the merge, §The Operator's hand resolution, §Rolling back, §Reading a failure all five present
make check green, now including make plan-test (14 cases) Makefile:284,270-271 reproduced exactly: 14 cases, all pass

No requirement missing, partial, or wrongly implemented. The two "still to come" items (marking plan / guest-plan-check required, the throwaway replace/green PRs) are declared deferred in the body and CP-40 is left open, so they are not findings here.

Verified by my own hand

  • mise exec -- make check at the head, in a worktree of 32240ba: green — env pin and map, env tests, plan-test (14 cases, every one ok), tofu fmt -recursive -check.
  • The tests can fail for the right reason. Mutation: judge() forced to return 0 in a copy → plan-test fails 5 assertions, including the deploy refuses a plan that would replace the Guest and nothing was applied … (want [a], got [b]) and the refused plan artifact was left behind. The suite is not passing by accident.
  • prod stops at the first red step. Sandbox of the head's Makefile + scripts/ over a throwaway Stack, make prod NONINTERACTIVE=1 PROD_STEPS="snapshot guest" with an empty state: snapshot failed (error: no vmid in state), make returned 2, and prod: make guest was never printed. The Guest was not touched.
  • NONINTERACTIVE=1 reaches the sub-makes. make prod NONINTERACTIVE=1 PROD_STEPS="guest verify" → the guest sub-make printed NONINTERACTIVE: the plan check judges the plan above in place of the word., applied, and prod: make verify followed. (Command-line vars ride MAKEFLAGS.)
  • bash -n clean on scripts/snapshot.sh, scripts/semaphore-idle.sh, scripts/tests/plan-check.sh; python3 -m py_compile clean on scripts/plan-check.py.
  • Forgejo-side: refs/pull/13/head resolves to this SHA (git ls-remote); concurrency.cancel-in-progress: false and on.pull_request_target are documented behaviour for this forge version (15.0.9), as is enable-email-notifications — the deploy's queueing claim is not wishful.

Not verified, and why

  • Every PROD-facing claim in the body: make snapshot on 143, make semaphore-idle's login and empty pool, make guest-plan-check with the real plan key and infra-ci@pve!cockpit-plan, and the live prevent_destroy refusal. I hold no credentials for PROD and I do not touch it. Those four are the author's evidence, not mine.
  • plan.yml end to end. No plan / guest-plan-check (pull_request_target) status exists on this head — get_commit_statuses shows only pr-checks / check (pull_request), success in 17s. A pull_request_target workflow is evaluated from the default branch, so it cannot run until it is on main. I read the YAML and syntax-checked the scripts it calls; I did not see the forge execute it.
  • deploy.yml end to end — it only runs on a push to main.

Recorded, not counted as a finding

plan.yml deliberately checks out and plans the pull request's own HCL while holding the plan state key and the auditor token; Forgejo's own reference says "It is strongly recommended that workflows using on.pull_request_target do not interact with the untrusted code from the pull request". The PR argues the trade-off and both credentials are read-only (GetObject on prod/semaphore.tfstate, PVEAuditor on /pool/prod), so the blast radius is disclosure of read-only material, not a change to PROD. Accepted risk, stated here so it is on the record.

Summary

  • Standards: 2 findings, 0 blockers. Worst: AGENTS.md:44 contradicts docs/deploy.md:93-97 on hand deploys (ADVISORY).
  • Spec: 0 findings, 0 blockers. Every claim in the body that I could exercise offline held; the PROD-live claims are named as unverified rather than assumed.

The change is better for the repo with it than without it. Merge, and take the two doc nits whenever the next touch lands.

repo: olympus/infra-cockpit · pr: 13 · reviewed-head: 32240bae634fc7a94b9eb99a6862c26ebd1a46a3 · round: 1/5 · verdict: approve Recommendation: merge Two ADVISORY findings, no BLOCKER. Neither touches behaviour; both are documentation. ## Standards Sources read: `AGENTS.md` (§Toolchain, §Docs), `docs/agents/issue-tracker.md`, `docs/environment.md`, plus the smell baseline. No documented-standard breach and no smell above nit level in the diff. | # | Where | Severity | Finding | | --- | --- | --- | --- | | S1 | `AGENTS.md:44` | ADVISORY | The new rule ends "Nothing deploys PROD by hand", but `docs/deploy.md:93-97` — added by this same PR — requires exactly that: "the Operator has done the destroy or the replacement **by hand, outside the deploy**", "run from a checkout with the Operator's own `.env` and their typed word, not `NONINTERACTIVE`". `AGENTS.md` is the file an agent reads first, so the two pages it now carries disagree about whether a hand deploy is allowed. Smallest fix: scope the AGENTS.md sentence to the ordinary path ("a merge deploys PROD; the one hand path is the conflict `docs/deploy.md` describes"). | | S2 | `scripts/snapshot.sh:39` | ADVISORY | The signature comment reads `stale_names() { # listing, keep`, but the function takes only `<keep>` and reads the listing from stdin (`--argjson keep "${1:-$KEEP}"`, called as `stale_names "$KEEP"` at :129 and `stale_names 3` in the tests). Called the way the comment documents, it breaks: passing the listing as `$1` gives `jq: error: number (4) and object ({"data":[{"…}) cannot be subtracted` (rc 5) instead of the names to prune. Smallest fix: `# stale_names <keep>: the listing on stdin`. | ## Spec Spec source: the PR body. CP-40 itself was **not** readable — this repo's tracker is Vikunja project 11 (`docs/agents/issue-tracker.md`) and no Vikunja tool is wired into this session — so the PR's own statements are the contract I held the diff to. | The PR says | Where it is, in the diff | Result | | --- | --- | --- | | `deploy.yml` on push to `main`; concurrency `cockpit-deploy`, `cancel-in-progress: false`; `enable-email-notifications: true` | `.forgejo/workflows/deploy.yml:23-34` | present; both keys are documented Forgejo workflow keys, and the docs confirm `cancel-in-progress: false` **queues** behind a running run rather than cancelling it | | login as `cockpit`, then `make semaphore-idle`, then `make prod NONINTERACTIVE=1` | `deploy.yml:56-63` | present, in that order | | `semaphore-idle` waits up to 15 min for an empty pool then proceeds and says why; never red | `scripts/semaphore-idle.sh:22,750-787`, `Makefile:367-371` | matches (`TIMEOUT=${…:-900}`, every failure path is `proceed`, only a missing URL is `exit 2`) | | `snapshot guest service verify`, each its own make, stopping at the first red one | `Makefile:377-382` | confirmed by execution — see Verified | | `guest` applies only a judged artefact; `service`'s check run is its gate; without `NONINTERACTIVE` the typed word still guards | `Makefile:116-152,321-325` | confirmed by execution (suite cases 10-12) | | `snapshot` takes `predeploy-<YYYYMMDD>-<HHMMSS>` UTC on the vmid read from state, prunes `predeploy-*` beyond the newest three **by exact name**, and a failed snapshot stops the deploy before anything changes | `scripts/snapshot.sh:40-41,100,127-137`, `Makefile:356-361` | matches; the prune never goes below three (regression case 13) and the stop-before-change is confirmed by execution | | `plan.yml` on `pull_request_target`, no `paths:`, workflow + judge from `main`, head's Guest Stack under `head/` planned `-lock=false`, red on destroy/replace and on any failure to read | `.forgejo/workflows/plan.yml:23-47` | matches as written; `refs/pull/13/head` exists on the remote, so the head checkout resolves | | `roles/journal` sets `Storage=persistent` on 143 | `semaphore/service/roles/journal/tasks/main.yml:20-27`, `site.yml:5` | present | | `docs/deploy.md` covers the deploy, the plan check, the Operator's conflict resolution, rollback losses, reading a failure | `docs/deploy.md` §Before the merge, §After the merge, §The Operator's hand resolution, §Rolling back, §Reading a failure | all five present | | `make check` green, now including `make plan-test` (14 cases) | `Makefile:284,270-271` | reproduced exactly: 14 cases, all pass | No requirement missing, partial, or wrongly implemented. The two "still to come" items (marking `plan / guest-plan-check` required, the throwaway replace/green PRs) are declared deferred in the body and CP-40 is left open, so they are not findings here. ## Verified by my own hand - `mise exec -- make check` at the head, in a worktree of `32240ba`: **green** — env pin and map, env tests, `plan-test` (14 cases, every one `ok`), `tofu fmt -recursive -check`. - **The tests can fail for the right reason.** Mutation: `judge()` forced to `return 0` in a copy → `plan-test` fails 5 assertions, including `the deploy refuses a plan that would replace the Guest` and `nothing was applied … (want [a], got [b])` and `the refused plan artifact was left behind`. The suite is not passing by accident. - **`prod` stops at the first red step.** Sandbox of the head's `Makefile` + `scripts/` over a throwaway Stack, `make prod NONINTERACTIVE=1 PROD_STEPS="snapshot guest"` with an empty state: `snapshot` failed (`error: no vmid in state`), make returned 2, and `prod: make guest` was never printed. The Guest was not touched. - **`NONINTERACTIVE=1` reaches the sub-makes.** `make prod NONINTERACTIVE=1 PROD_STEPS="guest verify"` → the `guest` sub-make printed `NONINTERACTIVE: the plan check judges the plan above in place of the word.`, applied, and `prod: make verify` followed. (Command-line vars ride `MAKEFLAGS`.) - `bash -n` clean on `scripts/snapshot.sh`, `scripts/semaphore-idle.sh`, `scripts/tests/plan-check.sh`; `python3 -m py_compile` clean on `scripts/plan-check.py`. - Forgejo-side: `refs/pull/13/head` resolves to this SHA (`git ls-remote`); `concurrency.cancel-in-progress: false` and `on.pull_request_target` are documented behaviour for this forge version (15.0.9), as is `enable-email-notifications` — the deploy's queueing claim is not wishful. ## Not verified, and why - **Every PROD-facing claim in the body**: `make snapshot` on 143, `make semaphore-idle`'s login and empty pool, `make guest-plan-check` with the real plan key and `infra-ci@pve!cockpit-plan`, and the live `prevent_destroy` refusal. I hold no credentials for PROD and I do not touch it. Those four are the author's evidence, not mine. - **`plan.yml` end to end.** No `plan / guest-plan-check (pull_request_target)` status exists on this head — `get_commit_statuses` shows only `pr-checks / check (pull_request)`, success in 17s. A `pull_request_target` workflow is evaluated from the default branch, so it cannot run until it is on `main`. I read the YAML and syntax-checked the scripts it calls; I did not see the forge execute it. - **`deploy.yml` end to end** — it only runs on a push to `main`. ## Recorded, not counted as a finding `plan.yml` deliberately checks out and plans the pull request's own HCL while holding the plan state key and the auditor token; Forgejo's own reference says "It is strongly recommended that workflows using `on.pull_request_target` do not interact with the untrusted code from the pull request". The PR argues the trade-off and both credentials are read-only (`GetObject` on `prod/semaphore.tfstate`, `PVEAuditor` on `/pool/prod`), so the blast radius is disclosure of read-only material, not a change to PROD. Accepted risk, stated here so it is on the record. ## Summary - **Standards**: 2 findings, 0 blockers. Worst: `AGENTS.md:44` contradicts `docs/deploy.md:93-97` on hand deploys (ADVISORY). - **Spec**: 0 findings, 0 blockers. Every claim in the body that I could exercise offline held; the PROD-live claims are named as unverified rather than assumed. The change is better for the repo with it than without it. Merge, and take the two doc nits whenever the next touch lands.
pit merged commit 337a5ffeee into main 2026-11-05 12:38:16 +00:00
pit deleted branch hermes/cp40-deploy-semaphore-on-merge 2026-11-05 12:38:16 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
olympus/infra-cockpit!13
No description provided.