Skip to content

Commit 31ebe31

Browse files
committed
fix(ci): restrict workflow_run test jobs to same-repo runs only
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.
1 parent 0f66e3e commit 31ebe31

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

.github/workflows/custard-run-dev.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ jobs:
5656
create-check-if: ${{ !!github.event.workflow_run }}
5757

5858
test:
59-
if: needs.affected.outputs.paths != '[]'
59+
# Guard: workflow_run fires for fork PRs but executes with repository secrets
60+
# (id-token: write / GCP WIF). Restrict credential use to same-repo runs.
61+
if: |
62+
needs.affected.outputs.paths != '[]' &&
63+
(github.event_name != 'workflow_run' || github.event.workflow_run.head_repository.full_name == github.repository)
6064
needs: affected
6165
runs-on: ubuntu-latest
6266
timeout-minutes: 120 # 2 hours hard limit

.github/workflows/custard-run.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ jobs:
102102
status: failure
103103

104104
test:
105-
if: needs.affected.outputs.paths != '[]'
105+
# Guard: workflow_run fires for fork PRs but executes with repository secrets
106+
# (id-token: write / GCP WIF). Restrict credential use to same-repo runs.
107+
if: |
108+
needs.affected.outputs.paths != '[]' &&
109+
(github.event_name != 'workflow_run' || github.event.workflow_run.head_repository.full_name == github.repository)
106110
needs: affected
107111
runs-on: ubuntu-latest
108112
timeout-minutes: 120 # 2 hours hard limit

0 commit comments

Comments
 (0)