Sub topic 8
Granting limited bypass access
This chapter assumes you know how a ruleset is structured (target, rules, bypass actors, enforcement) and can read the JSON bodies used in earlier chapters. It also assumes you understand GitHub repository roles, teams, and pull requests.
A ruleset with no exceptions will eventually block something urgent. A production fix may need to skip a review. A release bot may need to push a tag. Bypass actors let you allow those cases without turning the ruleset off. The goal is the narrowest exception that still lets the work happen, and a record of when it was used.
What a bypass actor is
A bypass actor is a person, team, role, or app that is allowed to skip the rules in one ruleset. The list belongs to the ruleset. An actor who can bypass protect-default-branch is not exempt from any other ruleset that targets the same branch.
Each entry in bypass_actors has three fields:
| Field | Meaning |
|---|---|
| `actor_id` | The numeric ID of the actor. For some actor types this is a fixed value. |
| `actor_type` | The kind of actor. |
| `bypass_mode` | When the actor may bypass: `always` or `pull_request`. |
The actor types you can use depend on where the ruleset lives.
| `actor_type` | Who it covers | Available in |
|---|---|---|
| `RepositoryRole` | A base role such as write, maintain, or admin, or a custom repository role | Repository and organisation rulesets |
| `Team` | A team in the organisation | Repository and organisation rulesets |
| `Integration` | A GitHub App, identified by its app ID | Repository and organisation rulesets |
| `OrganizationAdmin` | Organisation owners | Organisation rulesets |
| `DeployKey` | Deploy keys | Repository rulesets |
Repository roles use fixed IDs for the base roles. The example in the topic spine uses actor_id: 5, which is the repository admin role. The IDs for the other base roles are 1 (read), 2 (triage), 4 (write), and 2 for maintain in some listings, so check the current REST API documentation or list roles before hard-coding them. Custom roles have their own IDs, which you can find through the API. For a team, use the team's numeric ID, not its slug.
The two bypass modes
The bypass_mode field is where most of the narrowing happens.
always: the actor can push straight to the target ref and skip the rules. No pull request is needed.pull_request: the actor can skip the rules only by merging a pull request. Direct pushes remain blocked for them.
In the pull request mode, the actor opens a pull request as usual. When the rules are not satisfied, the merge box offers a bypass option. The actor uses it, and the pull request merges. The change still has a pull request, a diff, a discussion, and an audit trail.
Use always only when a pull request cannot work. A release app that pushes tags is the usual case, because tags are not merged through pull requests. For people, pull_request is almost always the right choice.
Reading the example from the spine
The ruleset from earlier in the tutorial contains this block:
{
"bypass_actors": [
{
"actor_id": 5,
"actor_type": "RepositoryRole",
"bypass_mode": "pull_request"
}
]
}It says: anyone holding the repository admin role may skip the rules, but only while merging a pull request. Because this is an organisation ruleset, the role is evaluated in each matched repository. An admin of payments-api can bypass in payments-api and nowhere else. An admin cannot force-push or delete the default branch, even though they can bypass the review requirement through a pull request. Their pull request bypass covers the whole ruleset for that merge, but the deletion and non_fast_forward rules protect operations that do not happen through a pull request, so those operations stay blocked for them.
Choosing the narrowest actor
Work through these questions in order and stop at the first answer that fits.
- Can the exception be a specific GitHub App? An app has a defined purpose and its permissions are limited. Prefer it to a person.
- Can it be a small team? A team such as
release-managerscan be audited. Membership changes are visible. - Can it be a custom role? This suits cases where a set of permissions, not a group of people, is the real criterion.
- Is a broad base role the only option? Then use
pull_requestmode, notalways.
Avoid putting the write role on the list. Everyone who can push can then skip the rules, and the ruleset stops having any effect on contributors. Avoid OrganizationAdmin in always mode for the same reason. Owners are few, but they are often the accounts that can least afford a mistake.
A useful pattern is a dedicated team for emergencies. Keep its membership small, require two-factor authentication for the organisation, and review the membership on a schedule.
{
"bypass_actors": [
{
"actor_id": 9876543,
"actor_type": "Team",
"bypass_mode": "pull_request"
},
{
"actor_id": 123456,
"actor_type": "Integration",
"bypass_mode": "always"
}
]
}Here the incident-responders team (ID 9876543, an example value) can merge urgent pull requests past the review rule. A release automation app (ID 123456, also an example) can act directly. Both IDs are placeholders. Replace them with values from your organisation.
Finding the IDs
You need numeric IDs, and the GitHub CLI can fetch them.
# Team ID, by organisation and team slug
gh api /orgs/YOUR_ORG/teams/incident-responders --jq .id
# Apps installed on the organisation, with their app IDs
gh api /orgs/YOUR_ORG/installations --jq '.installations[] | {app_id, app_slug}'The installations endpoint needs a token with the right permissions, and an app must be installed on the organisation before it can be added as a bypass actor. If an app is installed only on some repositories, it can bypass only where it has access.
Adding bypass actors through the API
You can update an existing ruleset without recreating it. Send the full bypass_actors array, because the update replaces the list.
gh api \
--method PUT \
-H "Accept: application/vnd.github+json" \
/orgs/YOUR_ORG/rulesets/RULESET_ID \
--input protect-default-branch.jsonEdit protect-default-branch.json to hold the new list first. If you leave out an actor you meant to keep, that actor loses bypass access on the next call.
Edge cases and common errors
- Bypass applies per ruleset. If two rulesets target the same branch, an actor must be on both lists to skip both. The next chapters cover how overlapping rulesets combine.
- Bypass is not the same as admin power. Under classic branch protection, admins could be included or excluded with one setting. In a ruleset, an admin has no special standing unless the admin role is on the list.
- Roles are evaluated per repository. In an organisation ruleset, a
RepositoryRoleactor is matched against the person's role in each repository. A person who is a maintainer in one repository and a reader in another gets different results. - Required workflows are rules too. A bypass actor can merge past a failing required workflow in
pull_requestmode. If the shared workflow is a compliance control, check whether the people on the list should be able to skip it. - Unknown IDs fail. An API call with a wrong
actor_idor anactor_typethat does not fit the scope returns a validation error. Do not retry with guessed IDs. - Bypass is visible. Bypassed changes show up in rule insights and the audit log, so you can review who used the exception and why. Use that review as part of your process, not only as a forensic tool.
A review checklist
Before saving a ruleset, check each entry on the bypass list.
- Is the actor a person, a role, a team, or an app, and is that the narrowest option?
- Is
pull_requestmode enough? - Does the exception still make sense in every repository the ruleset targets?
- Who owns the membership of the team or app, and when is it reviewed?
- Do you have a way to see when the bypass is used?
Exercise
An organisation ruleset protects the default branch of every repository. A release app must push version tags directly, and the on-call team must be able to merge urgent fixes without the usual review. Which bypass_mode should each actor get, and why?
Show answer
Give the release app always, because tag pushes do not go through a pull request, so pull_request mode would never apply. Give the on-call team pull_request, so urgent fixes still have a pull request, a diff, and an audit record, and the team cannot push directly or force-push the branch.
Exercise
A ruleset lists the repository write role as a bypass actor in always mode. What is the effect on contributors, and what would you change it to?
Show answer
Everyone who can push to the repository can skip the rules, so the ruleset no longer constrains ordinary contributors. Remove the write role. Add a small team or a specific app instead, and use pull_request mode for any people.