fix(security): restrict canary rollback to registered mutable channels (#1402)
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.0printedrolled back dev-lead/v139.0.0 -> v139.8.0and issued a PATCH on the release tag.rollback standards v1.2.3 --to v1.2.3did the same forstandards/v1.2.3. An unregistered agent falls back tohost = THIS_REPO.ring2(unregistered) andstable/../v139.0.0were 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 fromordered_channels(thestandards/canary-rings.json.agents[a].rings[].channelset). 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_suffixon 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 barestableand a v-scopedv139-stablestill produce the move. _gh_move_tagrefusesdev-lead/v139.8.0,standards/v1.2.3,v1.2.3anddev-lead/../heads/mainwithout calling PATCH or POST, and still movesdev-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_rollbackcheck sits right after--toparsing, above thehostlookup. #1117's hunk starts atlocal target, several lines below. The_gh_move_tagguard is in a function #1117 does not touch. The new tests are appended at the end oftests/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 whatrollback_ring_allowedvalidates. The tag #1117 then builds (<agent>/v<M>-<tier>or<agent>/<tier>) passes the_gh_move_tagguard, 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 1117on top of this branch withgit apply --3way. Both files applied cleanly, andbats -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. Onorigin/main, 7 of them fail (the 3 helper "accept" tests because the functions are missing, plus the orchestrator and_gh_move_tagwrite tests).- Full
bats tests/canary_rollout.batson macOS (bash 5 and GNU coreutils on PATH): 528/530 pass. The 2 failures (#171, #173) are local-only. They callgrep -P, which BSD grep lacks, and they fail the same way on unmodifiedorigin/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.shruns from this repo's checkout onmain, so the guard is live on merge. scripts/cut-standards-release.shhas its own_gh_move_tagcopy. 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