Skip to content

Commit a2bb907

Browse files
luisleo526claude
andauthored
ci: promote-baseline preflight rejects workflow-level defaults/env (#482 follow-up) (#483)
* ci: reject workflow-level defaults and env in the promote-baseline pin (SEC846 follow-up) Post-merge read of #482: the preflight pinned only the promote-guard job block, so a workflow-level defaults.run.shell or an env carrying a secret passed the checker while changing how the guard runs. ci_workflow_findings now rejects both, and the guard's own defaults, with specific findings; tests cover each reported input, the quoted and empty variants, and the unmodified workflow. Lane: ci-fu-eng482 (Codex gpt-6.1-sol). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * test: expect the pinned-guard finding in main's current wording (engine #483 after the main merge) After main (#470) landed, the checker's finding for a changed promote-guard block reads "must start with the pinned read-only promote-guard"; this PR's new test_promotion_guard_rejects_job_defaults still expected the earlier "credential-free" wording in its three subtests, so preflight failed. The expected list is now the exact list the checker emits (the job-level defaults finding, then the pinned-guard finding); the assertion stays an exact ordered equality. Checker unchanged. Lane: ci-fu-eng483b (Codex gpt-6.1-sol). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]>
1 parent 72d9fd5 commit a2bb907

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

‎docs/ci.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,9 @@ responses are selected by username. Mutation tests replace a script with
11991199
`exit 0`, remove repository/fork/identity checks or permission lookups, disable
12001200
`fail`, bypass failed lookups, add guard credentials or a checkout, or
12011201
disconnect the credential job. Missing, skipped or unsuccessful authorization
1202-
cannot admit promotion.
1202+
cannot admit promotion. The stage also rejects workflow-level `defaults` and
1203+
`env`, and guard-level `defaults`, so an inherited shell or environment
1204+
variable cannot bypass the guard pin.
12031205

12041206
The release pool is restricted to the existing pinned release and promotion
12051207
jobs; reusable call edges cannot admit PR events to them.

‎scripts/ci_preflight.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,13 @@ def ci_workflow_findings(ci: str, native: str, promote: str, cmake: str,
17121712
or '.["pineforge/parity"] == "success"' not in head_gate
17131713
or head_gate.count('echo "green=false" >> "$GITHUB_OUTPUT"; exit 0') != 2):
17141714
findings.append("baseline promotion must run main's copy and require the latest two head statuses")
1715+
# The job pin cannot see inherited workflow settings.
1716+
for key in ('defaults', 'env'):
1717+
if _job_values(promote, key):
1718+
findings.append(f'baseline promotion must not define workflow-level {key}')
17151719
promotion_jobs = _jobs(promote)
1720+
if _job_values(promotion_jobs.get('promote-guard', ''), 'defaults'):
1721+
findings.append('baseline promotion promote-guard must not define job-level defaults')
17161722
promotion_text = _jobs_text(promote) or ''
17171723
promotion_headers = list(_JOB_HEADER.finditer(promotion_text))
17181724
if ([header.group(1) for header in promotion_headers] != ['promote-guard', 'promote']

‎scripts/test_ci_preflight.py‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,45 @@ def test_promotion_guard_rejects_mutations_of_the_real_workflow(self):
944944
self.assertIn("baseline promotion must run main's copy and require the latest two head statuses",
945945
ci_workflow_findings(*changed))
946946

947+
def test_promotion_guard_rejects_workflow_defaults_and_env(self):
948+
original = self.ci_sources()
949+
self.assertEqual(ci_workflow_findings(*original), [])
950+
self.assertEqual(original[2].count('\njobs:\n'), 1)
951+
settings = (
952+
('defaults', 'defaults:\n run:\n shell: bash -c "exit 0" -- {0}\n'),
953+
('env', 'env:\n KEY: ${{ secrets.PINEFORGE_APP_PRIVATE_KEY }}\n'),
954+
('defaults', 'defaults: {}\n'),
955+
('env', 'env: {}\n'),
956+
('defaults', "'defaults': {run: {shell: bash}}\n"),
957+
('env', '"env": {PUBLIC_VALUE: harmless}\n'),
958+
)
959+
for key, setting in settings:
960+
with self.subTest(setting=setting):
961+
changed = original.copy()
962+
changed[2] = changed[2].replace('\njobs:\n', '\n' + setting + 'jobs:\n', 1)
963+
self.assertNotEqual(changed[2], original[2])
964+
self.assertEqual(_jobs(changed[2]), _jobs(original[2]))
965+
self.assertEqual(ci_workflow_findings(*changed), [
966+
f'baseline promotion must not define workflow-level {key}',
967+
])
968+
969+
def test_promotion_guard_rejects_job_defaults(self):
970+
original = self.ci_sources()
971+
self.assertEqual(ci_workflow_findings(*original), [])
972+
for setting in (
973+
' defaults:\n run:\n shell: bash -c "exit 0" -- {0}\n',
974+
' defaults: {}\n',
975+
' "defaults": {run: {shell: bash}}\n'):
976+
with self.subTest(setting=setting):
977+
changed = original.copy()
978+
changed[2] = in_job(changed[2], 'promote-guard', ' steps:\n',
979+
setting + ' steps:\n')
980+
self.assertNotEqual(changed[2], original[2])
981+
self.assertEqual(ci_workflow_findings(*changed), [
982+
'baseline promotion promote-guard must not define job-level defaults',
983+
'baseline promotion must start with the pinned read-only promote-guard',
984+
])
985+
947986
def promotion_guard_result(self, *, workflow=None, **overrides):
948987
"""Run the real workflow shell; only the external gh CLI is stubbed."""
949988
bash = shutil.which('bash')

0 commit comments

Comments
 (0)