Skip to content

Commit 7adc4ec

Browse files
luisleo526claude
andcommitted
ci(security): gate corpus-parity and docs on canon authz, run docs on the fleet
corpus-parity.yml triggers on pull_request (corpus and parity-tooling paths) and had no authz job. Its old conditional runs-on was the only fork and pull_request_target guard; moving both jobs to a literal ["self-hosted","pf-gcp-pr"] left a fork pull request running untrusted code on a fleet that has sudo and docker. docs.yml accepted pull_request too, with an ungated job still on GitHub-hosted ubuntu-latest. Both workflows now start with the canonical authz job, byte-identical to ci.yml's (the same header comment, the space inside the array, the same single step whose sha256 scripts/ci_preflight.py pins), and every other job needs it: corpus-parity and corpus-parity-subset, and docs build. Docs build moves from ubuntu-latest to ["self-hosted","pf-gcp-pr"]; its Cloudflare deployment step still skips pull_request. Outsider pull requests run no CI and get no hosted fallback; dependabot counts as ours through the authz allowlist (CI-DEPBOT A). scripts/ci_preflight.py gains gated_workflow_findings(): first job authz, verbatim canon header and step hash, no authz overrides (needs/if/env/uses/ strategy/continue-on-error), needs authz on every other job, readable events without pull_request_target, and a literal fleet array on every runs-on. It pins corpus-parity.yml and docs.yml. They are deliberately not routed through the full authz contract: corpus-parity needs persisted checkout credentials for its private HTTPS submodule and git lfs pull, and docs deploys with Cloudflare secrets; forcing persist-credentials: false or banning secrets there would break them. docs.yml moves out of HOSTED_JOB_RUNNERS, which is now empty. Refusal tests added for each mutation (authz job dropped, needs removed from either corpus job or from docs build, one-character change to the authz script, a hosted fallback expression, docs build back on ubuntu-latest, pull_request_target, authz reordered or given an extra step/override), each asserting the intended finding and the whole-workflow contract; every existing assertion is kept. Not executed on this Mac: the PR's preflight job on pf-gcp-pr is the proof. Sweep of every engine workflow triggered by pull_request, pull_request_target or workflow_run: ci.yml fully gated; corpus-parity.yml and docs.yml were the ungated ones and are fixed here; native-live.yml has no direct PR trigger; promote-baseline.yml's promote is pull_request_target, ungated, and unchanged in this commit (it runs main's own copy of the file, checks out and runs no PR code, and its WIF condition admits only refs/heads/main) — reported to CORE-TOP rather than widened into a release workflow. Lane core-org-472sec (ORG-CX); diff read by the supervisor. Tests not run on the Mac; CI is the proof. Co-Authored-By: Claude Code <[email protected]>
1 parent b816635 commit 7adc4ec

5 files changed

Lines changed: 359 additions & 58 deletions

File tree

‎.github/workflows/corpus-parity.yml‎

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,76 @@ env:
8080
# pin is almost entirely cache hits.
8181
CCACHE_MAXSIZE: 2G
8282

83-
# Both jobs use the live ci-spot 16-vCPU class with the hosted fallback for
84-
# forks and untrusted events. The build uses every core of the runner.
83+
# Both parity jobs follow canon authz on pf-gcp-pr, with no hosted fallback.
84+
# The build uses every core of the runner.
8585
# scripts/ci_preflight.py pins runners and limits.
8686
jobs:
87+
authz:
88+
name: authz
89+
# GCP fleet (owner #1050): non-release jobs on pf-gcp-pr; release-class jobs only on pf-gcp-main.
90+
runs-on: ["self-hosted", "pf-gcp-pr"]
91+
permissions: {}
92+
# No timeout-minutes: the owner's no-time-limits rule (check-no-time-limits refuses new ones).
93+
steps:
94+
- name: Only our own pull requests and our own events run CI
95+
env:
96+
EVENT: ${{ github.event_name }}
97+
REPO: ${{ github.repository }}
98+
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
99+
HEAD_IS_FORK: ${{ github.event.pull_request.head.repo.fork }}
100+
ASSOCIATION: ${{ github.event.pull_request.author_association }}
101+
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
102+
WR_HEAD_REPO: ${{ github.event.workflow_run.head_repository.full_name }}
103+
WR_ACTOR: ${{ github.event.workflow_run.triggering_actor.login }}
104+
GH_TOKEN: ${{ github.token }} # read-only use: one permission lookup for workflow_run
105+
# Bot logins whose same-repository pull requests count as ours: dependabot[bot] (CI-DEPBOT A)
106+
# and the org's own GitHub App bot logins by name (space-separated), nothing else.
107+
ALLOWED_BOTS: "dependabot[bot] pineforge-app[bot]"
108+
run: |
109+
set -eu
110+
fail() { echo "::error title=authz::$1"; echo "authz: REFUSED: $1" >> "$GITHUB_STEP_SUMMARY"; exit 1; }
111+
case "$EVENT" in
112+
push|workflow_dispatch|schedule|merge_group|release|workflow_call|repository_dispatch)
113+
# Only someone with write access to this repository (or our App's token) can cause these
114+
# events; none of them runs pull-request code.
115+
;;
116+
workflow_run)
117+
# LB-437: bind identity to the triggering run and its re-runner.
118+
# These two App bots are fixed canon policy; ALLOWED_BOTS is PR-only.
119+
[ -n "${WR_HEAD_REPO:-}" ] || fail "workflow_run head repository is missing"
120+
[ -n "${WR_ACTOR:-}" ] || fail "workflow_run triggering actor is missing"
121+
[ "$WR_HEAD_REPO" = "$REPO" ] || fail "workflow_run head repository does not match this repository"
122+
case "$WR_ACTOR" in
123+
"pineforge-app[bot]"|"pineforge-ci-dispatcher[bot]") ;;
124+
*"[bot]") fail "workflow_run bot is not on the canon allowlist" ;;
125+
*)
126+
perm=$(gh api "repos/$REPO/collaborators/$WR_ACTOR/permission" --jq .permission 2>/dev/null) || fail "workflow_run permission lookup failed"
127+
case "$perm" in admin|maintain|write) ;; *) fail "workflow_run triggering actor does not have write permission" ;; esac ;;
128+
esac ;;
129+
pull_request)
130+
[ "$HEAD_REPO" = "$REPO" ] || fail "pull request from another repository (${HEAD_REPO:-unknown})"
131+
[ "$HEAD_IS_FORK" = "false" ] || fail "pull request from a fork"
132+
case "$ASSOCIATION" in
133+
OWNER|MEMBER|COLLABORATOR) ;;
134+
*)
135+
case " $ALLOWED_BOTS " in
136+
*" $PR_AUTHOR "*) ;;
137+
*)
138+
# A member whose org membership is private shows as CONTRIBUTOR: ask GitHub for the
139+
# author's permission on this repository; anything but admin/maintain/write (or a
140+
# failed call) refuses.
141+
perm=$(gh api "repos/$REPO/collaborators/$PR_AUTHOR/permission" --jq .permission 2>/dev/null || echo none)
142+
case "$perm" in admin|maintain|write) ;; *) fail "author ${PR_AUTHOR:-unknown} (${ASSOCIATION:-NONE}) has permission '$perm', not write, and is not an allowlisted bot" ;; esac ;;
143+
esac ;;
144+
esac ;;
145+
*) fail "event $EVENT does not run CI (pull_request_target and other events are not allowed)" ;;
146+
esac
147+
echo "authz: allowed ($EVENT${PR_AUTHOR:+ by $PR_AUTHOR})" >> "$GITHUB_STEP_SUMMARY"
148+
87149
# The whole population. Nightly, on demand, and on a pull request that
88150
# touches the pin or the parity tooling. Never reached by `mode: subset`.
89151
corpus-parity:
152+
needs: [authz]
90153
if: inputs.mode != 'subset'
91154
runs-on: ["self-hosted","pf-gcp-pr"]
92155
env:
@@ -165,6 +228,7 @@ jobs:
165228
# The advisory PR subset: the 54 probes scripts/corpus_parity_subset.txt
166229
# names, judged against the same pinned sha256 rows. Reached through CI.
167230
corpus-parity-subset:
231+
needs: [authz]
168232
if: inputs.mode == 'subset'
169233
runs-on: ["self-hosted","pf-gcp-pr"]
170234
env:

‎.github/workflows/docs.yml‎

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,71 @@ concurrency:
2626
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
2727

2828
jobs:
29+
authz:
30+
name: authz
31+
# GCP fleet (owner #1050): non-release jobs on pf-gcp-pr; release-class jobs only on pf-gcp-main.
32+
runs-on: ["self-hosted", "pf-gcp-pr"]
33+
permissions: {}
34+
# No timeout-minutes: the owner's no-time-limits rule (check-no-time-limits refuses new ones).
35+
steps:
36+
- name: Only our own pull requests and our own events run CI
37+
env:
38+
EVENT: ${{ github.event_name }}
39+
REPO: ${{ github.repository }}
40+
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
41+
HEAD_IS_FORK: ${{ github.event.pull_request.head.repo.fork }}
42+
ASSOCIATION: ${{ github.event.pull_request.author_association }}
43+
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
44+
WR_HEAD_REPO: ${{ github.event.workflow_run.head_repository.full_name }}
45+
WR_ACTOR: ${{ github.event.workflow_run.triggering_actor.login }}
46+
GH_TOKEN: ${{ github.token }} # read-only use: one permission lookup for workflow_run
47+
# Bot logins whose same-repository pull requests count as ours: dependabot[bot] (CI-DEPBOT A)
48+
# and the org's own GitHub App bot logins by name (space-separated), nothing else.
49+
ALLOWED_BOTS: "dependabot[bot] pineforge-app[bot]"
50+
run: |
51+
set -eu
52+
fail() { echo "::error title=authz::$1"; echo "authz: REFUSED: $1" >> "$GITHUB_STEP_SUMMARY"; exit 1; }
53+
case "$EVENT" in
54+
push|workflow_dispatch|schedule|merge_group|release|workflow_call|repository_dispatch)
55+
# Only someone with write access to this repository (or our App's token) can cause these
56+
# events; none of them runs pull-request code.
57+
;;
58+
workflow_run)
59+
# LB-437: bind identity to the triggering run and its re-runner.
60+
# These two App bots are fixed canon policy; ALLOWED_BOTS is PR-only.
61+
[ -n "${WR_HEAD_REPO:-}" ] || fail "workflow_run head repository is missing"
62+
[ -n "${WR_ACTOR:-}" ] || fail "workflow_run triggering actor is missing"
63+
[ "$WR_HEAD_REPO" = "$REPO" ] || fail "workflow_run head repository does not match this repository"
64+
case "$WR_ACTOR" in
65+
"pineforge-app[bot]"|"pineforge-ci-dispatcher[bot]") ;;
66+
*"[bot]") fail "workflow_run bot is not on the canon allowlist" ;;
67+
*)
68+
perm=$(gh api "repos/$REPO/collaborators/$WR_ACTOR/permission" --jq .permission 2>/dev/null) || fail "workflow_run permission lookup failed"
69+
case "$perm" in admin|maintain|write) ;; *) fail "workflow_run triggering actor does not have write permission" ;; esac ;;
70+
esac ;;
71+
pull_request)
72+
[ "$HEAD_REPO" = "$REPO" ] || fail "pull request from another repository (${HEAD_REPO:-unknown})"
73+
[ "$HEAD_IS_FORK" = "false" ] || fail "pull request from a fork"
74+
case "$ASSOCIATION" in
75+
OWNER|MEMBER|COLLABORATOR) ;;
76+
*)
77+
case " $ALLOWED_BOTS " in
78+
*" $PR_AUTHOR "*) ;;
79+
*)
80+
# A member whose org membership is private shows as CONTRIBUTOR: ask GitHub for the
81+
# author's permission on this repository; anything but admin/maintain/write (or a
82+
# failed call) refuses.
83+
perm=$(gh api "repos/$REPO/collaborators/$PR_AUTHOR/permission" --jq .permission 2>/dev/null || echo none)
84+
case "$perm" in admin|maintain|write) ;; *) fail "author ${PR_AUTHOR:-unknown} (${ASSOCIATION:-NONE}) has permission '$perm', not write, and is not an allowlisted bot" ;; esac ;;
85+
esac ;;
86+
esac ;;
87+
*) fail "event $EVENT does not run CI (pull_request_target and other events are not allowed)" ;;
88+
esac
89+
echo "authz: allowed ($EVENT${PR_AUTHOR:+ by $PR_AUTHOR})" >> "$GITHUB_STEP_SUMMARY"
90+
2991
build:
30-
runs-on: ubuntu-latest
92+
needs: [authz]
93+
runs-on: ["self-hosted", "pf-gcp-pr"]
3194
env:
3295
CF_PROJECT: ${{ vars.CF_PAGES_PROJECT || 'pineforge-docs' }}
3396
DEPLOY_BRANCH: ${{ github.ref_name }}

‎docs/ci.md‎

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,9 +1070,13 @@ closed `pull_request_target` and manual dispatch triggers; only its
10701070
`runs-on` line changes in the workflow.
10711071

10721072
Other jobs in workflows triggered by `pull_request` or `pull_request_target`
1073-
do not move to the release class. Docs `build` stays on `ubuntu-latest` because
1074-
`docs.yml` accepts `pull_request`, even though its Cloudflare deployment step
1075-
skips that event. That workflow is left intact.
1073+
do not move to the release class. Docs `build` and both `corpus-parity.yml`
1074+
jobs run on `pf-gcp-pr` behind the canonical `authz` job: `docs.yml` and
1075+
`corpus-parity.yml` both accept `pull_request`, so a fork pull request must be
1076+
refused before any checkout, exactly as `ci.yml` and `native-live.yml` refuse
1077+
it. Outsider pull requests run no CI at all; there is no hosted fallback left
1078+
on either workflow. The docs Cloudflare deployment step still skips
1079+
`pull_request` events.
10761080

10771081
Both aggregates use `if: always()` and first refuse unless authz succeeded,
10781082
before any checkout or repository code. The native aggregate then requires
@@ -1111,8 +1115,9 @@ steps. Under owner #827 (2026-10-20), no job or step may declare
11111115
`timeout-minutes`, authz included. GitHub's own 6 h platform maximum is the
11121116
only bound; no step, stage or row deadline is added.
11131117

1114-
`corpus-parity.yml` now pins both jobs to the plain `pf-gcp-pr` literal, while
1115-
documentation deployment retains its existing hosted route and separate pin.
1118+
`corpus-parity.yml` pins both jobs to the plain `pf-gcp-pr` literal behind
1119+
canon authz, and documentation deployment moved from its former hosted route
1120+
to the same gated `pf-gcp-pr` job (PR #472 security fix, 2026-10-21).
11161121
Baseline promotion and release keep #461's separate release pins, now on
11171122
`pf-gcp-main`; their trigger and promotion checks remain binding.
11181123
The literal corpus runner pin refuses the former conditional expression and
@@ -1139,9 +1144,9 @@ Owner ruling of 2026-10-20, CI-HOSTED = B: all CI runs on our own machines,
11391144
credentialed jobs included, subject to the pinned hosted exceptions below.
11401145
Non-release jobs run on `pf-gcp-pr`; the named release and promotion jobs
11411146
run on the separate `pf-gcp-main` class (protected refs, one job per VM),
1142-
never on the shared non-release fleet. Hosted macOS jobs, docs `build` on
1143-
`ubuntu-latest` and release Linux ARM on `ubuntu-22.04-arm` retain their exact
1144-
GitHub runner pins. The earlier CR-171 hosted exception is VOID.
1147+
never on the shared non-release fleet. Hosted macOS jobs and release Linux ARM
1148+
on `ubuntu-22.04-arm` retain their exact GitHub runner pins. The earlier
1149+
CR-171 hosted exception is VOID.
11451150

11461151
Owner ruling of 2026-10-20, REL-HOSTED = B: the release cut and Linux x64
11471152
artifact build run on `pf-gcp-main`; the existing ARM/macOS matrix legs retain
@@ -1151,13 +1156,17 @@ As of 2026-10-21, #461 has merged as main `03b2406dd`: the old hosted pins
11511156
for the engine's release and promote jobs are gone. `RELEASE_JOB_RUNNERS`
11521157
and `runner_findings` in `scripts/ci_preflight.py` pin those jobs to
11531158
`pf-gcp-main`, with the release `prebuilt` job selecting its pinned matrix.
1154-
`HOSTED_JOB_RUNNERS` in `scripts/ci_preflight.py` lists only docs `build` on
1155-
`ubuntu-latest`. The existing guard for unlisted credential-bearing jobs
1156-
still requires standard hosted routing (`runner_findings` in `scripts/ci_preflight.py`),
1157-
and the release matrix retains its hosted ARM/macOS legs
1158-
(`RELEASE_STRATEGY` in `scripts/ci_preflight.py`). The remaining hosted Linux
1159-
routes are the pinned docs `ubuntu-latest` and release ARM
1160-
`ubuntu-22.04-arm` exceptions.
1159+
`HOSTED_JOB_RUNNERS` in `scripts/ci_preflight.py` is now empty: docs `build`
1160+
moved to `["self-hosted","pf-gcp-pr"]` behind canon authz (2026-10-21, the
1161+
PR #472 security fix), and `gated_workflow_findings` pins it and both
1162+
`corpus-parity.yml` jobs — first-job authz, the byte-canonical header and step
1163+
hash, `needs: [authz]` on every other job, readable events without
1164+
`pull_request_target`, and a literal fleet array on every `runs-on`. The
1165+
existing guard for unlisted credential-bearing jobs still requires standard
1166+
hosted routing (`runner_findings` in `scripts/ci_preflight.py`), and the
1167+
release matrix retains its hosted ARM/macOS legs (`RELEASE_STRATEGY` in
1168+
`scripts/ci_preflight.py`). The only remaining hosted Linux route is release
1169+
ARM `ubuntu-22.04-arm`.
11611170

11621171
The `release.yml` pin requires readable `workflow_dispatch`-only triggers,
11631172
refusing both PR events. The named promotion exception requires its existing

0 commit comments

Comments
 (0)