Sub topic 12
Administrator bypass and what it means
This chapter assumes you can read workflow YAML and have already set up an environment with required reviewers, a wait timer, or branch restrictions. It covers a setting that can weaken all of those rules, and how to turn it off.
What the bypass setting does
Each environment has a setting named Allow administrators to bypass configured protection rules. It is on by default. While it is on, a repository administrator is not held to the environment's protection rules the way other users are. The rules still exist and still apply to everyone else.
For example, you might configure a required reviewer and a wait timer on production. If the bypass setting is on, an administrator can still push a deployment through without waiting for the review or the timer.
The setting does not appear in the workflow file. It belongs to the environment's configuration, so someone reading the YAML cannot tell whether it is on.
Why it matters
Your protection rules are only as strong as their weakest exception. Consider these cases:
- You require a reviewer other than the author. An administrator can still approve their own deployment.
- You restrict deployments to
main. An administrator is not blocked by that restriction. - You rely on the rules as evidence for an audit. The bypass undermines that evidence.
Bypass is useful in an emergency, such as a broken approval chain or a hotfix when reviewers are unavailable. The trade-off is that the emergency path is always open to every administrator, even when there is no emergency.
Turning bypass off
Open the environment under Settings, then Environments, and clear the bypass checkbox. You can also set it through the REST API with the can_admins_bypass field:
gh api --method PUT repos/OWNER/REPO/environments/production --input - <<'EOF'
{
"wait_timer": 10,
"prevent_self_review": true,
"can_admins_bypass": false,
"reviewers": [{ "type": "User", "id": 12345 }],
"deployment_branch_policy": {
"protected_branches": false,
"custom_branch_policies": true
}
}
EOFReplace 12345 with a real user ID. Send the full configuration each time. The PUT call creates or updates the environment, so a field you leave out may be reset to its default.
Common mistakes
- Assuming that adding required reviewers means every deployment is reviewed. With bypass on, administrators are exempt.
- Disabling bypass but leaving
prevent_self_reviewoff. The author can then approve their own deployment if they are a listed reviewer. - Reviewing settings only in YAML. Check the environment page, because the bypass setting is not in the workflow file.
Exercise
Your production environment requires one reviewer and has a 10-minute wait timer. A repository administrator pushes to main and the deployment starts without waiting for either. What is the most likely cause, and how do you fix it?
Show answer
The environment's "Allow administrators to bypass configured protection rules" setting is on, which is the default. Clear it in the environment settings, or send "can_admins_bypass": false in the REST API request, along with the rest of the environment configuration.