fix(ci): restrict workflow_run test jobs to same-repo runs only#4303
Open
adilburaksen wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
Open
fix(ci): restrict workflow_run test jobs to same-repo runs only#4303adilburaksen wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
adilburaksen wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
Conversation
Contributor
|
Note Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported. |
The `test` jobs in custard-run.yaml and custard-run-dev.yaml use
`workflow_run` as a trigger (fired by `Custard CI` running on PRs,
including fork PRs). These jobs have `id-token: write` and authenticate
to GCP via Workload Identity Federation as
kokoro-system-test@long-door-651.iam.gserviceaccount.com.
Without a repository guard, the `test` job runs for fork-triggered
workflow_run events. It checks out the fork's code at
`github.event.workflow_run.head_sha` and executes `make test`, allowing
attacker-controlled code to run with live GCP credentials.
Add a guard condition so the credentialed `test` job only fires when the
triggering workflow originated from the same repository (not a fork):
github.event.workflow_run.head_repository.full_name == github.repository
Non-workflow_run triggers (push, workflow_dispatch) are unaffected.
073fffd to
31ebe31
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
testjobs incustard-run.yamlandcustard-run-dev.yamluseworkflow_runas a trigger, which fires whenever theCustard CIworkflow runs — including when triggered by fork PRs.The vulnerability: These
testjobs haveid-token: writepermission and authenticate to GCP askokoro-system-test@long-door-651.iam.gserviceaccount.comvia Workload Identity Federation. They then check out code atgithub.event.workflow_run.head_sha(which can be a fork commit) and executemake test dir=${{ matrix.path }}.Attack path:
Makefileor test file in any affected pathCustard CIworkflow runs on the fork, triggeringcustard-run.yamlviaworkflow_runtestjob checks out the fork's commit and runsmake testwith live GCP credentialskokoro-system-test@long-door-651.iam.gserviceaccount.com(GCP WIF token)Fix: Add a guard condition on the
testjob so credentials are only used when the triggeringworkflow_runoriginated from the same repository:Push,
workflow_dispatch, and same-repo PR triggers are completely unaffected.Changes
.github/workflows/custard-run.yaml: Add fork guard totestjobif:condition.github/workflows/custard-run-dev.yaml: Same fixTest Plan
testjob runs normally (event_name != 'workflow_run'or same-repo check passes)workflow_run:testjob is skipped, no GCP credentials are issuedworkflow_dispatchruns: unaffected (condition short-circuits atevent_name != 'workflow_run')Reported to Google via OSS VRP. Fix PR submitted as part of responsible disclosure.