From 4f4da033b3c298fab56c7d21b38f734b092f7ccd Mon Sep 17 00:00:00 2001 From: Moritz Clasmeier Date: Mon, 18 May 2026 13:26:29 +0200 Subject: [PATCH] Guard CI workflows against fork PRs provisioning infrastructure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add fork-origin checks to all jobs in pr.yml and docker-build.yml that depend on repository secrets or provision real infrastructure (GKE and OpenShift clusters via infractl). The guard `github.event.pull_request.head.repo.full_name == github.repository` ensures these jobs only run for PRs originating from the same repository, not from external forks. This is defensive infrastructure practice for public repositories because: 1. GitHub withholds repository secrets from fork PRs by design, so secret-dependent jobs (registry login, infra token auth, GCP SA) would fail anyway — but they fail late, after consuming CI minutes and producing confusing check statuses. 2. More critically, this prevents a future misconfiguration from becoming a security incident. If someone later changes the trigger from `pull_request` to `pull_request_target` (a common "fix" for the fork-secrets problem), the guard still blocks fork PRs from accessing INFRA_CI_TOKEN, ROXIE_CI_AUTOMATION_GCP_SA, and the ability to provision or delete GKE/OpenShift clusters on internal infrastructure. 3. Without the guard, fork PRs can trigger cluster creation attempts that fail with opaque auth errors, wasting time for both the contributor and reviewers trying to interpret the CI results. For docker-build.yml, the guard additionally allows push events (tag and branch pushes) to pass through unconditionally, since those are not subject to the fork-PR threat model. Co-Authored-By: Claude Opus 4.6 --- .github/workflows/docker-build.yml | 1 + .github/workflows/pr.yml | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 2fa98a5..16042b4 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -14,6 +14,7 @@ env: jobs: docker-build-push: + if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository name: Build and Push Multi-arch Image runs-on: ubuntu-latest permissions: diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 8da1082..126016b 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -29,6 +29,7 @@ jobs: fi create-gke-cluster: + if: github.event.pull_request.head.repo.full_name == github.repository uses: ./.github/workflows/create-dev-cluster.yml with: cluster-name: infra-roxie-pr-${{ github.event.pull_request.number }}-gke @@ -38,7 +39,7 @@ jobs: create-openshift-cluster: needs: check-olm-label - if: needs.check-olm-label.outputs.has-label == 'true' + if: needs.check-olm-label.outputs.has-label == 'true' && github.event.pull_request.head.repo.full_name == github.repository uses: ./.github/workflows/create-dev-cluster.yml with: cluster-name: infra-roxie-pr-${{ github.event.pull_request.number }}-openshift @@ -47,6 +48,7 @@ jobs: secrets: inherit build-roxie-image: + if: github.event.pull_request.head.repo.full_name == github.repository uses: ./.github/workflows/build-roxie-image.yml permissions: contents: read @@ -54,6 +56,7 @@ jobs: secrets: inherit e2e-tests: + if: github.event.pull_request.head.repo.full_name == github.repository needs: [ create-gke-cluster, build-roxie-image ] uses: ./.github/workflows/e2e-tests.yml with: @@ -62,6 +65,7 @@ jobs: secrets: inherit e2e-tests-openshift: + if: github.event.pull_request.head.repo.full_name == github.repository needs: [ create-openshift-cluster, build-roxie-image ] uses: ./.github/workflows/e2e-tests.yml with: @@ -72,7 +76,7 @@ jobs: secrets: inherit delete-gke-cluster: - if: ${{ always() && needs.create-gke-cluster.result == 'success' }} + if: ${{ always() && needs.create-gke-cluster.result == 'success' && github.event.pull_request.head.repo.full_name == github.repository }} needs: [ create-gke-cluster, e2e-tests ] uses: ./.github/workflows/delete-dev-cluster.yml with: @@ -80,7 +84,7 @@ jobs: secrets: inherit delete-openshift-cluster: - if: ${{ always() && needs.create-openshift-cluster.result == 'success' }} + if: ${{ always() && needs.create-openshift-cluster.result == 'success' && github.event.pull_request.head.repo.full_name == github.repository }} needs: [ create-openshift-cluster, e2e-tests-openshift ] uses: ./.github/workflows/delete-dev-cluster.yml with: