ci: restrict credentialed Custard test job to trusted refs#4382
Open
evilgensec wants to merge 1 commit into
Open
ci: restrict credentialed Custard test job to trusted refs#4382evilgensec wants to merge 1 commit into
evilgensec wants to merge 1 commit into
Conversation
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).
Contributor
|
Note Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported. |
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.
What
Add a trust guard to the
testjob in.github/workflows/custard-run.yamlso it does not run repository code from forked pull requests while thekokoro-system-test@long-door-651service account credentials are configured.Why
custard-run.yamlis triggered byworkflow_run(Custard CI,types: [in_progress]) and therefore runs in the base-repository context. Thetestjob requestsid-token: write, authenticates withgoogle-github-actions/auth, and then runsmake test, which runsnpm install(repo root and the affected package) followed bynpm test.Its only condition today is
if: needs.affected.outputs.paths != '[]', with no check on where the triggering pull request came from. A pull request from a fork that adds apackage.jsonmarks a path as affected (.github/config/nodejs.jsoncsets"package-file": ["package.json"]), so the job runs, checks out the fork head commit (ref: github.event.workflow_run.head_sha), and executes the fork's npm lifecycle and test scripts.google-github-actions/authdefaults tocreate_credentials_file: trueandexport_environment_variables: true, soGOOGLE_APPLICATION_CREDENTIALSpoints at an impersonation credential for the service account before those scripts run. The result is fork-controlled code execution in the privileged context with access to the service account.The legacy
testjob incustard-ci.yamlalready refuses to run on forks (github.event.pull_request.head.repo.fork == false). This change applies the same trust boundary to theworkflow_runjob.Change
Run the credentialed
testjob only for trusted refs:workflow_runwhere the head repository equals this repository (same-repo branches)push(post-merge validation)workflow_dispatch(manual runs)Fork pull requests continue to get lint and region-tag feedback from
custard-ci.yaml, which runs in the unprivileged fork context without credentials. Integration tests that need the service account run once a maintainer lands the change on a branch in this repository or after merge.Alternative
If running integration tests on fork pull requests before merge is a requirement, the supported way to keep it is a GitHub Environment with required reviewers on this job, so every fork run pauses for an explicit per-run approval that is not skipped for returning contributors. That needs repository settings in addition to workflow changes, so it is out of scope for this PR. Happy to follow up if preferred.
Related, not in this PR
The
lintjob incustard-run.yamlalso checks out the head commit and runsnpm installin the base context, though with onlystatuses: writeand no service account.custard-ci.yamlalready lints forked pull requests in the unprivileged context, so that job could later move out of the privileged workflow. Left out here to keep this change minimal.Reported through the Google OSS VRP.