Skip to content

Commit 09c0e88

Browse files
committed
fix(ci): grant the security permissions in dry-run.yml, and derive the caller list
DeusData#2189 gave codeql-gate the security-events:read it needs to see code-scanning alerts, and granted it at the two callers I knew about: pr.yml and release.yml. There is a third. dry-run.yml calls the same reusable workflow and was left granting only the workflow default, so every dispatch of it now fails at startup -- before a single job runs, with no job output to explain why. Observed immediately: run 34725401182 on 7d74337, startup_failure. The contract test did not catch it because it iterated a hardcoded ("pr.yml", "release.yml"). A test that checks only the callers you remembered cannot catch the one you forgot, and it reports green while doing so -- the same shape of false assurance as the 403-to-"0 alerts" bug this whole contract exists to prevent. So the list is now derived: every workflow containing `uses: ./.github/workflows/_security.yml` must grant security-events:read and actions:read, with a floor of three callers so a silent deletion is noticed too. Reverting only dry-run.yml's grant now fails the test by name. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 7d74337 commit 09c0e88

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

‎.github/workflows/dry-run.yml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ jobs:
5858
# ── Security (independent island — does not block main pipeline) ──
5959
security:
6060
uses: ./.github/workflows/_security.yml
61+
# The called job requests security-events:read to count code-scanning
62+
# alerts; a reusable workflow cannot request more than its caller grants,
63+
# so withholding this here fails the whole run at startup.
64+
permissions:
65+
contents: read
66+
security-events: read
67+
actions: read
6168
secrets: inherit
6269

6370
# ── Lint (cppcheck + clang-format) ────────────────────────────

‎tests/test_security_gate_fail_closed.sh‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,25 @@ require(
9898
# downgrade, it fails the entire run with a startup_failure before a single
9999
# job executes. Checking only the called workflow is how this test passed
100100
# while the PR pipeline never started.
101-
for caller_name in ("pr.yml", "release.yml"):
102-
caller = (root / ".github" / "workflows" / caller_name).read_text(encoding="utf-8")
101+
# The caller list is DERIVED, never hardcoded. An earlier revision listed
102+
# ("pr.yml", "release.yml") by hand and stayed green while dry-run.yml -- a
103+
# third caller nobody had listed -- failed every run at startup. A test that
104+
# only checks the callers you remembered cannot catch the one you forgot.
105+
workflow_dir = root / ".github" / "workflows"
106+
callers = sorted(
107+
path.name
108+
for path in workflow_dir.glob("*.yml")
109+
if "uses: ./.github/workflows/_security.yml" in path.read_text(encoding="utf-8")
110+
)
111+
require(
112+
len(callers) >= 3,
113+
"expected at least 3 callers of _security.yml, found: "
114+
+ (", ".join(callers) or "none")
115+
+ " -- if a caller was deliberately removed, lower this floor on purpose",
116+
)
117+
118+
for caller_name in callers:
119+
caller = (workflow_dir / caller_name).read_text(encoding="utf-8")
103120
# The next sibling may be a comment line, not a key, so the lookahead has to
104121
# accept any 2-space-indented non-space -- matching only ` \w` silently
105122
# failed to find release.yml's job at all.

0 commit comments

Comments
 (0)