Skip to content

Commit da6ab60

Browse files
luisleo526claude
andcommitted
ci(release): the ruleset probe refuses any dispatch ref other than main before it mints the App token; the runner refusal no longer calls the post fleet isolated (CR-245 F1)
Fresh sol read of the pf-gcp-post move (065826e): moving the probe job to the unrestricted pf-gcp-post group removed the only thing that kept it on main, the restricted pf-gcp-main group's workflow and ref allow-list. A workflow_dispatch with ref=refs/heads/<topic> would run that branch's copy of the workflow, pass authz (which accepts any workflow_dispatch), mint the release App token and run the branch's script; neither the workflow nor the probe checked GITHUB_REF. The CI canon requires manual dispatch to satisfy the same ref restriction and to refuse an unsupported ref before checkout or repository-code execution. The probe job now starts with a step that has no secrets and no token: [ "$REF" = refs/heads/main ] || fail, modelled on promote-baseline.yml's own ref refusal, before the App-token mint and before checkout. The whole-file template and release_rulesets_probe_workflow_findings require that step first and refuse a probe workflow that lacks it, has it after the mint or checkout, in the authz job only, compares another ref, or neutralises its exit (|| true, continue-on-error, if:); 13 mutation rows plus an ordering control and a behavioural dispatch control (a topic ref exits 1 before the mint boundary). The App-token mint step is still byte-identical to release.yml's. docs/ci.md says the dispatch must run from main and the workflow itself refuses any other ref. The guard lives in the workflow file, so it stops mistakes, not a writer who edits the file on their own branch; the lock against that is the environment work (CR-304) that keeps the App secrets away from non-main refs. The per-job runner checker's refusal printed " (isolated release)" for a probe pinned to pf-gcp-post; the post fleet is shared. The suffix is now derived from the pinned label (none for the PR fleet, " (post fleet)" for the post fleet, " (isolated release)" only for the release label) and the pins that expected the old suffix (test_gcp_sites_pin_probe_to_the_dispatch_fleet, test_release_ruleset_probe_refuses_release_and_pr_fleets) expect the new one. Rewrites named for the doc-reverts check: the suffix expression and its test expectations came from 1d5dfd6 and 065826e; the pf-gcp-post routing and allow-list sentences of 065826e and the main-copy dispatch wording of 5ce34fc are kept; the generic probe refusal of 6adae66 is kept verbatim. No prose sentence or comment is deleted. Lane: ci-fu-cr486u (Codex gpt-6.1-sol). Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 302736f commit da6ab60

5 files changed

Lines changed: 149 additions & 10 deletions

File tree

‎.github/workflows/release-ruleset-probe.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ jobs:
7676
needs: [authz]
7777
runs-on: ["self-hosted","pf-gcp-post"]
7878
steps:
79+
- name: Refuse a dispatch ref other than main
80+
env:
81+
REF: ${{ github.ref }}
82+
run: |
83+
set -euo pipefail
84+
fail() { echo "::error title=rulesets-probe::$1"; echo "rulesets-probe: REFUSED: $1" >> "$GITHUB_STEP_SUMMARY"; exit 1; }
85+
[ "$REF" = refs/heads/main ] || fail "release ruleset probe requires refs/heads/main"
86+
7987
- name: Mint org App token
8088
id: app
8189
uses: actions/create-github-app-token@v1

‎docs/ci.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,8 @@ The probe job runs on `["self-hosted","pf-gcp-post"]`, with `authz` on
13851385
`["self-hosted","pf-gcp-pr"]`.
13861386
`pf-gcp-main` admits only allowlisted workflows (an org runner-group restriction),
13871387
so the one-time probe uses `pf-gcp-post`.
1388+
The dispatch must run from `main`; the workflow itself refuses any other ref
1389+
before minting the App token or checking out repository code.
13881390
It runs `python3 scripts/ci_release_gate.py rulesets-probe --repo OWNER/REPO`,
13891391
reading only repository metadata, the parent-inclusive ruleset inventory and
13901392
branch details. Success prints the barrier id/name and one compact inventory

‎scripts/ci_preflight.py‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,8 @@ def runner_findings(workflows: dict[str, str]) -> list[str]:
10081008
actual = [_runner_value(value) for value in actual]
10091009
expected = [_runner_value(value) for value in expected]
10101010
if actual != expected:
1011-
suffix = '' if fixed_release[job] == PR_RUNNER else ' (isolated release)'
1011+
suffix = {PR_RUNNER: '', POST_RUNNER: ' (post fleet)'}.get(
1012+
fixed_release[job], ' (isolated release)')
10121013
findings.append(f'{name} job {job} must run on {fixed_release[job]}{suffix}')
10131014
environments = _job_values(workflow, 'env') + _job_values(body, 'env')
10141015
if any(re.search(r'\bPF_CI_LABELS["\']?\s*:', value) for value in environments):
@@ -1250,6 +1251,14 @@ def _step_block(step: str, key: str) -> list[str]:
12501251
needs: [authz]
12511252
runs-on: ["self-hosted","pf-gcp-post"]
12521253
steps:
1254+
- name: Refuse a dispatch ref other than main
1255+
env:
1256+
REF: ${{ github.ref }}
1257+
run: |
1258+
set -euo pipefail
1259+
fail() { echo "::error title=rulesets-probe::$1"; echo "rulesets-probe: REFUSED: $1" >> "$GITHUB_STEP_SUMMARY"; exit 1; }
1260+
[ "$REF" = refs/heads/main ] || fail "release ruleset probe requires refs/heads/main"
1261+
12531262
- name: Mint org App token
12541263
id: app
12551264
uses: actions/create-github-app-token@v1
@@ -1274,15 +1283,20 @@ def _step_block(step: str, key: str) -> list[str]:
12741283

12751284

12761285
def release_rulesets_probe_workflow_findings(workflow: str, release: str) -> list[str]:
1277-
probe_app = _step_named(_steps(_jobs(workflow).get('probe', '')),
1278-
' - name: Mint org App token')
1286+
steps = _steps(_jobs(workflow).get('probe', ''))
1287+
expected = _steps(_jobs(RELEASE_RULESETS_PROBE_WORKFLOW)['probe'])
1288+
findings = []
1289+
if not steps or _code(steps[0]) != _code(expected[0]):
1290+
findings.append('release-ruleset-probe.yml probe must refuse a dispatch ref other than '
1291+
'refs/heads/main as its first step before minting the App token or checkout')
1292+
probe_app = _step_named(steps, ' - name: Mint org App token')
12791293
release_app = _step_named(_steps(_jobs(release).get('release', '')),
12801294
' - name: Mint org App token')
12811295
if (_code(workflow) != _code(RELEASE_RULESETS_PROBE_WORKFLOW)
12821296
or _code(probe_app) != _code(release_app)):
1283-
return ['release-ruleset-probe.yml must keep the dispatch-only read-only probe '
1284-
'with the same release App token']
1285-
return []
1297+
findings.append('release-ruleset-probe.yml must keep the dispatch-only read-only probe '
1298+
'with the same release App token')
1299+
return findings
12861300

12871301

12881302
def release_bump_workflow_findings(workflow: str) -> list[str]:

‎scripts/test_ci_preflight.py‎

Lines changed: 117 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
RULESETS_PROBE_FINDING = (
6767
'release-ruleset-probe.yml must keep the dispatch-only read-only probe '
6868
'with the same release App token')
69+
RULESETS_PROBE_REF_FINDING = (
70+
'release-ruleset-probe.yml probe must refuse a dispatch ref other than '
71+
'refs/heads/main as its first step before minting the App token or checkout')
6972
RULESETS_PROBE_WORKFLOW = '''name: Release ruleset probe
7073
7174
on:
@@ -142,6 +145,14 @@
142145
needs: [authz]
143146
runs-on: ["self-hosted","pf-gcp-post"]
144147
steps:
148+
- name: Refuse a dispatch ref other than main
149+
env:
150+
REF: ${{ github.ref }}
151+
run: |
152+
set -euo pipefail
153+
fail() { echo "::error title=rulesets-probe::$1"; echo "rulesets-probe: REFUSED: $1" >> "$GITHUB_STEP_SUMMARY"; exit 1; }
154+
[ "$REF" = refs/heads/main ] || fail "release ruleset probe requires refs/heads/main"
155+
145156
- name: Mint org App token
146157
id: app
147158
uses: actions/create-github-app-token@v1
@@ -516,7 +527,9 @@ def gcp_sites(self):
516527
continue
517528
value, = ci_preflight._job_values(body, 'runs-on', unquote=False)
518529
finding = f'{name} job {job} must run on {runner}'
519-
if fixed_runner is not None and fixed_runner != PR_RUNNER:
530+
if fixed_runner == POST_RUNNER:
531+
finding += ' (post fleet)'
532+
elif fixed_runner is not None and fixed_runner != PR_RUNNER:
520533
finding += ' (isolated release)'
521534
yield name, job, fleet, f' runs-on: {value}\n', finding
522535

@@ -2250,7 +2263,7 @@ def test_gcp_sites_pin_probe_to_the_dispatch_fleet(self):
22502263
[('authz', 'pr'), ('probe', 'post')])
22512264
self.assertEqual(sites[1][-1],
22522265
f'release-ruleset-probe.yml job probe must run on {POST_RUNNER} '
2253-
'(isolated release)')
2266+
'(post fleet)')
22542267

22552268
def test_gcp_sites_reject_retired_and_void_labels(self):
22562269
for name, job, fleet, before, finding in self.gcp_sites():
@@ -3664,7 +3677,7 @@ def test_release_ruleset_probe_post_fleet_is_accepted(self):
36643677
def test_release_ruleset_probe_refuses_release_and_pr_fleets(self):
36653678
original, others = self.ci_sources(), self.other_sources()
36663679
finding = (f'release-ruleset-probe.yml job probe must run on {POST_RUNNER} '
3667-
'(isolated release)')
3680+
'(post fleet)')
36683681
for runner in (RELEASE_RUNNER, PR_RUNNER):
36693682
with self.subTest(runner=runner):
36703683
changed = in_job(RULESETS_PROBE_WORKFLOW, 'probe',
@@ -3679,6 +3692,104 @@ def test_release_ruleset_probe_refuses_release_and_pr_fleets(self):
36793692
ci_preflight.release_rulesets_probe_workflow_findings(
36803693
changed, others['release.yml']))
36813694

3695+
def test_release_ruleset_probe_main_ref_guard_precedes_credentials(self):
3696+
marker = ' - name: Refuse a dispatch ref other than main'
3697+
for workflow in (
3698+
(ROOT / '.github/workflows/release-ruleset-probe.yml').read_text(),
3699+
ci_preflight.RELEASE_RULESETS_PROBE_WORKFLOW,
3700+
RULESETS_PROBE_WORKFLOW):
3701+
with self.subTest(workflow=workflow):
3702+
steps = ci_preflight._steps(_jobs(workflow)['probe'])
3703+
self.assertEqual(steps[0].splitlines()[0], marker)
3704+
self.assertEqual(ci_preflight._step_values(steps[0], 'if'), [])
3705+
self.assertEqual(ci_preflight._step_values(steps[0], 'continue-on-error'), [])
3706+
self.assertEqual(ci_preflight._step_values(steps[0], 'env'),
3707+
['REF: ${{ github.ref }}'])
3708+
self.assertNotIn('secrets.', steps[0])
3709+
self.assertNotIn('token', steps[0])
3710+
self.assertEqual(steps[1].splitlines()[0], ' - name: Mint org App token')
3711+
self.assertEqual(steps[2].splitlines()[0], ' - name: Checkout')
3712+
3713+
def test_release_ruleset_probe_topic_dispatch_stops_before_mint(self):
3714+
workflow = (ROOT / '.github/workflows/release-ruleset-probe.yml').read_text()
3715+
steps = ci_preflight._steps(_jobs(workflow)['probe'])
3716+
mint = next(index for index, step in enumerate(steps)
3717+
if step.splitlines()[0] == ' - name: Mint org App token')
3718+
prefix = []
3719+
for step in steps[:mint]:
3720+
self.assertEqual(ci_preflight._step_values(step, 'uses'), [])
3721+
self.assertEqual(ci_preflight._step_values(step, 'if'), [])
3722+
self.assertEqual(ci_preflight._step_values(step, 'continue-on-error'), [])
3723+
self.assertEqual(ci_preflight._step_values(step, 'env'),
3724+
['REF: ${{ github.ref }}'])
3725+
name, = ci_preflight._step_values(step, 'name')
3726+
prefix.append(job_script(workflow, 'probe', name))
3727+
# Execute the real pre-mint shell; the echo marks reaching the action boundary.
3728+
script = ''.join(prefix) + 'echo "mint step reached"\n'
3729+
for ref, expected in (
3730+
('refs/heads/topic', 1), ('refs/tags/main', 1),
3731+
('refs/heads/main/topic', 1), ('refs/heads/Main', 1),
3732+
('', 1), ('refs/heads/main', 0)):
3733+
with self.subTest(ref=ref), tempfile.TemporaryDirectory() as directory:
3734+
summary = Path(directory) / 'summary'
3735+
result = subprocess.run(
3736+
['bash', '--noprofile', '--norc', '-eo', 'pipefail', '-c', script],
3737+
env={'PATH': os.environ.get('PATH', '/usr/bin:/bin'),
3738+
'REF': ref, 'GITHUB_STEP_SUMMARY': str(summary)},
3739+
capture_output=True, text=True)
3740+
self.assertEqual(result.returncode, expected, result.stdout + result.stderr)
3741+
self.assertEqual(result.stderr, '')
3742+
if expected:
3743+
self.assertEqual(result.stdout, '::error title=rulesets-probe::'
3744+
'release ruleset probe requires refs/heads/main\n')
3745+
self.assertEqual(summary.read_text(), 'rulesets-probe: REFUSED: '
3746+
'release ruleset probe requires refs/heads/main\n')
3747+
self.assertNotIn('mint step reached', result.stdout)
3748+
else:
3749+
self.assertEqual(result.stdout, 'mint step reached\n')
3750+
self.assertFalse(summary.exists())
3751+
3752+
def test_release_ruleset_probe_main_ref_guard_mutations_refuse(self):
3753+
original, others = self.ci_sources(), self.other_sources()
3754+
steps = ci_preflight._steps(_jobs(RULESETS_PROBE_WORKFLOW)['probe'])
3755+
guard, mint, checkout = (step + '\n' for step in steps[:3])
3756+
no_guard = RULESETS_PROBE_WORKFLOW.replace(guard, '', 1)
3757+
comparison = (' [ "$REF" = refs/heads/main ] || fail '
3758+
'"release ruleset probe requires refs/heads/main"')
3759+
guard_name = ' - name: Refuse a dispatch ref other than main\n'
3760+
for name, before, after in (
3761+
('missing main ref guard', guard, ''),
3762+
('main ref guard after mint', guard + mint, mint + guard),
3763+
('main ref guard after checkout', guard + mint + checkout, mint + checkout + guard),
3764+
('dispatch input ref', ' REF: ${{ github.ref }}',
3765+
' REF: ${{ github.event.inputs.ref }}'),
3766+
('head ref', ' REF: ${{ github.ref }}',
3767+
' REF: ${{ github.head_ref }}'),
3768+
('different ref comparison', comparison,
3769+
comparison.replace('[ "$REF" = refs/heads/main ]', '[ "$REF" = refs/heads/topic ]')),
3770+
('prefix ref comparison', comparison,
3771+
comparison.replace('[ "$REF" = refs/heads/main ]', '[[ "$REF" == refs/heads/main* ]]')),
3772+
('masked main ref refusal', comparison,
3773+
' [ "$REF" = refs/heads/main ] || true'),
3774+
('neutralized main ref exit', guard, guard.replace('exit 1; }', 'return 0; }')),
3775+
('main ref continue-on-error', guard_name,
3776+
guard_name + ' continue-on-error: true\n'),
3777+
('main ref if false', guard_name, guard_name + ' if: false\n'),
3778+
('main ref if always', guard_name, guard_name + ' if: ${{ always() }}\n'),
3779+
('main ref guard only in authz', RULESETS_PROBE_WORKFLOW,
3780+
in_job(no_guard, 'authz', ' steps:\n', ' steps:\n' + guard))):
3781+
with self.subTest(invariant=name):
3782+
self.assertEqual(RULESETS_PROBE_WORKFLOW.count(before), 1, name)
3783+
changed = RULESETS_PROBE_WORKFLOW.replace(before, after, 1)
3784+
self.assertNotEqual(changed, RULESETS_PROBE_WORKFLOW)
3785+
direct = ci_preflight.release_rulesets_probe_workflow_findings(
3786+
changed, others['release.yml'])
3787+
combined = ci_workflow_findings(
3788+
*original, others={**others, 'release-ruleset-probe.yml': changed})
3789+
for findings in (direct, combined):
3790+
self.assertIn(RULESETS_PROBE_REF_FINDING, findings)
3791+
self.assertIn(RULESETS_PROBE_FINDING, findings)
3792+
36823793
def test_release_ruleset_probe_comments_describe_the_actual_pin_scope(self):
36833794
source = (ROOT / 'scripts/ci_preflight.py').read_text()
36843795
workflow = (ROOT / '.github/workflows/release-ruleset-probe.yml').read_text()
@@ -3740,7 +3851,9 @@ def test_release_ruleset_probe_workflow_mutations_refuse(self):
37403851
('missing authz', authz, ''),
37413852
('missing needs', ' needs: [authz]\n', ''),
37423853
('disabled authz', ' name: authz\n', ' name: authz\n if: false\n'),
3743-
('authz refusal', 'exit 1; }', ':; }'),
3854+
('authz refusal',
3855+
'fail() { echo "::error title=authz::$1"; echo "authz: REFUSED: $1" >> "$GITHUB_STEP_SUMMARY"; exit 1; }',
3856+
'fail() { echo "::error title=authz::$1"; echo "authz: REFUSED: $1" >> "$GITHUB_STEP_SUMMARY"; :; }'),
37443857
('authz permissions', ' permissions: {}', ' permissions: {contents: read}'),
37453858
('authz runner', ' runs-on: ["self-hosted", "pf-gcp-pr"]',
37463859
' runs-on: ["self-hosted", "pf-gcp-post"]'),

‎scripts/test_ci_release_gate.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,8 @@ def test_probe_dispatch_branch_and_fleets_are_documented(self):
16991699
'`["self-hosted","pf-gcp-pr"]`.',
17001700
"`pf-gcp-main` admits only allowlisted workflows (an org runner-group restriction),\n"
17011701
"so the one-time probe uses `pf-gcp-post`.",
1702+
"The dispatch must run from `main`; the workflow itself refuses any other ref\n"
1703+
"before minting the App token or checking out repository code.",
17021704
)
17031705
message = "docs must state the probe's main dispatch and actual fleet routes"
17041706
for required in requirements:

0 commit comments

Comments
 (0)