Skip to content

Commit 717c75d

Browse files
luisleo526claude
andauthored
ci: promote-baseline refuses untrusted heads and actors (SEC846) (#482)
* SEC846: require head and actor authorization before baseline promotion PARKED 10-20 17:35 (owner #859): CI security work resumes 10-23 10:00; committed as-is, no PR. Review read 12 returned CHANGES NEEDED (P2 guard text differs across engine, codegen and the template; P3 handoff quotes omitted, template edits beyond scope) — open, not fixed. Put a credential-free, hosted promote-guard before promote with empty job permissions. On every pull_request_target close, check this repository's non-fork head and the canonical author association/bot/permission rule before the unmerged exit. Copy the canon's author fallback and comment verbatim: private-member CONTRIBUTOR authors pass with admin/maintain/write permission from GitHub; failed or empty author lookups refuse. Fork closes refuse even when unmerged. Merged own PRs also require a nonempty merger and an allowlisted bot merger or admin/maintain/write permission from GitHub; failed or empty lookups refuse. Authorised own unmerged closes skip promotion through the existing job condition. Manual dispatches remain allowed; every other event refuses. Pin the complete guard independently in ci_preflight and keep every existing promotion pin. Add mutations of the real workflow for a no-op fail, missing head/fork bindings and checks, bypassed author checks, a widened bot list, missing/failed author and merger lookups, missing needs, status-function bypasses, guard checkout/secrets/OIDC, permissions and runner drift. Add whole-script no-op and early-unmerged-exit mutations. Decision tables execute the actual workflow shell with bash and an executable gh stub first on PATH; the stub answers by username with separate author and merger permission/exit fixtures. The table requires a merged CONTRIBUTOR-with-write PR to pass, read/none/empty or failed author lookups to refuse, and a writer author merged by a reader to refuse. Deleting the author lookup changes the writer-author case from 0 to 1; making a failed author lookup pass changes its refusal from 1 to 0. Disabled refusal mutations must differ from the original execution. Document that merged == true is already required for PR promotion but the trigger and guard have no main-base condition; leave the base-ref behavior unchanged. Record the WIF source conditions and promotion-account blast radius in REPORT-SEC846.md: WIF admits base-repo pull_request_target runs for fork PRs, so promote-guard supplies that distinction. Validation: NOT RUN for every changed file; this is an edit-only lane. The supervisor must execute verification before any passing claim. No staging, commit or push was performed. Documentation sentences added or rewritten, quoted verbatim (each six or more words): README.md: ```text `promote-guard` runs before promotion credentials are available and rejects foreign or fork heads and disallowed authors on every PR close, including unmerged closes. Authors outside the association and bot allowlists must have `admin`, `maintain` or `write` permission from GitHub; failed or empty author lookups refuse promotion. Merged PRs also require an allowlisted bot merger or a merger with write access; manual dispatches are allowed. See [CI documentation](docs/ci.md) for author associations and permissions, merger permissions and unmerged-close behavior. ``` docs/ci.md, baseline eligibility sentences: ```text It requires both statuses to be successful on the verified PR head and a merge commit on the PR's base branch that carries exactly that head's tree (PRs are squash-merged, so the head itself never lands on the base branch). It hands the campaign tool the merge commit, the PR head and that tree, and the tool promotes the pair the merge gate's parity verdict measured for the tree; after the guard succeeds, ineligible baseline cases exit green without promoting. ``` docs/ci.md, promotion authorization: ```text `promote-guard` must pass before the credential job runs. Every `pull_request_target` close requires a non-fork head in this repository and an author whose association is `OWNER`, `MEMBER` or `COLLABORATOR`, whose login is an allowlisted bot, or whose GitHub permission is `admin`, `maintain` or `write`. The permission fallback admits private organization members reported as `CONTRIBUTOR`; a failed or empty author lookup refuses promotion. Only after those checks can an unmerged close pass without a merger lookup and skip `promote`. For a merged PR, the merger login must be nonempty and must be an allowlisted bot or have `admin`, `maintain` or `write` permission; a failed or empty lookup refuses promotion. Only `dependabot[bot]` and `pineforge-app[bot]` are allowlisted bots. Manual `workflow_dispatch` events pass the guard because dispatch requires write access. Every other event fails the guard before credentials are available. The trigger has no `branches:` filter and the guard does not require a `main` base ref; the existing tree check reads the PR's base ref, defaulting to `main` for dispatch. ``` docs/ci.md, hosted routing: ```text Promotion and its `promote-guard` stay hosted for both target and dispatch triggers. ``` docs/ci.md, preflight pins: ```text The same stage pins `promote-guard` independently, its empty permissions, its payload bindings and refusal script, and the merged-or-dispatch credential job's dependency on it. Decision tests execute the guard script extracted from the real workflow with bash and an executable `gh` stub first on PATH that returns separate author and merger permissions by username. Mutation tests alter the real promotion workflow to replace the script with `exit 0`, move the unmerged exit before authorization, remove author or merger lookups and other checks, disable `fail`, bypass failed author or merger lookups, add guard credentials or a checkout, or disconnect the credential job. ``` * SEC846 handoff: a final integration record supersedes the checkpoint passages (read 13 P3 F1, F2) REPORT-SEC846.md and COMMIT-MSG-SEC846.md carry a closing record with the actual parent pairs, the union resolutions, the shared promote-guard md5, and the final template scope (proxy wait identical to the template's main, not synchronised with codegen). Earlier "pending merge" and "proxy synchronisation" passages are marked as checkpoint accounts. Documentation only; nothing was run. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * SEC846: remove the lane handoff files from the repository REPORT-SEC846.md and COMMIT-MSG-SEC846.md are lane records, not product files. They stay in the lane's own reports directory; the branch carries only the SEC846 product change. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]>
1 parent e799ac8 commit 717c75d

5 files changed

Lines changed: 621 additions & 9 deletions

File tree

‎.github/workflows/promote-baseline.yml‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,66 @@ permissions:
100100
id-token: write
101101

102102
jobs:
103+
promote-guard:
104+
name: promote-guard
105+
runs-on: ubuntu-latest
106+
permissions: {}
107+
steps:
108+
- name: Only our own merged pull requests and dispatches promote the baseline
109+
env:
110+
EVENT: ${{ github.event_name }}
111+
REPO: ${{ github.repository }}
112+
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
113+
HEAD_IS_FORK: ${{ github.event.pull_request.head.repo.fork }}
114+
ASSOCIATION: ${{ github.event.pull_request.author_association }}
115+
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
116+
MERGED: ${{ github.event.pull_request.merged }}
117+
MERGED_BY: ${{ github.event.pull_request.merged_by.login }}
118+
GH_TOKEN: ${{ github.token }} # read-only use: permission lookups for the PR author and merger
119+
# Bot logins whose same-repository pull requests count as ours: dependabot[bot] (CI-DEPBOT A)
120+
# and the org's own GitHub App bot logins by name (space-separated), nothing else.
121+
ALLOWED_BOTS: "dependabot[bot] pineforge-app[bot]"
122+
run: |
123+
set -eu
124+
fail() { echo "::error title=authz::$1"; echo "authz: REFUSED: $1" >> "$GITHUB_STEP_SUMMARY"; exit 1; }
125+
case "$EVENT" in
126+
workflow_dispatch)
127+
# Only someone with write access to this repository (or our App's token) can cause these
128+
# events; none of them runs pull-request code.
129+
;;
130+
pull_request_target)
131+
[ "$HEAD_REPO" = "$REPO" ] || fail "pull request from another repository (${HEAD_REPO:-unknown})"
132+
[ "$HEAD_IS_FORK" = "false" ] || fail "pull request from a fork"
133+
case "$ASSOCIATION" in
134+
OWNER|MEMBER|COLLABORATOR) ;;
135+
*)
136+
case " $ALLOWED_BOTS " in
137+
*" $PR_AUTHOR "*) ;;
138+
*)
139+
# A member whose org membership is private shows as CONTRIBUTOR: ask GitHub for the
140+
# author's permission on this repository; anything but admin/maintain/write (or a
141+
# failed call) refuses.
142+
perm=$(gh api "repos/$REPO/collaborators/$PR_AUTHOR/permission" --jq .permission 2>/dev/null || echo none)
143+
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 ;;
144+
esac ;;
145+
esac
146+
# Only our own authorised unmerged closes pass without promotion.
147+
[ "$MERGED" = "true" ] || { echo "promote-guard: unmerged pull request; promotion is skipped" >> "$GITHUB_STEP_SUMMARY"; exit 0; }
148+
[ -n "$MERGED_BY" ] || fail "pull_request_target merger is empty"
149+
case " $ALLOWED_BOTS " in
150+
*" $MERGED_BY "*) ;;
151+
*)
152+
# No author_association exists for the merger: ask GitHub for the merger's permission on
153+
# this repository; anything but admin/maintain/write (or a failed call) refuses.
154+
perm=$(gh api "repos/$REPO/collaborators/$MERGED_BY/permission" --jq .permission 2>/dev/null || echo none)
155+
case "$perm" in admin|maintain|write) ;; *) fail "pull_request_target merger ${MERGED_BY:-unknown} has permission '$perm', not write" ;; esac ;;
156+
esac ;;
157+
*) fail "event $EVENT does not run baseline promotion (only pull_request_target and workflow_dispatch are allowed)" ;;
158+
esac
159+
echo "authz: allowed ($EVENT${PR_AUTHOR:+ by $PR_AUTHOR})" >> "$GITHUB_STEP_SUMMARY"
160+
103161
promote:
162+
needs: [promote-guard]
104163
if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true }}
105164
runs-on: ["self-hosted","pf-gcp-main"]
106165
steps:

‎README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ are described in the README of the private fixture set `coof_cascade_identity`.
358358

359359
A change is judged by what it moves: the same population is graded before and after it, and two rules must both hold. On the hard surface (ETHUSDT.P at 15 minutes) **no probe may regress**: none may lose a grade, stop reporting a metric or become an engine error. Every other market and timeframe is pooled and scored over two bands, excellent and excellent+strong: +1 each time a probe enters a band, −1 each time one leaves it. A score above 0 passes, as long as no probe that leaves a band falls more than one grade. A score of exactly 0 passes only if no probe lost a grade or became an engine error and no hard-surface probe got worse on a graded metric; it is flagged *no-improve-no-regression*, or *improved* when a probe got better where the bands cannot see it (a grade rising below them or on the hard surface, or an engine error fixed). Any other 0 fails, and so does a negative score. The merge ruleset requires the maintainers' `pineforge/verify` and `pineforge/parity` commit statuses on the exact PR head; GitHub Actions CI is advisory. Baseline promotion also requires a recorded PASS and an exact-head merge.
360360

361+
`promote-guard` runs before promotion credentials are available and rejects foreign or fork heads and disallowed authors on every PR close, including unmerged closes.
362+
Authors outside the association and bot allowlists must have `admin`, `maintain` or `write` permission from GitHub; failed or empty author lookups refuse promotion.
363+
Merged PRs also require an allowlisted bot merger or a merger with write access; manual dispatches are allowed.
364+
See [CI documentation](docs/ci.md) for author associations and permissions, merger permissions and unmerged-close behavior.
365+
361366
### What the closed test taught the engine
362367

363368
Every gap was closed by pinning the rule TradingView actually follows — never by loosening the grader. Each rule was isolated with sensor strategies exported from TradingView (capital sweeps, literal replays, per-bar state encoded into order comments) and landed with a replay test on the recorded bars. Among them: the broker carries money at **ten significant digits** (equity rounding, the whole-order drop band, the one-contract margin call, the raw lot floor on every lot-stepped symbol); a trailing stop restarts from the issuing bar's *close* when `trail_points` changes and never folds that bar's extreme; a zero-offset trail rides the raw running best and its arming open fills at the nearest-tick print; a reversal rejected at placement preserves standing exits and a separately queued `strategy.close`, while the distinct fill-time rejection rules govern stop, limit, and trailing legs; sparse `ta.atr`/`ta.tr` read the chart's previous close on every execution; a resting stop or limit level a hair off the tick grid snaps onto it; early-close sessions complete their higher-timeframe bucket; and account-currency conversion is left out of the comparison entirely, because TradingView's FX series is a moving target no fixed table reproduces.

‎docs/ci.md‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -850,11 +850,22 @@ requires these two commit statuses. GitHub Actions jobs, including `build`,
850850
(`promote-baseline.yml`, installed from the maintainers' private campaign
851851
tooling) runs `main`'s own copy on the closed PR
852852
(`pull_request_target`) and runs no PR code. It requires both statuses to be
853-
successful on the verified PR head and a merge commit on `main` that carries
853+
successful on the verified PR head and a merge commit on the PR's base branch that carries
854854
exactly that head's tree (PRs are squash-merged, so the head itself never lands
855-
on `main`). It hands the campaign tool the merge commit, the PR head and that
855+
on the base branch). It hands the campaign tool the merge commit, the PR head and that
856856
tree, and the tool promotes the pair the merge gate's parity verdict measured
857-
for the tree; every other case exits green without promoting.
857+
for the tree; after the guard succeeds, ineligible baseline cases exit green
858+
without promoting.
859+
860+
`promote-guard` must pass before the credential job runs.
861+
Every `pull_request_target` close requires a non-fork head in this repository and an author whose association is `OWNER`, `MEMBER` or `COLLABORATOR`, whose login is an allowlisted bot, or whose GitHub permission is `admin`, `maintain` or `write`.
862+
The permission fallback admits private organization members reported as `CONTRIBUTOR`; a failed or empty author lookup refuses promotion.
863+
Only after those checks can an unmerged close pass without a merger lookup and skip `promote`.
864+
For a merged PR, the merger login must be nonempty and must be an allowlisted bot or have `admin`, `maintain` or `write` permission; a failed or empty lookup refuses promotion.
865+
Only `dependabot[bot]` and `pineforge-app[bot]` are allowlisted bots.
866+
Manual `workflow_dispatch` events pass the guard because dispatch requires write access.
867+
Every other event fails the guard before credentials are available.
868+
The trigger has no `branches:` filter and the guard does not require a `main` base ref; the existing tree check reads the PR's base ref, defaulting to `main` for dispatch.
858869

859870
The full corpus sweep remains a separate acceptance step. The nightly and
860871
manual corpus workflow, and the maintainers' full parity verification, keep
@@ -1141,6 +1152,13 @@ No job or step declares `timeout-minutes`, and no proof continues on error.
11411152
The checker retains the bans on paid larger-runner labels and
11421153
`larger_runner` keys. GitHub's platform maximum remains the only time bound.
11431154

1155+
The credential-free `promote-guard` stays hosted on `ubuntu-latest`; the credential job keeps main's isolated release runner.
1156+
The same stage pins the complete shared `promote-guard` block byte for byte, including comments, empty permissions, payload bindings, refusal script and separator, and the merged-or-dispatch credential job's dependency on it.
1157+
Decision tests execute the guard script extracted from the real workflow with bash and an executable `gh` stub first on PATH that returns separate author and merger permissions by username.
1158+
Mutation tests alter the real promotion workflow to replace the script with `exit 0`, move the unmerged exit before authorization, remove author or merger lookups and other checks, disable `fail`, bypass failed author or merger lookups, add guard credentials or a checkout, or disconnect the credential job.
1159+
The release pool is restricted to the existing pinned release and promotion jobs; reusable call edges cannot admit PR events to them.
1160+
Retired `pf-ci-release` labels remain refused, and an unpinned `flat-peak.yml` receives no release-pool exception.
1161+
11441162
More cores do not shorten every job. The `test_ci_verify` CTest row
11451163
(`scripts/test_ci_verify.py`) is one Python process, and in the main run at
11461164
0d76a099 it was the whole CTest wall time of every full-set leg but

0 commit comments

Comments
 (0)