Harden auto-merge workflow against pull_request_target fork attacks (CI-001)#386
Merged
Conversation
The generated auto-merge workflow runs on pull_request_target with contents/issues/pull-requests write and the GH_PAT/GH_BOT_PAT tokens. Add a job-level guard so the privileged token never runs against code from a fork, add a per-PR concurrency group to cancel superseded runs, and stamp an AUTO-GENERATED header so the file is not hand-edited. Addresses code-review finding CI-001. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
cloudofficer-admin
approved these changes
May 17, 2026
ydesgagn
added a commit
to Cloud-Officer/ci-actions
that referenced
this pull request
May 17, 2026
BUG-007/BUG-008/QUAL-020 (codedeploy/deploy): the monitor exited 0 on timeout and treated blue/green "Ready" as terminal success, so failed or in-flight deployments reported green. Now polls with set -euo pipefail, treats only Succeeded as success, fails on Failed/Stopped and on timeout, keeps polling through Ready, and the window is configurable via the new monitor-timeout-minutes input (default 30). TEST-001 (variables): the bats suite re-implemented production functions instead of running them. variables.sh now defines all helpers up front and guards its main body behind BASH_SOURCE==$0; the suite sources the real script. All 65 tests pass against production code. CI-001 (auto-merge.yml): regenerated from the patched github-build generator - adds a fork guard, a per-PR concurrency group, and the AUTO-GENERATED header. See Cloud-Officer/github-build#386. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The generated
auto-merge.ymlworkflow triggers onpull_request_targetwithcontents/issues/pull-requests: writeand usessecrets.GH_PAT/secrets.GH_BOT_PAT. It is safe today, but is one PR-controlled-string interpolation away from a token-exfiltration path, and the bot PAT carries org-wide write rights. This patches the generator so every downstream repo gets the fix on regeneration.Key changes:
lib/ghb/auto_merge_manager.rb: add a job-level fork guard (github.event.pull_request.head.repo.full_name == github.repository) so the privileged token never runs against fork-checked-out code; add a per-PRconcurrencygroup withcancel-in-progress; write an# AUTO-GENERATED by github-buildheader so the file is no longer hand-edited.spec/ghb/auto_merge_manager_spec.rb: update the draft-PR expectation and add coverage for the fork guard, the concurrency group, and the auto-generated header.Addresses code-review finding CI-001 (Critical). Companion PR: Cloud-Officer/ci-actions#197 (consumes the regenerated workflow).
Types of changes
Checklist
readme.mdincludes sections on introduction, installation, usage, and contributingdocs/architecture.mdincludes sections on the architecture diagram, software units, software of unknown provenance, critical algorithms and risk controls related to PII and securityFurther comments (if required)
Regenerating any consumer repo will rewrite its
.github/workflows/auto-merge.ymlwith the fork guard, concurrency group, and AUTO-GENERATED header. Merge this PR before the companionCloud-Officer/ci-actions#197is regenerated so the committed workflow and the generator stay in sync.