Merge rust-bitcoin/rust-bitcoin#7139: ops: harden ci workflows
What changed, and why it matters
This commit tightens three GitHub Actions workflows to reduce the risk of supply-chain or repository-manipulation attacks. It removes an unused high-power permission (id-token: write), makes a CI-failure issue-matching script only trust issues created by the GitHub Actions bot, and validates data pulled from untrusted pull-request workflow artifacts before using it to label or comment on pull requests. These are defensive hardening changes rather than fixes for a known active exploit.
No immediate user action is required. Reviewers should verify the new validation logic covers all artifact-consuming steps and consider applying similar hardening to any other workflows that consume artifacts from pull_request runs.
Security signals we found
Removal of excessive workflow permission (id-token: write)
Validation of untrusted PR-produced artifact contents before use
Cross-check of PR head SHA against triggering workflow_run head_sha
Restriction of issue matching to github-actions[bot] author
Defensive hardening of CI labeler and failure-issue workflows
Evidence from the diff
The patch hardens CI/CD workflows: (1) removes id-token: write from the weekly nightly-update job, eliminating an unnecessary OIDC token minting capability; (2) restricts ci-failure-issues issue matching to issues authored by github-actions[bot] and containing the expected marker, preventing a malicious issue from being mistaken for a previously filed CI failure; (3) in ci-labeller, validates that PR number and exit-code fields from workflow-run artifacts are numeric, and cross-checks the artifact’s PR number against the head SHA of the triggering workflow_run before editing labels or posting comments. This closes a path where a malicious PR could craft artifact contents to manipulate labels or comments on arbitrary PRs.
Changed components
.github/workflows/ci-failure-issues.yml.github/workflows/ci-labeller.yml.github/workflows/cron-weekly-update-nightly.ymlInspect captured patch +27 / −5
### .github/workflows/ci-failure-issues.yml
@@ -70,8 +70,11 @@ jobs:
per_page: 100,
});
+ // Only trust issues opened by this workflow
const existing = issues.find(issue =>
- !issue.pull_request && issue.body && issue.body.includes(marker)
+ !issue.pull_request &&
+ issue.user?.login === "github-actions[bot]" &&
+ issue.body && issue.body.includes(marker)
);
if (run.conclusion === "failure" && !existing) {
### .github/workflows/ci-labeller.yml
@@ -39,23 +39,43 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
+ HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
issue_number=$(head -n1 api-diff)
exit_code=$(tail -n1 api-diff)
+ # The artifact is produced by an untrusted PR run, validate it before use.
+ if ! [[ "$issue_number" =~ ^[0-9]+$ && "$exit_code" =~ ^[0-9]+$ ]]; then
+ echo "::error::Malformed api-diff artifact"
+ exit 1
+ fi
+ if [ "$(gh pr view "$issue_number" --json headRefOid --jq .headRefOid)" != "$HEAD_SHA" ]; then
+ echo "::notice::PR #$issue_number head does not match the triggering run, skipping"
+ exit 0
+ fi
toggle=$([ "$exit_code" -eq 0 ] && echo "--remove-label" || echo "--add-label")
- gh pr edit $issue_number $toggle "API diff"
+ gh pr edit "$issue_number" "$toggle" "API diff"
# The semver break artifact must have the PR number on the first line,
# and the exit code of the semver check on the second line.
- name: "Toggle API break Label"
if: ${{ hashFiles('semver-break') != '' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
+ HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
issue_number=$(head -n1 semver-break)
exit_code=$(tail -n1 semver-break)
+ # The artifact is produced by an untrusted PR run, validate it before use.
+ if ! [[ "$issue_number" =~ ^[0-9]+$ && "$exit_code" =~ ^[0-9]+$ ]]; then
+ echo "::error::Malformed semver-break artifact"
+ exit 1
+ fi
+ if [ "$(gh pr view "$issue_number" --json headRefOid --jq .headRefOid)" != "$HEAD_SHA" ]; then
+ echo "::notice::PR #$issue_number head does not match the triggering run, skipping"
+ exit 0
+ fi
toggle=$([ "$exit_code" -eq 0 ] && echo "--remove-label" || echo "--add-label")
- gh pr edit $issue_number $toggle "API break"
+ gh pr edit "$issue_number" "$toggle" "API break"
if [ "$exit_code" -ne 0 ]; then
- gh pr comment $issue_number --body 'API BREAKING CHANGE DETECTED!'
+ gh pr comment "$issue_number" --body 'API BREAKING CHANGE DETECTED!'
fi
### .github/workflows/cron-weekly-update-nightly.yml
@@ -10,7 +10,6 @@ jobs:
runs-on: ubuntu-24.04
permissions:
contents: write
- id-token: write
pull-requests: write
strategy:
fail-fast: falseWhy this scored 37/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.