Repository navigation
feat: implement issue #393 — Compliance: missing-permissions-issue-triage-runner.yml #485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
50a2821
feat: implement issue #393 — Compliance: missing-permissions-issue-tr…
donpetry-bot 00b7892
chore: apply manual instructions [skip ci-relay]
donpetry-bot fe70d14
fix(reviews): address review comments [skip ci-relay]
donpetry-bot 288b863
Merge branch 'main' into dev-lead/issue-393-20260608-0055
don-petry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
tests/dev-lead/integration/test_workflow_toplevel_permissions.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
|
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 | ||
|
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()) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.