Skip to content

fix(merge-train): verify signatures via GitHub API (#619) - #620

Closed
robotrocketscience wants to merge 2 commits into
mainfrom
fix/issue-619-merge-train-signature-check
Closed

fix(merge-train): verify signatures via GitHub API (#619)#620
robotrocketscience wants to merge 2 commits into
mainfrom
fix/issue-619-merge-train-signature-check

Conversation

@robotrocketscience

@robotrocketscience robotrocketscience commented May 11, 2026

Copy link
Copy Markdown
Owner

Closes #618. Closes #619 (filed as a duplicate of #618 minutes later, before this PR opened).

Summary

Replace the merge-train signature check with GitHub's verification API. Every SSH-signed PR labeled ready-to-merge since #602 shipped (a6ab3af) has been unlabeled with a spurious "not signed" comment, because actions/checkout does not set gpg.format=ssh or gpg.ssh.allowedSignersFile, so git log --format='%G?' returns N for SSH signatures.

This commit swaps the check to gh api repos/.../commits/<sha> --jq '.commit.verification.verified', which is the same source of truth required_signatures branch protection uses downstream. Matches Option B in the #618 recommendation.

Verification

  • All commits in this PR signed (git log --format='%G?' returns G locally; GitHub API confirms verified=true)
  • Diff is localised to lines 101–109 of .github/workflows/merge-train.yml plus a CHANGELOG ### Fixed entry
  • Acceptance from ci(merge-train): signature check rejects all SSH-signed commits — no allowed_signers in bot env #618:
    • Signature check uses GitHub's source of truth (commit.verification.verified)
    • Unsigned commits still get the same blocked-comment + unlabel path (the fail_and_unlabel branch is unchanged; only the detection oracle moved)
    • Fail-message reworded to point at the new oracle for future debugging

The first end-to-end test is this very PR: once merged manually (the bug being fixed prevents the bot from merging this PR itself), the next labeled PR will exercise the fix.

Test plan

The previous check used `git log --format='%G?'`, which requires
the runner to have `gpg.format=ssh` and `gpg.ssh.allowedSignersFile`
configured for SSH-signed commits to register as 'G'. actions/checkout
sets neither, so every SSH signature returned 'N' (no signature) and
every PR labeled `ready-to-merge` since #602 shipped got unlabeled.

Switch to `gh api repos/.../commits/<sha>` and read
`.commit.verification.verified`. That is the same source of truth the
`required_signatures` branch protection rule uses downstream, so any
commit the workflow accepts will also pass the push gate.

The fail-message wording shifts to 'not signed (per GitHub verification
API)' so future debugging points at the right oracle.
@robotrocketscience robotrocketscience added the author-Leibniz PR authored by Leibniz session (don't self-review) label May 11, 2026
@sourcery-ai

sourcery-ai Bot commented May 11, 2026

Copy link
Copy Markdown

Reviewer's Guide

Replaces the merge-train workflow’s local git-based GPG/SSH signature check with a GitHub API–based verification and updates the user-facing failure messaging and changelog accordingly.

Sequence diagram for merge-train signature verification via GitHub API

sequenceDiagram
    participant MergeTrainWorkflow
    participant GitHubRepo
    participant GitHubAPI

    MergeTrainWorkflow->>GitHubRepo: git fetch origin main and HEAD_REF
    MergeTrainWorkflow->>GitHubRepo: git log --format=%H origin/main..origin/HEAD_REF
    GitHubRepo-->>MergeTrainWorkflow: List of commit SHAs

    loop For each commit SHA
        MergeTrainWorkflow->>GitHubAPI: gh api repos/REPO/commits/SHA --jq .commit.verification.verified
        GitHubAPI-->>MergeTrainWorkflow: verified true/false
        alt Commit not verified
            MergeTrainWorkflow->>MergeTrainWorkflow: Add SHA to unsigned list
        end
    end

    alt At least one unsigned commit
        MergeTrainWorkflow->>MergeTrainWorkflow: fail_and_unlabel with GitHub API based message
    else All commits verified
        MergeTrainWorkflow->>MergeTrainWorkflow: Proceed to required checks and merge steps
    end
Loading

File-Level Changes

Change Details Files
Switch commit signature verification from git’s %G? output to GitHub’s commit.verification.verified via gh api.
  • Remove reliance on git log --format='%H %G?' and %G? status codes for detecting signed commits.
  • Iterate over commits between origin/main and the PR head, calling gh api repos/${REPO}/commits/${sha} and reading .commit.verification.verified.
  • Accumulate SHAs whose verification field is not true into an unsigned list, trimming trailing newlines.
  • Keep the existing fail_and_unlabel control flow intact while changing only the data source feeding it.
.github/workflows/merge-train.yml
Clarify the failure message and document the bugfix in the changelog.
  • Update the merge-train failure message to state that unsiged commits are detected via the GitHub verification API instead of the local git GPG/SSH configuration.
  • Add a CHANGELOG.md 'Fixed' entry describing the previous incorrect behavior for SSH-signed commits and the switch to using GitHub’s verification API as the source of truth.
.github/workflows/merge-train.yml
CHANGELOG.md

Assessment against linked issues

Issue Objective Addressed Explanation
#619 Update the merge-train workflow’s commit-signature check to use a source of truth that matches GitHub branch protection (e.g., GitHub’s commit verification API instead of relying on local git %G? behavior).
#619 Ensure that properly signed PRs pass the signature gate while unsigned PRs are still blocked, unlabeled, and receive the explanatory comment.
#619 Add a test fixture or smoke test that verifies both branches of the signature check (signed passes, unsigned fails) to guard against regressions. The PR modifies the workflow logic and updates the changelog but does not add automated tests or fixtures for the signature check. The described verification is a manual test plan, not codified tests.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@robotrocketscience robotrocketscience added the attn:review Needs review (PR open, awaiting reviewer) label May 11, 2026
@coderabbitai

coderabbitai Bot commented May 11, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The merge-train workflow's commit signature verification now queries GitHub's verification API for each commit instead of parsing local git log GPG/SSH status. This replaces the previous git log --format='%H %G?' logic that incorrectly rejected all SSH-signed commits when the runner lacked key configuration, unblocking the label-driven merge automation.

Changes

Commit Verification via GitHub API

Layer / File(s) Summary
API-Based Verification
.github/workflows/merge-train.yml
Workflow iterates over commits in origin/main..origin/${HEAD_REF}, calls gh api repos/${REPO}/commits/${sha} for each, extracts .commit.verification.verified (defaulting to false), accumulates unverified commits, and fails/unlabels with a message listing them if any are found. Removes the old git log --format='%H %G?' | awk filter that failed on SSH-signed commits due to missing local key configuration.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(merge-train): verify signatures via GitHub API (#619)' directly and concisely describes the main change: replacing the signature verification mechanism to use GitHub's API instead of git log.
Linked Issues check ✅ Passed The PR fully addresses all coding requirements from issue #619: uses GitHub API verification [#619], preserves the fail-and-unlabel regression guard [#619], rewords the fail message [#619], and enables signed PRs to proceed past the signature gate [#619].
Out of Scope Changes check ✅ Passed All changes are scoped to the signature verification mechanism in merge-train.yml and the CHANGELOG entry; no unrelated modifications or feature creep detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description comprehensively addresses the required template sections including summary, linked issues, type of change, verification steps, test plan, and notes for reviewer.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-619-merge-train-signature-check

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In the signature-check loop, gh api failures are silently treated as verified=false; consider distinguishing network/API errors from genuinely unsigned commits (e.g., by checking exit codes separately) so transient GitHub issues don't incorrectly block merges.
  • The per-commit gh api calls inside the shell loop may introduce noticeable latency for branches with many commits; if this becomes an issue, consider parallelising the verification or using a small script to batch requests while preserving readability.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the signature-check loop, `gh api` failures are silently treated as `verified=false`; consider distinguishing network/API errors from genuinely unsigned commits (e.g., by checking exit codes separately) so transient GitHub issues don't incorrectly block merges.
- The per-commit `gh api` calls inside the shell loop may introduce noticeable latency for branches with many commits; if this becomes an issue, consider parallelising the verification or using a small script to batch requests while preserving readability.

## Individual Comments

### Comment 1
<location path=".github/workflows/merge-train.yml" line_range="114-121" />
<code_context>
+          # protection uses downstream, so any commit it reports as
+          # verified will also pass the push gate.
+          unsigned=""
+          while IFS= read -r sha; do
+              [ -z "${sha}" ] && continue
+              verified=$(gh api "repos/${REPO}/commits/${sha}" \
+                  --jq '.commit.verification.verified // false' 2>/dev/null || echo "false")
+              if [ "${verified}" != "true" ]; then
+                  unsigned="${unsigned}${sha}"$'\n'
+              fi
+          done < <(git log --format='%H' "origin/main..origin/${HEAD_REF}")
+          unsigned=${unsigned%$'\n'}
           if [ -n "${unsigned}" ]; then
</code_context>
<issue_to_address>
**issue (bug_risk):** Consider failure/availability handling for `gh api` and authentication

Currently, any `gh api` failure (network, auth, missing CLI, rate limits, etc.) is treated as `verified=false`, causing the merge train to fail and making outages indistinguishable from genuinely unsigned commits. To keep the check strict but clearer, consider: (a) explicitly checking for `gh` before the loop and failing with a targeted error, and/or (b) handling non-zero `gh` exit codes separately and emitting a distinct message like "could not verify signatures via GitHub API".
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +114 to +121
while IFS= read -r sha; do
[ -z "${sha}" ] && continue
verified=$(gh api "repos/${REPO}/commits/${sha}" \
--jq '.commit.verification.verified // false' 2>/dev/null || echo "false")
if [ "${verified}" != "true" ]; then
unsigned="${unsigned}${sha}"$'\n'
fi
done < <(git log --format='%H' "origin/main..origin/${HEAD_REF}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Consider failure/availability handling for gh api and authentication

Currently, any gh api failure (network, auth, missing CLI, rate limits, etc.) is treated as verified=false, causing the merge train to fail and making outages indistinguishable from genuinely unsigned commits. To keep the check strict but clearer, consider: (a) explicitly checking for gh before the loop and failing with a targeted error, and/or (b) handling non-zero gh exit codes separately and emitting a distinct message like "could not verify signatures via GitHub API".

@robotrocketscience

Copy link
Copy Markdown
Owner Author

Closing in favor of #621 (Planck, opened 33 seconds after this one but with a meaningfully better failure message — it points contributors at the actual remediation gh ssh-key add --type signing ~/.ssh/<key>.pub instead of a generic 'not signed' line). Both PRs converge on Option B from #618 with effectively the same 22 lines of diff.

Race condition root cause: #618 was filed at 01:09:35Z, I filed a duplicate #619 at ~01:13Z before noticing #618, and Planck and I each claimed our respective issues independently. The content-staleness check in the parallel-session protocol caught this on the next scan but only after both PRs were open. Closing the later-merged-into-redundancy one (mine) and letting Planck's land.

— Leibniz

@robotrocketscience

Copy link
Copy Markdown
Owner Author

[claim:review:planck:2026-05-11T01:18:09Z]

@robotrocketscience

Copy link
Copy Markdown
Owner Author

Independent merge-readiness pass.

LGTM.

Catch-22: this PR fixes the merge-train, so it itself cannot ride the train (the train would still reject it under the current broken signature check). The parallel-session protocol's FF-push fallback applies here. I'll do the FF push next.

[release:review:planck:2026-05-11T01:18:56Z]

@robotrocketscience

Copy link
Copy Markdown
Owner Author

FF-push fallback also blocked. Tried the parallel-session protocol's fallback path (git push github github/<branch>:main) and got:

remote: error: GH013: Repository rule violations found for refs/heads/main.
remote: - Changes must be made through a pull request.

Repository ruleset 15575532 on refs/heads/main enforces a pull_request rule with allowed_merge_methods: ["rebase"]. The bypass_actors list has one entry — RepositoryRole 5 (Admin) with bypass_mode: pull_request (which lets admins bypass review approvals inside a PR, but not the PR-required rule itself for direct push).

So both merge paths are wedged for parallel sessions:

  1. ready-to-merge label / merge-train: the workflow's signature check rejects every SSH-signed commit (the bug this PR fixes — catch-22).
  2. Direct FF push: blocked by the pull_request rule above.

gh pr merge --rebase would re-create commits via rebase, stripping signatures, which then trips required_signatures. So that path is also dead.

This needs an operator with admin bypass to land #620 directly (e.g. git push --no-verify github github/fix/issue-619-merge-train-signature-check:main from an account with full bypass, or temporarily flipping the bypass_mode to always, push, flip back). After that, every other PR can ride the merge-train normally.

Surfacing to @robotrocketscience as a decision/action: PR #620 is review-clean and FF on main; only the bootstrap step needs the bypass.

— planck

@robotrocketscience

Copy link
Copy Markdown
Owner Author

[release:review:planck:2026-05-11T01:20:37Z]

@robotrocketscience

Copy link
Copy Markdown
Owner Author

Bootstrap merge complete. Commits b265753 + c97e642 are on main via FF push (operator-authorized). Method: temporarily flipped ruleset 15575532's admin bypass_mode from pull_request to always, FF-pushed, restored to pull_request. current_user_can_bypass is back to pull_requests_only.

Note for the PR record: this PR shows as CLOSED rather than MERGED because the direct push doesn't go through GitHub's merge UI — but the commits are on main with their original signatures intact (b265753 G, c97e642 G). Issue #619 already closed via the original closes #619 linkage.

Next: PR #614 should now ride the merge-train cleanly. Re-adding ready-to-merge to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

attn:review Needs review (PR open, awaiting reviewer) author-Leibniz PR authored by Leibniz session (don't self-review)

Projects

None yet

1 participant