Sub topic 7
Should administrators be exempt?
This chapter assumes you know how classic branch protection rules work and have admin access to a test repository. It covers how each system treats administrators and when an exemption is justified.
The default in classic branch protection
A classic rule does not always bind administrators. Unless you turn on enforcement for admins, people with the repository admin role can push directly to a protected branch, merge a pull request with failing checks, or skip required reviews. In the UI the setting is "Do not allow bypassing the above settings". In the API it is enforce_admins.
{
"required_status_checks": {
"strict": true,
"checks": [{ "context": "build" }]
},
"enforce_admins": true,
"required_pull_request_reviews": {
"required_approving_review_count": 1
},
"restrictions": null
}With enforce_admins set to true, the same rules apply to everyone. This is a single switch. You cannot exempt one named admin or one team.
The default in rulesets
Rulesets start from the opposite position. No one is exempt unless the ruleset lists them in bypass_actors. Being a repository admin gives no automatic exemption. Each bypass entry names a role, team, or app, and it sets a bypass_mode:
always: the actor can bypass the rules at any time, including direct pushes.pull_request: the actor can bypass only through a pull request, so the change stays visible and reviewable.
"bypass_actors": [
{
"actor_id": 5,
"actor_type": "RepositoryRole",
"bypass_mode": "pull_request"
}
]Here actor_id 5 is the repository admin role. Admins can merge a pull request without waiting for the other rules, but they cannot push straight to the branch.
Choosing a policy
Exemptions have a real use. An admin may need to merge a hotfix when a flaky check blocks the pipeline, or an app may need to push release commits. The risks of leaving admins exempt are also real:
- A compromised admin account skips every review.
- Habitual bypasses train people to ignore the rules.
- Audit questions such as "did every change to main get reviewed?" cannot be answered with a clean yes.
A reasonable approach:
- Enforce rules for admins by default.
- Grant bypass to the smallest group that needs it, such as an on-call team or a release bot.
- Prefer
pull_requestmode so every bypassing change still has a pull request on record.
Common errors
- Testing as an admin and seeing no blocks. If
enforce_adminsis off, you are exempt. Test with a non-admin account, or turn enforcement on first. - Assuming rulesets inherit the classic exemption. They do not. Admins can be blocked by a new ruleset that covers a branch they used to push to.
- Listing a broad role in the bypass list. Adding the whole write role effectively disables the ruleset for most contributors.
Exercise
A ruleset requires one approving review on main, and its bypass list is empty. A repository admin tries to push directly to main. What happens, and what is the least permissive change that lets admins merge urgent fixes?
Show answer
The push is blocked, because rulesets give admins no implicit exemption. The least permissive fix is to add the admin role (or a smaller on-call team) to bypassactors with bypassmode set to pull_request. Admins can then merge a pull request without the rule's requirements, but still cannot push directly.