Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/issue-triage-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:

# Two-job pattern: triage runs with read-only issue access and produces a
# staged JSON artifact; apply runs with write access and calls safe-output.
permissions: {} # Reset to none; each job declares its own scoped block below.

jobs:
triage:
runs-on: ubuntu-latest
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/test-dev-lead.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- 'scripts/lib/**'
- '.github/workflows/dev-lead*.yml'
- '.github/workflows/test-dev-lead.yml'
- '.github/workflows/issue-triage-runner.yml'
- 'tests/dev-lead/**'
- 'prompts/dev-lead/**'
push:
Expand All @@ -22,6 +23,7 @@ on:
# (how the per-repo->per-lane mismatch stayed hidden after #450).
- '.github/workflows/dev-lead*.yml'
- '.github/workflows/test-dev-lead.yml'
- '.github/workflows/issue-triage-runner.yml'
workflow_dispatch: {}

permissions:
Expand Down Expand Up @@ -94,3 +96,16 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
run: python3 tests/dev-lead/integration/test_caller_permissions.py

toplevel-permissions:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
with:
persist-credentials: false
- name: Install PyYAML
run: python3 -m pip install --quiet pyyaml
- name: Validate issue-triage-runner.yml top-level permissions declaration
run: python3 tests/dev-lead/integration/test_workflow_toplevel_permissions.py
Comment thread
don-petry marked this conversation as resolved.
Resolved
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
"""Validate that issue-triage-runner.yml has a top-level permissions: declaration.

Org least-privilege policy requires every workflow to declare permissions at the
top level (even if just `permissions: {}`) so that GitHub's default
write-all grant is never silently inherited. Each job then overrides with its
own scoped block.

Standard: https://github.com/petry-projects/.github/blob/main/standards/ci-standards.md#permissions-policy
"""
from __future__ import annotations

import sys

try:
import yaml
except ImportError:
print("FAIL: PyYAML is required (pip install pyyaml)", file=sys.stderr)
sys.exit(2)

WORKFLOW = ".github/workflows/issue-triage-runner.yml"
Comment thread
don-petry marked this conversation as resolved.
Resolved


def main() -> int:
try:
with open(WORKFLOW, encoding="utf-8") as fh:
doc = yaml.safe_load(fh)
except FileNotFoundError:
print(f"FAIL: {WORKFLOW} not found")
return 1

if not isinstance(doc, dict):
print(f"FAIL: {WORKFLOW} did not parse as a YAML mapping")
return 1

if "permissions" not in doc:
print(
f"FAIL: {WORKFLOW} is missing a top-level 'permissions:' declaration.\n"
" Add `permissions: {}` before `jobs:` to satisfy the least-privilege policy.\n"
" Each job already has its own scoped permissions block — the top-level block\n"
" only needs to reset the GitHub default (write-all) to none."
)
return 1
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

if doc.get("permissions") != {}:
print(
f"FAIL: {WORKFLOW} must set top-level permissions to an empty mapping.\n"
" Expected: `permissions: {}` to reset default token scopes to none."
)
return 1

print(f"PASS: {WORKFLOW} has a top-level 'permissions: {{}}' declaration.")
return 0


if __name__ == "__main__":
sys.exit(main())
Loading