From adcb1662671fcfa36ab34dbc7994c6c208ca534a Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Tue, 20 Oct 2026 13:25:31 +0200 Subject: [PATCH] ci: keep the EE token out of agent jobs on fork PRs and out of .git/config Co-Authored-By: Claude Opus 5.5 --- .github/workflows/claude.yml | 102 +++++++++++++++++++------- .github/workflows/codex-pr-review.yml | 1 + .github/workflows/git-commands.yaml | 25 ++++--- .github/workflows/pi-pr-review.yml | 1 + .github/workflows/pr-ready-review.yml | 1 + 5 files changed, 92 insertions(+), 38 deletions(-) diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index 5250c5a04b..2df9c062a6 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -24,11 +24,49 @@ jobs: username: ${{ github.event.comment.user.login || github.event.review.user.login || github.event.issue.user.login }} secrets: inherit - claude-code-action: + # The agent runs with unrestricted Bash and reads PR text anyone can write, so a job + # that references WINDMILL_EE_PRIVATE_ACCESS hands it that token: the runner holds + # every secret its job references (a skipped step's included) in process memory. EE is + # therefore checked out only in a separate job, and only for PRs whose head branch + # lives in this repo; forks, issues and token-less runs take the job without it. + pr-info: needs: [check-access] if: | needs.check-access.outputs.authorized == 'true' || contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association || github.event.review.author_association || github.event.issue.author_association) + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + outputs: + ee_repo_ref: ${{ steps.pr.outputs.ee_repo_ref }} + steps: + # The EE ref is read from the PR head's backend/ee-repo-ref.txt (via the API, so it + # reflects the PR's EE pin regardless of which ref the agent job checks out). + - name: Resolve EE ref for same-repo PRs + id: pr + env: + HAS_EE_TOKEN: ${{ secrets.WINDMILL_EE_PRIVATE_ACCESS != '' }} + GH_TOKEN: ${{ github.token }} + PR_NUMBER: ${{ github.event.issue.number || github.event.pull_request.number }} + run: | + if [ "$HAS_EE_TOKEN" != "true" ] || [ -z "$PR_NUMBER" ]; then + exit 0 + fi + # Fails for a plain issue, which gets no EE. + PR=$(gh api "repos/${{ github.repository }}/pulls/$PR_NUMBER") || exit 0 + # head.repo is null when the fork was deleted. + if [ "$(jq -r '.head.repo.full_name' <<<"$PR")" != "${{ github.repository }}" ]; then + echo "PR head is not in this repo; running without EE." + exit 0 + fi + HEAD_SHA=$(jq -r '.head.sha' <<<"$PR") + REF=$(gh api "repos/${{ github.repository }}/contents/backend/ee-repo-ref.txt?ref=$HEAD_SHA" --jq .content | base64 -d | tr -d '[:space:]') || true + echo "ee_repo_ref=$REF" >> "$GITHUB_OUTPUT" + + claude-code-action-ee: + needs: [pr-info] + if: needs.pr-info.outputs.ee_repo_ref != '' runs-on: ubicloud-standard-8 permissions: contents: write @@ -40,43 +78,22 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 1 + persist-credentials: false # Make the EE source (the *_ee.rs files in the companion repo) available so the # reviewer can see EE-only code (e.g. windmill-queue/src/jobs_ee.rs), not just the - # CE surface. The EE ref is read from the PR head's backend/ee-repo-ref.txt (via the - # API, so it reflects the PR's EE pin regardless of which ref is checked out here). - - name: Check EE access - id: ee - env: - EE_TOKEN: ${{ secrets.WINDMILL_EE_PRIVATE_ACCESS }} - GH_TOKEN: ${{ github.token }} - PR_NUMBER: ${{ github.event.issue.number || github.event.pull_request.number }} - run: | - if [ -z "$EE_TOKEN" ] || [ -z "$PR_NUMBER" ]; then - echo "available=false" >> "$GITHUB_OUTPUT" - exit 0 - fi - HEAD_SHA=$(gh api "repos/${{ github.repository }}/pulls/$PR_NUMBER" --jq .head.sha) - REF=$(gh api "repos/${{ github.repository }}/contents/backend/ee-repo-ref.txt?ref=$HEAD_SHA" --jq .content | base64 -d | tr -d '[:space:]') - if [ -z "$REF" ]; then - echo "available=false" >> "$GITHUB_OUTPUT" - else - echo "available=true" >> "$GITHUB_OUTPUT" - echo "ee_repo_ref=$REF" >> "$GITHUB_OUTPUT" - fi - + # CE surface. - name: Checkout EE repository - if: steps.ee.outputs.available == 'true' uses: actions/checkout@v4 with: repository: windmill-labs/windmill-ee-private path: ./windmill-ee-private - ref: ${{ steps.ee.outputs.ee_repo_ref }} + ref: ${{ needs.pr-info.outputs.ee_repo_ref }} token: ${{ secrets.WINDMILL_EE_PRIVATE_ACCESS }} fetch-depth: 1 + persist-credentials: false - name: Substitute EE code - if: steps.ee.outputs.available == 'true' run: ./backend/substitute_ee_code.sh --copy --dir ./windmill-ee-private - name: Run Claude PR Action @@ -94,3 +111,36 @@ jobs: claude_args: | --allowedTools "Bash,WebFetch,WebSearch" --model claude-opus-5-5 + + claude-code-action: + needs: [pr-info] + if: needs.pr-info.outputs.ee_repo_ref == '' + runs-on: ubicloud-standard-8 + permissions: + contents: write + pull-requests: write + issues: write + id-token: write + steps: + # claude-code-action installs its own git credential, so checkout's is not needed. + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 1 + persist-credentials: false + + - name: Run Claude PR Action + uses: anthropics/claude-code-action@v1 + with: + claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} + allowed_bots: "windmill-internal-app[bot]" + trigger_phrase: "/ai" + settings: | + { + "env": { + "SQLX_OFFLINE": "true" + } + } + claude_args: | + --allowedTools "Bash,WebFetch,WebSearch" + --model claude-opus-5-5 diff --git a/.github/workflows/codex-pr-review.yml b/.github/workflows/codex-pr-review.yml index 2d70ad7f7a..ee3ddf5660 100644 --- a/.github/workflows/codex-pr-review.yml +++ b/.github/workflows/codex-pr-review.yml @@ -209,6 +209,7 @@ jobs: ref: ${{ steps.ee.outputs.ee_repo_ref }} token: ${{ secrets.WINDMILL_EE_PRIVATE_ACCESS }} fetch-depth: 1 + persist-credentials: false - name: Substitute EE code if: steps.ee.outputs.available == 'true' diff --git a/.github/workflows/git-commands.yaml b/.github/workflows/git-commands.yaml index bf9009c800..a8eaef8e4d 100644 --- a/.github/workflows/git-commands.yaml +++ b/.github/workflows/git-commands.yaml @@ -69,12 +69,24 @@ jobs: ref: ${{ github.event.issue.pull_request.head.ref }} fetch-depth: 0 + - name: Read EE ref + id: ee + run: | + if [ -f backend/ee-repo-ref.txt ]; then + echo "ref=$(tr -d '[:space:]' < backend/ee-repo-ref.txt)" >> "$GITHUB_OUTPUT" + else + echo "Warning: ee-repo-ref.txt not found, using default branch" + fi + + # The PR's own build code runs below, so the EE token must not stay in .git/config. - name: Checkout windmill-ee-private uses: actions/checkout@v3 with: repository: windmill-labs/windmill-ee-private path: windmill-ee-private + ref: ${{ steps.ee.outputs.ref }} token: ${{ secrets.WINDMILL_EE_PRIVATE_ACCESS }} + persist-credentials: false # Setup Rust toolchain - uses: actions-rust-lang/setup-rust-toolchain@v1 @@ -108,18 +120,6 @@ jobs: git config pull.rebase true git pull origin $BRANCH_NAME - # Checkout the correct windmill-ee-private commit from ee-repo-ref.txt - if [ -f backend/ee-repo-ref.txt ]; then - EE_REF=$(cat backend/ee-repo-ref.txt | tr -d '[:space:]') - echo "Checking out windmill-ee-private at commit: $EE_REF" - cd windmill-ee-private - git fetch origin $EE_REF - git checkout $EE_REF - cd .. - else - echo "Warning: ee-repo-ref.txt not found, using default branch" - fi - mkdir -p frontend/build cd backend cargo install sqlx-cli --version 0.8.5 @@ -274,6 +274,7 @@ jobs: repository: windmill-labs/windmill-ee-private path: windmill-ee-private token: ${{ secrets.WINDMILL_EE_PRIVATE_ACCESS }} + persist-credentials: false - name: Get last commit hash of private-repo id: get-commit-hash diff --git a/.github/workflows/pi-pr-review.yml b/.github/workflows/pi-pr-review.yml index a18dc28ff2..9fa2350224 100644 --- a/.github/workflows/pi-pr-review.yml +++ b/.github/workflows/pi-pr-review.yml @@ -202,6 +202,7 @@ jobs: ref: ${{ steps.ee.outputs.ee_repo_ref }} token: ${{ secrets.WINDMILL_EE_PRIVATE_ACCESS }} fetch-depth: 1 + persist-credentials: false - name: Substitute EE code if: steps.ee.outputs.available == 'true' diff --git a/.github/workflows/pr-ready-review.yml b/.github/workflows/pr-ready-review.yml index 90714cba53..13638f3d46 100644 --- a/.github/workflows/pr-ready-review.yml +++ b/.github/workflows/pr-ready-review.yml @@ -120,6 +120,7 @@ jobs: ref: ${{ steps.ee.outputs.ee_repo_ref }} token: ${{ secrets.WINDMILL_EE_PRIVATE_ACCESS }} fetch-depth: 1 + persist-credentials: false - name: Substitute EE code if: steps.ee.outputs.available == 'true'