Skip to content

Commit ce0ac01

Browse files
fix: authenticate every migration workflow
1 parent fe488bd commit ce0ac01

1 file changed

Lines changed: 42 additions & 2 deletions

File tree

‎scripts/test_pr_review_workflow.py‎

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,17 @@
188188
".github/workflows/review-caller-contract.yaml",
189189
".github/workflows/scorecard.yml",
190190
)
191+
# Approve the remaining workflow contents from the migration alongside its
192+
# shared-review files; a matching path alone must not authorize changed CI.
193+
OTHER_WORKFLOW_DIGESTS = {
194+
".github/workflows/canonical-contract-drift.yml": "afbbb7b23ce46902fb0e919539dce6ff7ebc85ce8213bc353f3439085fa98a06",
195+
".github/workflows/ci.yml": "cf7e7375251b8dfb8d74415cbdadde87b314071dccc244b78a6e4897d239115d",
196+
".github/workflows/codeql.yml": "ed7198f5f9394f6c93f496b9e2371ba23c1eb33ac0fa1c54884a2a7b3d820818",
197+
".github/workflows/dependency-review.yml": "1eff4db66f6a060b8c346d05981fa7273f6a60fe190b8fc695486f06462a5b8c",
198+
".github/workflows/fuzz.yml": "75e1a182dbb34789a308f233062d565ea324c5cd9c36ffddc37916be561f7e81",
199+
".github/workflows/release.yml": "e28954d424acee81dc669a83c9b182c60460941aa3e0da0eb63876eee87aa76b",
200+
".github/workflows/scorecard.yml": "42cb0dedc983fc30e27b4b073f66b24a85834d8d63c0e0c341b8e319c35e9389",
201+
}
191202

192203

193204
def git_environment():
@@ -262,6 +273,11 @@ def shared_migration(path):
262273
for name, expected in SHARED_FILES.items():
263274
if hashlib.sha256(read_blob(root, entries[name])).hexdigest() != expected:
264275
raise ValueError("shared review installation differs from its approved data")
276+
if set(OTHER_WORKFLOW_DIGESTS) != set(MIGRATED_WORKFLOWS) - set(SHARED_FILES):
277+
raise ValueError("migration workflow approvals are incomplete")
278+
for name, expected in OTHER_WORKFLOW_DIGESTS.items():
279+
if hashlib.sha256(read_blob(root, inventory[name])).hexdigest() != expected:
280+
raise ValueError("migration workflow differs from its approved data")
265281
return True
266282

267283

@@ -529,12 +545,18 @@ def setUp(self):
529545
self.digests = {
530546
name: hashlib.sha256(data).hexdigest() for name, data in self.shared_data.items()
531547
}
532-
self.patch = mock.patch.dict(globals(), SHARED_FILES=self.digests)
548+
other_data = b"name: CI\njobs:\n security-scan:\n runs-on: ubuntu-latest\n"
549+
other_digests = {
550+
name: hashlib.sha256(other_data).hexdigest() for name in OTHER_WORKFLOW_DIGESTS
551+
}
552+
self.patch = mock.patch.dict(
553+
globals(), SHARED_FILES=self.digests, OTHER_WORKFLOW_DIGESTS=other_digests
554+
)
533555
self.patch.start()
534556
self.addCleanup(self.patch.stop)
535557
for name in MIGRATED_WORKFLOWS:
536558
if name not in self.shared_data:
537-
self.write(name, b"name: existing CI\n")
559+
self.write(name, other_data)
538560

539561
def git(self, *arguments):
540562
environment = git_environment()
@@ -644,6 +666,24 @@ def test_mixed_installations_are_denied(self):
644666
(self.root / name).unlink()
645667
self.commit()
646668

669+
def test_changed_existing_workflows_are_denied(self):
670+
"""Matching workflow paths must not admit removed security jobs."""
671+
self.migrate()
672+
self.assertTrue(shared_migration(self.caller))
673+
for name in OTHER_WORKFLOW_DIGESTS:
674+
with self.subTest(name=name):
675+
original = (self.root / name).read_bytes()
676+
self.write(name, b"name: CI\njobs: {}\n")
677+
self.commit()
678+
for check, path in [
679+
(validate_caller, self.caller),
680+
(validate_contract, self.contract),
681+
]:
682+
with self.assertRaisesRegex(ValueError, "workflow differs"):
683+
check(path)
684+
self.write(name, original)
685+
self.commit()
686+
647687
def test_partial_and_tampered_installations_are_denied(self):
648688
self.migrate()
649689
for name, data in self.shared_data.items():

0 commit comments

Comments
 (0)