fix(ci): stop checking out event-controlled refs in privileged workflows - #1738
Conversation
OpenSSF Scorecard flagged three untrusted-code checkouts: the OpenAPI autocommit workflow checked out the pull request's head under pull_request_target, and the release job checked out workflow_run.head_sha. The autocommit workflow now runs on pull_request. It already refused forks, so pull_request_target gave it nothing and exposed the base branch's cache scope to the build. The release job checks out main and proves the built commit is an ancestor of origin/main before reading it. A contract test mirrors Scorecard's rule so it fails before merge, and pins the release guard. Written by Claude Fable 5.1 in Claude Code. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
There was a problem hiding this comment.
Approved automatically: @FelixTJDietrich is listed in the REVIEW_POLICY_MAINTAINERS repository variable, which the repository treats as satisfying the review requirement. See the review policy in docs/contributor/ci-cd.mdx.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe pull request updates workflow triggers, checkout credentials, and release commit validation. It adds CI contract coverage for unsafe event-derived checkouts and verifies that release commits belong to ChangesWorkflow security controls
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This change tightens privileged workflow checkout behavior and adds regression coverage; no actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Docstring CoverageExplanation No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1 files. (2 skipped: 2 unsupported.) ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
📚 Documentation Preview
|
🧩 Storybook Preview
|
What changed and why
OpenSSF Scorecard's Dangerous-Workflow check flagged three places where a privileged workflow checked out a ref taken from its own triggering event (1155, 1156, 1157). Under
pull_request_targetandworkflow_runthe job carries the base repository's token, so that pattern is the classic "pwn request" shape, whether or not the surrounding guards happen to make it safe today.openapi-autocommit.ymlnow runs onpull_requestinstead ofpull_request_target. The workflow already refused forks, so the privileged trigger bought nothing and only exposed the base branch's cache scope to the build it runs. The three-job split stays: the job that runs Maven and the OpenAPI generators holds no write token, and the job that pushes runs nothing from the checkout.release.ymlchecks outmainand, before reading anything from the commit CI/CD built, proves that commit is an ancestor oforigin/main. A force-pushed or foreign commit now fails the job instead of being released. Both credential-holding checkouts in the file droppersist-credentials.scripts/ci-contract.test.tsgains one test that mirrors Scorecard's rule, so a regression fails on the pull request rather than in the weekly scan after merge, and that pins the release guard the other release jobs depend on.Follow-up to #1736, which covered the top-level
permissionsand Maven wrapper findings from the same scan.How to test
CI covers the workflows: actionlint, zizmor and
pnpm run test:toolingall pass locally on this branch. The new test was checked both ways: restoring the oldhead_shacheckout fails it, and removing the ancestry guard fails it.After merge, add the
autocommit-openapilabel to a same-repository pull request. The API workflow should run on thepull_requestevent and push the regenerated spec and client to the branch as before.Release impact
None. Only workflows and a repository test change, none of which ship in an image, so
verify-changesetsdoes not ask for a changeset and operators have nothing to do.Notes for reviewers
main, so the three alerts close on the first scan after merge, not on this pull request.security-scan/*andtrivy-image-*uploads that no workflow produces any more, whose 240 alerts pointed at files or image digests that no longer exist), and I dismissed CodeQL alert 1103 with the same justification the earlier stateless-chain dismissals used. Neither is part of this diff.release.yml: the one-line comment on the guard is the only prose added there, and the diff is easiest to follow from the checkout down.Written by Claude Fable 5.1 in Claude Code.
Summary by CodeRabbit