Skip to content

Commit 6324144

Browse files
committed
ci: restrict credentialed Custard test job to trusted refs
The test job in custard-run.yaml runs on the workflow_run event in the base-repository context with id-token: write and authenticates to Google Cloud as kokoro-system-test@long-door-651. It checks out the triggering commit and runs `make test`, which runs `npm install` and `npm test`. With only `if: needs.affected.outputs.paths != '[]'`, a pull request opened from a fork reaches this job, so fork-controlled npm lifecycle and test scripts run with the service account credentials present in the workspace. Gate the job so it runs only for trusted refs: same-repo branches on workflow_run, plus push and workflow_dispatch. Fork pull requests no longer execute their code in this privileged context. This matches the boundary the legacy test job in custard-ci.yaml already enforces (github.event.pull_request.head.repo.fork == false).
1 parent 1d8c421 commit 6324144

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

.github/workflows/custard-run.yaml

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

104104
test:
105-
if: needs.affected.outputs.paths != '[]'
105+
# These tests authenticate to Google Cloud as the
106+
# kokoro-system-test@long-door-651 service account and run repository code
107+
# (make test -> npm install -> npm test), so they must only run on trusted
108+
# refs. For workflow_run triggers, limit execution to same-repo branches.
109+
# Pull requests from forks do not reach the service account credentials or
110+
# execute their code in this privileged context; push (post-merge) and
111+
# workflow_dispatch runs are unaffected. The legacy test job in
112+
# custard-ci.yaml enforces the same boundary with
113+
# `github.event.pull_request.head.repo.fork == false`.
114+
if: >-
115+
needs.affected.outputs.paths != '[]' &&
116+
(github.event_name != 'workflow_run' ||
117+
github.event.workflow_run.head_repository.full_name == github.repository)
106118
needs: affected
107119
runs-on: ubuntu-latest
108120
timeout-minutes: 120 # 2 hours hard limit

0 commit comments

Comments
 (0)