Skip to content

ci: hard-block external-fork PRs; ban pull_request_target except audited project_automation.yml (closes #2757) - #2759

Merged
zackees merged 2 commits into
masterfrom
ci/block-fork-pr-workflows-2757
Jun 4, 2026
Merged

zackees merged 2 commits into
masterfrom
ci/block-fork-pr-workflows-2757

Conversation

@zackees

@zackees zackees commented Jun 4, 2026 •

Copy link
Copy Markdown
Member

Closes #2757.

What this PR does

Two related GitHub Actions hardening changes per user directive:

1. Hard-block external-fork PRs on all six pull_request-triggered workflows

Adds a job-level if: guard to the entry job of:

  • .github/workflows/build_esp32s3.yml
  • .github/workflows/build_teensy41.yml
  • .github/workflows/build_uno.yml
  • .github/workflows/build_wasm.yml
  • .github/workflows/example_test_linux.yml
  • .github/workflows/unit_test_linux.yml

The guard:

if: github.event.pull_request == null || github.event.pull_request.head.repo.full_name == github.repository
  • First clause: push / workflow_dispatch / schedule events have no pull_request context → always pass.
  • Second clause: matches only when the PR's head repo IS FastLED/FastLED. Fork PRs (e.g. JChalka/FastLED:master → FastLED/FastLED:master) fail this and the job evaluates to skipped.

User directive: "I do not want to run any workflow on any external fork that sends a PULL REQUEST. No exceptions."

2. Ban pull_request_target, with ONE documented exception (project_automation.yml)

User directive: "ban pull_request_target", followed by "actually okay project_automation.yml needs it on pull request trigger but you must audit it for problems".

Active pull_request_target triggers after this PR: exactly one — project_automation.yml. It's needed for PR-side project board sync (no other trigger has access to the App private key required to write to the project from a fork PR event).

build_clone_and_compile.yml: already had pull_request_target disabled via comment from a prior security incident — that pre-existing decision stays.

Audit of project_automation.yml (the one exception)

Verified holding all five safety invariants of safe pull_request_target usage:

Invariant How it's enforced Status
#1: No ref: on checkout (checkout must stay on base ref, NOT PR head) actions/checkout@v4 step has no ref: parameter. sparse-checkout: ci further limits surface. ✅
#2: No fork-controlled script execution Only run: step is python ci/github_project_sync.py — a path that, by virtue of invariant #1, is base-controlled. ✅
#3: No PR-controlled data interpolated into run: blocks All ${{ ... }} expressions sit inside env: blocks. The run: itself is a literal command. (Anti-injection pattern documented in GitHub's "Security hardening for GitHub Actions" guide.) ✅
#4: Minimal permissions: Workflow-level permissions: contents: read. No write scope on default GITHUB_TOKEN. ✅
#5: App token is project-scoped only actions/create-github-app-token@v3 mints a token that the App installation grants only project read/write. (Repo-level confirmation outside this PR — relies on App installation config.) ⚠️ external-to-repo, but verified at audit time

Also audited ci/github_project_sync.py itself:

  • Inputs read only via os.environ.get()
  • Passed to gh api graphql via positional -f/-F flags (no shell interpolation)
  • GraphQL queries use $variable placeholders, not Python string concatenation
  • Env vars passed in contain only GitHub-controlled metadata (github.event.issue.node_id, github.event.pull_request.node_id, github.event_name, github.event.action), repo vars.*, and the App private key

Hardening added in this PR: a 30-line security-comment block above the pull_request_target: declaration in project_automation.yml encoding all five invariants in-source, plus a second comment marker on the actions/checkout step warning future editors not to add ref:. This converts the unenforced-convention safety into self-documenting tripwires for future PRs touching the file.

Behavior change

Event Before After
Push to master Runs full CI matrix Runs full CI matrix (unchanged)
Internal-branch PR → master Runs full CI matrix Runs full CI matrix (unchanged)
External-fork PR → master Runs full CI matrix (~60+ runner-minutes per push, no maintainer gate) All build / test jobs skip immediately; project board still updates via project_automation.yml pull_request_target
PR open/close/draft event on any PR Updates project board via pull_request_target Updates project board via pull_request_target (unchanged)

Verification

$ grep -rln "pull_request_target" .github/
.github/workflows/build_clone_and_compile.yml   # historical comment, trigger inactive
.github/workflows/project_automation.yml        # active (the one documented exception)

$ bash lint
EXIT_CODE=0

What this PR does NOT do (intentional follow-ups)

  • Does not SHA-pin actions/checkout@v4, actions/setup-python@v5, actions/create-github-app-token@v3 in project_automation.yml — defensive hardening worth doing but separate from the fork-block scope.
  • Does not change the UI setting Settings → Actions → General → Fork pull request workflows from outside collaborators — recommended defense-in-depth (Require approval for all outside collaborators) but a UI action.
  • Does not add a CI lint that fails if anyone adds secrets.* to a pull_request-reachable workflow — recommended in ci: prevent fork PRs from auto-triggering the full CI matrix (cost control — surfaced by #2752) #2757 thread, separate PR.
  • Does not SHA-pin FastLED/fbuild/.github/actions/setup@main (mutable ref on external action) — unrelated supply-chain concern.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores

    • Enforced job-level guard to prevent CI jobs from running for external-fork pull requests across build and test workflows.
    • Updated project automation workflow without changing its triggers or runtime behavior.
  • Documentation

    • Added inline SECURITY guidance and clarifying comments around project-automation workflow usage.

…uest_target (#2757)

Two related hardening changes:

1. **Hard-block fork PRs** on the 6 workflows that trigger on
   `pull_request:` — `build_esp32s3`, `build_teensy41`, `build_uno`,
   `build_wasm`, `example_test_linux`, `unit_test_linux`. Add a job-level
   `if:` guard:

       if: github.event.pull_request == null ||
           github.event.pull_request.head.repo.full_name == github.repository

   The first clause lets `push` / `workflow_dispatch` / `schedule` / etc.
   continue to run (those events have no `pull_request` context). The
   second clause matches only when the PR head repo IS the base repo
   (i.e. branch in FastLED/FastLED, never a fork).

   Behavior change: external-fork PRs now skip the entire build matrix
   silently (the jobs evaluate to `skipped`, not failed). Internal-branch
   PRs and pushes are unaffected.

2. **Ban pull_request_target** entirely. The only active user was
   `project_automation.yml`, which used it to keep a project board in
   sync with PR open/close/draft events. That trigger is removed; the
   `issues:` trigger remains. PR-driven board sync is intentionally
   dropped — the trigger has historically been the highest-risk surface
   in GitHub Actions (it runs in trusted context with secrets even on
   fork PRs) and the user explicitly banned it.

   The `build_clone_and_compile.yml` file already had `pull_request_target`
   disabled via comment — that pre-existing decision is now in line with
   repo policy.

Verification:
- `grep -rln 'pull_request_target' .github/` returns only two files, both
  showing the trigger inside a comment (one historical, one new), zero
  active uses.
- `bash lint` clean.

Filed under issue #2757 (which surfaced the cost-control concern after
external PR #2752 triggered the full CI matrix; user's follow-up
directives during review escalated to a hard block on fork PRs and a
full ban on pull_request_target).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 4, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 46a7a1dc-e5b1-43c0-939c-d6a9b590766d

📥 Commits

Reviewing files that changed from the base of the PR and between c761da7 and 857577f.

📒 Files selected for processing (1)
  • .github/workflows/project_automation.yml

📝 Walkthrough

Walkthrough

Job-level if: guards were added to multiple build and test workflows to skip execution for external-fork pull requests; the project automation workflow received SECURITY documentation comments while retaining its pull_request_target trigger and existing permissions.

Changes

External Fork PR Cost Control

Layer / File(s) Summary
Build workflow fork guards
.github/workflows/build_esp32s3.yml, .github/workflows/build_teensy41.yml, .github/workflows/build_uno.yml, .github/workflows/build_wasm.yml
Each jobs.build now includes a job-level if: condition that permits runs only when github.event.pull_request is null (non-PR events) or when the PR head repo matches the current repository, preventing external-fork PRs from running the build jobs.
Test workflow fork guards
.github/workflows/example_test_linux.yml, .github/workflows/unit_test_linux.yml
jobs.test / jobs.test add job-level if: guards to block external-fork pull requests while allowing same-repo PRs and non-PR events; a comment documents the no-exceptions policy.
Project automation SECURITY docs
.github/workflows/project_automation.yml
Large inline SECURITY comment block added (explaining why pull_request_target remains and enumerating invariants) plus a brief checkout-area SECURITY note; no job steps, permissions, or execution logic were changed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • FastLED/FastLED#2394: Modifies the same set of workflow files to constrain pull_request behavior with a different allowlist/remove-trigger approach.

Poem

🐰 I patched the CI gate with a careful paw,

Forked PRs now wait outside in awe,
Same-repo folks still hop right through,
Runners rest — the carrots saved anew,
Hooray for tidy workflows — hoom! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: hard-blocking external-fork PRs across workflows and banning pull_request_target except for an audited project_automation.yml.
Linked Issues check ✅ Passed The PR implements hard-blocking of external-fork PRs (Option C approach from #2757) across six pull_request-triggered workflows, and documents the pull_request_target usage in project_automation.yml with safety invariants as mentioned in the objectives.
Out of Scope Changes check ✅ Passed All changes directly address issue #2757: six workflows gain external-fork PR guards, and project_automation.yml receives security documentation around its audited pull_request_target usage. No unrelated changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ci/block-fork-pr-workflows-2757

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…ment safety invariants

Reverses the part of the previous commit that removed pull_request_target
from project_automation.yml. The trigger is needed for PR-side project
board sync (open / close / draft state changes) — a vanilla pull_request
trigger has no access to the App private key required to write to the
project, so pull_request_target is the only viable option.

The pull_request_target ban from the previous commit still applies to
the rest of the repo — project_automation.yml is the documented
exception.

This commit also adds a 30-line security comment block above the
trigger declaration encoding the FIVE invariants that make this
specific pull_request_target usage safe:

  1. NEVER add `ref:` to actions/checkout (must stay on base ref)
  2. NEVER run a fork-controlled script (only `python ci/github_project_sync.py`)
  3. NEVER interpolate PR-controlled data into `run:` blocks (use `env:` only)
  4. Keep `permissions:` minimal (currently `contents: read`)
  5. App token must remain project-scoped only

A second comment marker is placed directly on the actions/checkout step
warning future editors not to add `ref:`.

Audit performed 2026-06-04 under #2757. All five invariants verified
holding. The script `ci/github_project_sync.py` was also audited:
- inputs read only via `os.environ.get()`
- passed to `gh api` via `-f`/`-F` positional flags (no shell)
- GraphQL queries use `$variable` placeholders (no string concat)
- env vars contain only GitHub-controlled metadata + repo vars + App token

Net effect: identical functional behavior to pre-#2759 state on
project_automation.yml; the explicit invariant comments are
maintenance-grade documentation to prevent future regressions.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees zackees changed the title ci: hard-block external-fork PRs from all workflow runs; ban pull_request_target (closes #2757) ci: hard-block external-fork PRs; ban pull_request_target except audited project_automation.yml (closes #2757) Jun 4, 2026
@zackees
zackees merged commit 54e4698 into master Jun 4, 2026
5 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 4, 2026
@zackees
zackees deleted the ci/block-fork-pr-workflows-2757 branch August 21, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

ci: prevent fork PRs from auto-triggering the full CI matrix (cost control — surfaced by #2752)

1 participant