ci: restrict self-hosted runner jobs to non-fork PRs#2096
Conversation
Jobs ci-build-test, ci-images (ci.yaml) and diff (image-check.yaml) run on distroless-ci-large-ubuntu-22.04 self-hosted runners and execute code from the checked-out repository (Bazel BUILD files, diff.bash). Without a fork guard, fork PRs trigger these jobs, giving fork code access to the runner's GCP credentials. Add an if condition to each affected job so that pull_request events from forks are skipped. workflow_dispatch and push events are unaffected.
|
Note Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported. |
|
I think you have made incorrect assumptions on how our builds work and are gated. |
|
Thank you for the feedback — could you clarify what mechanism you're referring to? From the workflow YAML as currently written:
If the |
Summary
Jobs
ci-build-testandci-imagesinci.yaml, anddiffinimage-check.yaml, run on thedistroless-ci-large-ubuntu-22.04self-hosted runner. These jobs check out the PR author's code and execute it (Bazel BUILD rules,private/tools/diff/diff.bash) on the runner without any fork restriction.An attacker who opens a PR from a fork can modify
BUILDfiles to include a maliciousgenrule, or modifyprivate/tools/diff/diff.bash, and have that code execute on the self-hosted runner. Self-hosted GCP runners have GCE service account credentials accessible via the metadata server (http://metadata.google.internal/).Affected jobs (no fork guard at job level):
ci.yaml→ci-build-test(runs fork's Bazel targets +bazel test //...)ci.yaml→ci-images(runs fork's Bazel image tests)image-check.yaml→diff(runsbazel build //:sign_and_push+./private/tools/diff/diff.bashfrom fork)Note:
image-check.yamlhas fork checks on comment-posting steps, but not on the build/execution steps where the actual risk exists.Fix
Add
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repositoryto each affected job:pushandworkflow_dispatchevents are unaffectedTest plan
ci-build-test,ci-images, anddiffjobs (expected: jobs show as skipped in workflow run)