ci: do not run fork PR code on the self-hosted runner#340
Open
evilgensec wants to merge 1 commit into
Open
Conversation
The lint and test jobs run on a self-hosted runner and check out and execute the pull request head (pip install -r requirements.txt, pytest, pylint over src/gcp_scanner/*.py). On a pull_request event this also runs for PRs from forks, so any external contributor can execute arbitrary code on the runner. The runner is a persistent GCE instance with an attached service account: the acceptance test (src/gcp_scanner/test_acceptance.py) scans the live project test-gcp-scanner-2 using credsdb.get_creds_from_metadata(), which reads an OAuth token from the instance metadata server. Fork PR code on that runner can read the same metadata token and steal the service-account credential, even though no secrets are passed to the job. Guard both self-hosted jobs so they run only on pushes and on pull requests originating from this repository, not from forks.
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.
Problem
.github/workflows/python-app.ymlruns thelintandtestjobs onruns-on: self-hostedand triggers onpull_request. Both jobs check out and execute the pull request head:pip install -r requirements.txt(line 40 / 74)pylint ... src/gcp_scanner/*.py(line 46)pytest(line 77)On a
pull_requestevent these jobs also run for pull requests opened from forks, with no fork guard, author-association check, or environment approval. An external contributor can open a PR that adds atest_*.py(collected bypytest), or pointsrequirements.txtat a package with a build hook, and run arbitrary code on the self-hosted runner.The self-hosted runner is a persistent GCE instance with an attached service account. The acceptance test (
src/gcp_scanner/test_acceptance.py) scans the live projecttest-gcp-scanner-2viacredsdb.get_creds_from_metadata(), which reads an OAuth token fromhttp://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token. Fork PR code on that runner can read the same metadata token and exfiltrate the service-account credential, even though the job receives nosecrets.*.Fix
Add a job-level guard so the self-hosted jobs run only on pushes and on pull requests that originate from this repository (not from forks):
Pushes to
mainand same-repo branch PRs continue to run unchanged. Fork PRs no longer execute on the credentialed self-hosted runner.This mirrors the guard applied to other Google self-hosted CI workflows that run on
pull_request.