Skip to content

chore(ci): allow test_cloud workflow to run on labeled fork PRs - #805

Open
canbekley wants to merge 2 commits into
mainfrom
ci/fork-pr-cloud-tests
Open

canbekley wants to merge 2 commits into
mainfrom
ci/fork-pr-cloud-tests

Conversation

@canbekley

@canbekley canbekley commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

At the moment, fork PRs fail the test_cloud workflow because they don't set the cloud credentials. This PR enables running test_cloud on fork PRs via the maintainer label tests:run-cloud and the allow-unsafe-pr-checkout: true flag, similar to how clickhouse-go has set up their cloud tests (see run-tests-cloud.yml), but with some distinctions:

  • PRs opened from this repository (by maintainers) don't need the label to run test_cloud

Note

Medium Risk
pull_request_target with unsafe fork checkout runs contributor code with cloud credentials; risk is mitigated by maintainer-only labeling and explicit checkout controls, but mis-labeling or insufficient review could expose secrets.

Overview
Fork PRs can run ClickHouse cloud integration tests when a maintainer adds the tests:run-cloud label, using a pull_request_target + labeled trigger so workflows can access cloud secrets (which ordinary fork pull_request runs cannot).

The cloud_smt_tests job is gated so it still runs for in-repo PRs, manual dispatch, and nightly schedule without the label; only labeled fork runs use pull_request_target.

Checkout is adjusted for that path: ref pins to the PR head SHA at label time, allow-unsafe-pr-checkout enables fork code with secrets (with maintainer review expectation), and persist-credentials: false. Workflow permissions are set to read-only on contents.

Reviewed by Cursor Bugbot for commit 4c2ef2d. Bugbot is set up for automated code reviews on this repo. Configure here.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The workflow can test a commit other than the triggering SHA, while subsequent pushes to labeled fork PRs neither run cloud tests nor request renewed approval.

2 open issues
What changed in this PR

This PR enables maintainer-triggered ClickHouse Cloud integration tests for fork PRs, which cannot access cloud credentials through ordinary pull_request runs.

Changes:

  • Adds a tests:run-cloud label trigger for fork PRs while preserving in-repository, manual, and nightly runs.
  • Checks out the PR head commit for label-triggered runs.
  • Restricts token permissions to read-only contents and disables checkout credential persistence.
File Description
.github/​workflows/​test_cloud.yml Adds label-gated cloud testing and checkout controls for fork PRs.

Review effort: Balanced

Comment thread .github/workflows/test_cloud.yml Resolved
Comment thread .github/workflows/test_cloud.yml Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4c2ef2d. Configure here.

Comment thread .github/workflows/test_cloud.yml Resolved
@connectorsec

Copy link
Copy Markdown

ConnectorSec security review — head 4c2ef2d

1. The tests:run-cloud label runs an unreviewed fork commit with the Cloud password — .github/workflows/test_cloud.yml:43

  • Scenario: on the new pull_request_target path (L10-12) the job runs in the base-repo context with DBT_CH_TEST_HOST/DBT_CH_TEST_PASSWORD in the job env (L33-34), and L43 checks out pull_request.head.sha as it is at the moment the label is added, not the commit that was reviewed. A fork that pushes between the review and the label click gets its new commit run. Adding a label needs only triage access, and the labeled event is triggered by the maintainer, so no fork-run approval step applies on this path (the "fresh workflow approvals" in the description cover pull_request runs only). That commit then runs pip3 install . --group dev (L57: its build backend and any dev dependency it adds) and pytest (L64, L69: its conftest.py and tests), and either can send the password out, or print it encoded into the public run log (GitHub masks only the literal value). CONNECTORS_TEAM_TESTS_CLOUD_* are the same secret names the Cloud CI of other connector repos uses, so a leak would not stay within dbt-clickhouse.
  • Fix: drop the pull_request_target path (the fork skip in if: and the permissions: block already stop fork runs from failing) and run a fork PR in Cloud by dispatching the workflow with the exact SHA a maintainer reviewed: workflow_dispatch needs write access and runs that commit only. Reviewed fork code still sees the credential this way; a dbt-only Cloud credential for such runs would contain that.
-  # Fork PRs get no secrets on pull_request; a maintainer runs them by adding the label.
-  pull_request_target:
-    branches: main
-    types: [labeled]
   workflow_dispatch:
+    inputs:
+      sha:
+        description: 'Full head SHA of a reviewed fork PR (empty: the selected branch)'
+        required: false
+        default: ''
   schedule:
@@
       (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) ||
-      (github.event_name == 'pull_request_target' && github.event.label.name == 'tests:run-cloud') ||
       github.event_name == 'workflow_dispatch' ||
@@
         with:
-          # head.sha is fixed at label time, so later pushes need a fresh label.
-          ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.ref }}
-          # Fork code runs with secrets. a maintainer must review it before labeling.
-          # See https://gh.io/securely-using-pull_request_target
-          allow-unsafe-pr-checkout: true
+          # Exactly the commit a maintainer reviewed: gh workflow run test_cloud.yml -f sha=<full sha>
+          ref: ${{ inputs.sha || github.ref }}
           persist-credentials: false

Static review by ConnectorSec (ClickHouse Product Security); no PR code was executed.

@canbekley

canbekley commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

regarding what @connectorsec flagged. I'm not sure whether this is too defensive or not. the contributor would have to push a malicious commit within a small window between having reviewed the code and adding the label.
we also would have the exact same risk in other repositories that rely on this mechanism. the suggested mechanism with dispatched runs on confirmed sha's would work, but it wouldn't show up in the PRs workflow overview

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

A maintainer needs to validate the trust boundary for executing fork-controlled code with cloud credentials, including approval-label permissions and the cloud account’s isolation and privileges.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants