ci(terraform): restrict the privileged terraform job to non-fork PRs#2682
Open
adilburaksen wants to merge 1 commit into
Open
ci(terraform): restrict the privileged terraform job to non-fork PRs#2682adilburaksen wants to merge 1 commit into
adilburaksen wants to merge 1 commit into
Conversation
The terraform job authenticates with GCP credentials and runs `terraform init`/`plan` over the pull request's own .tf files. On `pull_request` this checks out fork-controlled code, and terraform init/plan execute that HCL (module sources, `external` data sources), so a fork PR can run arbitrary commands while the GCP service-account key and the Buildkite API token are in scope. The job's `if:` only checked that orgs changed; the intended "PR from trusted users" guard was never implemented, and the matrix environments (bazel / bazel-trusted / bazel-testing) have no required reviewers, so nothing stops a fork PR from reaching this job. Gate the job so fork pull requests can no longer reach it: run on push, or on pull requests that originate from this repository.
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/terraform.ymltriggers onpull_requestforbuildkite/terraform/**, and the privilegedterraformjob:credentials_json: ${{ secrets.GCP_SA_KEY }}, andterraform init/terraform planover the pull request's own.tffiles, withTF_VAR_buildkite_api_token: ${{ secrets.BUILDKITE_API_TOKEN }}in the environment.On a
pull_requestevent the defaultactions/checkoutchecks out the fork's code, andterraform init/planexecute attacker-controlled HCL — modulesourcefetching anddata "external"blocks run arbitrary programs duringplan. So a fork PR that edits a file underbuildkite/terraform/<org>/can run arbitrary commands in a job that already holds the GCP service-account key and the Buildkite API token, which is enough to exfiltrate both.The job's guard only checks that orgs changed:
The "PR from trusted users" part of that comment was never implemented, and the
bazel/bazel-trusted/bazel-testingenvironments have no required reviewers, so nothing currently prevents a fork PR from reaching this job (the only remaining barrier is GitHub's "approve fork PR workflows" click, which is routinely granted to prior contributors).Fix
Gate the privileged job so fork pull requests can no longer reach it, while keeping
pushand same-repo PR behaviour unchanged:This implements the originally-intended "trusted users" guard. (Alternatively / additionally, the three environments could be configured with required reviewers.)