From a57fcc57505f971019b8b516e4cd016e396f8c7d Mon Sep 17 00:00:00 2001 From: aldbr <19813740+aldbr@users.noreply.github.com> Date: Tue, 1 Dec 2026 08:57:38 +0100 Subject: [PATCH] feat(rulesets): let repository admins bypass required checks in pull requests A security advisory's pull requests come from a temporary private fork where GitHub Actions does not run, so the required checks never report and GitHub refuses the merge ("may only be merged by someone that can bypass branch protections"). DIRAC GHSA-wh9g-g683-q496 is blocked on it. Add the repository admin role as a bypass actor of `required-checks`, in `pull_request` mode: an admin can merge a pull request with "Merge without waiting for requirements" (logged in the ruleset insights), and pushes to the protected branches stay blocked. Templates can now give a bypass mode next to an actor's name. Assisted-by: Claude:claude-opus-5-5 --- README.md | 4 ++-- rulesets/repos.toml | 6 ++++++ rulesets/required-checks.json | 4 +++- scripts/rulesets.py | 8 ++++++-- scripts/test_rulesets.py | 16 ++++++++++++++++ 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e22fcd4..5083126 100644 --- a/README.md +++ b/README.md @@ -34,11 +34,11 @@ Every repository gets the same rulesets, defined in `rulesets/`: - `branches`: the protected branches only change through a reviewed pull request with signed commits. - `fork-only`: nobody creates or pushes other branches in the repository, so pull requests come from forks. Renovate is the exception. - `tags` or `no tags`: only release managers create tags, or nobody does. -- `required-checks` (where `repos.toml` lists checks): the named CI jobs must pass before a merge. Only results reported by GitHub Actions count, so a status with the same name posted by a token or another app is ignored. +- `required-checks` (where `repos.toml` lists checks): the named CI jobs must pass before a merge. Only results reported by GitHub Actions count, so a status with the same name posted by a token or another app is ignored. Repository admins can bypass it when merging a pull request ("Merge without waiting for requirements"), and only then: a security advisory's pull requests come from a temporary private fork where GitHub Actions does not run, so their checks never report. The `branches` ruleset also asks for the approval of a code owner. This only has an effect in repositories with a `CODEOWNERS` file; a one-line file such as `/.github/ @DIRACGrid/dirac-release-manager` makes every workflow change go through a release manager. -What differs per repository (protected branches, whether it has releases, required checks) is in `rulesets/repos.toml`. The same file names the accounts the templates refer to (`[actors]`: Renovate, the release managers' team, GitHub Actions). +What differs per repository (protected branches, whether it has releases, required checks) is in `rulesets/repos.toml`. The same file names the accounts the templates refer to (`[actors]`: Renovate, the release managers' team, GitHub Actions, the repository admin role). A template lists an actor by name, or as `{"actor": name, "bypass_mode": "pull_request"}` for a bypass that only applies when merging a pull request.. ```bash scripts/rulesets.py # show what differs on GitHub, for every repository diff --git a/rulesets/repos.toml b/rulesets/repos.toml index 0a74c47..595e75c 100644 --- a/rulesets/repos.toml +++ b/rulesets/repos.toml @@ -26,6 +26,12 @@ dirac-release-manager = { actor_type = "Team", actor_id = 52350 } # The GitHub Actions app. Required checks are pinned to it, so a status with the # same name posted by anything else (a token, another app) does not count. github-actions = { actor_type = "Integration", actor_id = 15368 } +# The built-in admin role of each repository: bypasses `required-checks`, in pull +# requests only. A security advisory's pull requests come from a temporary private +# fork where GitHub Actions does not run, so their required checks never report. +# The admin merges them with "Merge without waiting for requirements"; the bypass +# is logged in the ruleset's insights. Pushes to the protected branches stay blocked. +repository-admin = { actor_type = "RepositoryRole", actor_id = 5 } [repos.".github"] required_checks = ["pre-commit"] diff --git a/rulesets/required-checks.json b/rulesets/required-checks.json index 54e3a65..a0588ca 100644 --- a/rulesets/required-checks.json +++ b/rulesets/required-checks.json @@ -13,5 +13,7 @@ } } ], - "bypass_actors": [] + "bypass_actors": [ + {"actor": "repository-admin", "bypass_mode": "pull_request"} + ] } diff --git a/scripts/rulesets.py b/scripts/rulesets.py index ada50a8..8600157 100755 --- a/scripts/rulesets.py +++ b/scripts/rulesets.py @@ -78,10 +78,14 @@ def render(params: dict, default_branch: str, actors: dict) -> dict[str, dict]: ] rulesets.append(required) + # A template names an actor, or gives {"actor": name, "bypass_mode": mode} + # for a mode other than "always" ("pull_request": only when merging a PR). for ruleset in rulesets: ruleset["bypass_actors"] = [ - {**actors[name], "bypass_mode": "always"} - for name in ruleset["bypass_actors"] + {**actors[entry], "bypass_mode": "always"} + if isinstance(entry, str) + else {**actors[entry["actor"]], "bypass_mode": entry["bypass_mode"]} + for entry in ruleset["bypass_actors"] ] return {r["name"]: r for r in rulesets} diff --git a/scripts/test_rulesets.py b/scripts/test_rulesets.py index 2ca8b1c..dc8b339 100644 --- a/scripts/test_rulesets.py +++ b/scripts/test_rulesets.py @@ -9,6 +9,7 @@ "renovate": {"actor_type": "Integration", "actor_id": 2740}, "dirac-release-manager": {"actor_type": "Team", "actor_id": 52350}, "github-actions": {"actor_type": "Integration", "actor_id": 15368}, + "repository-admin": {"actor_type": "RepositoryRole", "actor_id": 5}, } @@ -81,6 +82,21 @@ def test_required_checks_are_pinned_to_github_actions(self): self.assertFalse(pull_request["parameters"]["require_code_owner_review"]) self.assertNotIn("required-checks", render({}, "main")) + def test_admins_bypass_required_checks_in_pull_requests_only(self): + # Security advisory PRs come from a private fork where Actions does not run. + wanted = render({"required_checks": ["pre-commit"]}, "main") + self.assertEqual( + wanted["required-checks"]["bypass_actors"], + [ + { + "actor_type": "RepositoryRole", + "actor_id": 5, + "bypass_mode": "pull_request", + } + ], + ) + self.assertEqual(wanted["branches"]["bypass_actors"], []) + def test_equivalent_live_ruleset_is_not_drift(self): wanted = render({}, "main")["branches"] live = {