fix(security): restrict canary rollback to registered mutable channels (#1402)

Merged
DO
14d ago
+263-0

Summary

canary-rollout.sh rollback now only force-moves a registered mutable channel of the agent. It refuses an immutable release tag (<agent>/vX.Y.Z, standards/vX.Y.Z), an unregistered agent or channel, or a malformed ref path, and it refuses before any lookup or write. _gh_move_tag also refuses immutable release names and malformed ref paths. That means every caller (promote, autocut, rollback) is protected, not only rollback.

Fixes #1402

Confirmed. cmd_rollback (scripts/canary-rollout.sh ~L2500–2533 on 1ea9ee1f) builds the tag "$agent/$ring" from the workflow_dispatch ring input (.github/workflows/canary-rollout.yml L124, passed through at L331/L342). It hands that tag straight to _gh_move_tag (L304), which runs PATCH .../git/refs/tags/<tag> force=true with the release-manager write token. There was no check that <ring> is a channel. I reproduced this with a gh stub that logs writes, never against GitHub:

  • rollback dev-lead v139.0.0 --to v139.8.0 printed rolled back dev-lead/v139.0.0 -> v139.8.0 and issued a PATCH on the release tag.
  • rollback standards v1.2.3 --to v1.2.3 did the same for standards/v1.2.3. An unregistered agent falls back to host = THIS_REPO.
  • ring2 (unregistered) and stable/../v139.0.0 were also accepted.

Fix (the decision logic is pure, in scripts/lib/canary-rollout.sh):

  • rollback_ring_allowed <ring> <channels_csv> accepts the ring only if it is one of the agent's registered channels from ordered_channels (the standards/canary-rings.json .agents[a].rings[].channel set). It may be bare (stable) or v-scoped (v139-stable, the form a v-scoped fleet pins today). An unregistered agent has no channels and is rejected. Anything with /, ., or a dotted version is rejected.
  • is_release_tag_name <tag> matches when the last path component is a dotted version (v1.2.3, v2.0.0-rc.1, …). It is broader than the existing _is_release_tag_suffix on purpose, because it is the deny-list.
  • movable_channel_tag_name <tag> requires a well-formed ref path (no empty, ., or .. segments) that is not a release name.
  • cmd_rollback: one 6-line check right after argument parsing. It returns 2 with ::error:: and makes no gh calls.
  • _gh_move_tag: one 7-line guard at the top. It returns 2 with ::error:: and makes no PATCH or POST. The echoed value is character-filtered.

No public contract changes. The workflow inputs and command syntax are the same, and every currently valid rollback (ring = a registered channel, bare or v<M>- scoped) still works. Rollback to a non-channel ref was never a documented use: the input description is "which ring channel to move".

Regression tests (tests/canary_rollout.bats, appended at the end of the file):

  • Unit tests for the three helpers, covering both accept and reject cases.
  • Stubbed orchestrator tests: a release-tag ring, an unregistered agent (standards), and unregistered channels or ref paths all exit 2 with no write logged. A bare stable and a v-scoped v139-stable still produce the move.
  • _gh_move_tag refuses dev-lead/v139.8.0, standards/v1.2.3, v1.2.3 and dev-lead/../heads/main without calling PATCH or POST, and still moves dev-lead/v139-stable.

On origin/main the orchestrator and _gh_move_tag tests fail (the write happens), and they pass with this fix.

Interaction with #1117 (#1103)

#1117 changes cmd_rollback to resolve the ring tag v-scope-aware (<agent>/v<M>-<ring>, else bare <agent>/<ring>) and to fail loudly if the tag is absent. This PR is written to merge in either order:

  • No textual overlap. The cmd_rollback check sits right after --to parsing, above the host lookup. #1117's hunk starts at local target, several lines below. The _gh_move_tag guard is in a function #1117 does not touch. The new tests are appended at the end of tests/canary_rollout.bats, and #1117 inserts its tests around L1205.
  • Semantics compose. #1117 still takes the bare tier name as <ring>, and that is exactly what rollback_ring_allowed validates. The tag #1117 then builds (<agent>/v<M>-<tier> or <agent>/<tier>) passes the _gh_move_tag guard, because both channel forms are accepted there. A release-name or unregistered ring is rejected before #1117's resolution runs.
  • Checked locally: I applied gh pr diff 1117 on top of this branch with git apply --3way. Both files applied cleanly, and bats -f "1103|1402" passed 15/15 (3 from #1103 and 12 from #1402).

#1196 (shell hygiene) also touches scripts/canary-rollout.sh. This diff adds 13 lines in two places and reformats nothing.

Tests run

  • shellcheck --severity=warning -x scripts/canary-rollout.sh scripts/lib/canary-rollout.sh: clean (same invocation as CI).
  • bats -f 1402 tests/canary_rollout.bats: 12/12 pass. On origin/main, 7 of them fail (the 3 helper "accept" tests because the functions are missing, plus the orchestrator and _gh_move_tag write tests).
  • Full bats tests/canary_rollout.bats on macOS (bash 5 and GNU coreutils on PATH): 528/530 pass. The 2 failures (#171, #173) are local-only. They call grep -P, which BSD grep lacks, and they fail the same way on unmodified origin/main. In both, the channel move still reaches the stubbed API, so the guard does not interfere. CI runs on Ubuntu with GNU grep.

Follow-ups / release notes

  • No tag moves are needed. canary-rollout.sh runs from this repo's checkout on main, so the guard is live on merge.
  • scripts/cut-standards-release.sh has its own _gh_move_tag copy. It is out of scope here because its channel tag is derived internally rather than from dispatch input. It could adopt the same guard later.

🤖 Generated with Claude Code