Skip to content

ci: pin security review to the PR head commit - #3425

Open
jakemas wants to merge 1 commit into
aws:mainfrom
jakemas:ci-security-review-pin-sha
Open

ci: pin security review to the PR head commit#3425
jakemas wants to merge 1 commit into
aws:mainfrom
jakemas:ci-security-review-pin-sha

Conversation

@jakemas

@jakemas jakemas commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

security-review.yml starts the CodeBuild review with SOURCE_VERSION="pr/<number>". CodeBuild resolves that ref when it fetches the source, so it races pushes to the PR, while the commit status is posted against github.event.pull_request.head.sha. When those disagree a maintainer sees security-review / report: success on the commit they are about to merge, for a review of different code. It is the only unpinned reference in the workflow — the checkout (line 60) and the status (line 128) already use head.sha.

Seen on #3277: three runs completed success for 82871d85d, 4d12f7bb6 and dcb7a8317, while the report stayed on a5bf56b3 and kept listing findings already fixed in the newer commits. The workflow only checks that CodeBuild exited cleanly, never which commit it fetched.

Fix: use the reference-and-commit-ID form, refs/pull/<number>/head^{<sha>}. Per the source version docs a bare commit ID would make CodeBuild "download the entire repository to find the version", while naming the ref means it "downloads only the specified branch" — so this pins the commit without the clone cost pr/<number> avoids. It also does not change what is reviewed: the docs give the pull request form as refs/pull/1/head, so pr/<number> already resolved to the PR head, not a merge commit.

Not runnable outside this repo's CI (needs the SecurityReview-aws-lc project and OIDC role). Verified offline: the workflow parses, the value renders to refs/pull/3277/head^{dcb7a8317...} and survives the quoted shell expansion, and the other pull_request.number uses are correctly per-PR.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@jakemas
jakemas requested a review from a team as a code owner August 13, 2026 04:37
@jakemas
jakemas force-pushed the ci-security-review-pin-sha branch 2 times, most recently from c26dbae to 83c090b Compare August 13, 2026 04:39
The security review passed SOURCE_VERSION="pr/<number>" to
`aws codebuild start-build`. CodeBuild resolves that when it fetches the
source, so it races updates to the pull request: if the PR is pushed to
while a run is queued, CodeBuild can fetch a different commit than the
one that triggered the workflow, while the commit status is attached to
github.event.pull_request.head.sha. The reported result can then describe
a different commit than the one being merged.

Use the reference-and-commit-ID form instead,
refs/pull/<number>/head^{<sha>}. This pins the exact commit while still
naming the ref, so CodeBuild downloads only that ref rather than the
whole repository, which a bare commit ID would require. pr/<number>
already resolves to refs/pull/<number>/head, so the code being reviewed
is unchanged.
@jakemas
jakemas force-pushed the ci-security-review-pin-sha branch from 83c090b to 94f7945 Compare August 13, 2026 04:41
@jakemas jakemas changed the title ci: pin security review to the PR head SHA, not the pr/N ref ci: pin security review to the PR head commit Aug 13, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.22%. Comparing base (1b0a9fe) to head (94f7945).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3425      +/-   ##
==========================================
- Coverage   78.24%   78.22%   -0.02%     
==========================================
  Files         696      696              
  Lines      124511   124511              
  Branches    17279    17280       +1     
==========================================
- Hits        97418    97404      -14     
- Misses      26168    26183      +15     
+ Partials      925      924       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nhatnghiho nhatnghiho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for catching this! I have updated the security reviewer to work with this new source version. Tested locally that this new source version works

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants