Sub topic 9
Preventing the triggering user from approving
This chapter assumes you can read workflow YAML, know what a required reviewer is, and have an environment with at least one reviewer configured. Here you will add a rule that stops the person who triggered a deployment from approving it.
Why self-review is a problem
Required reviewers add a second pair of eyes before a job touches production. That protection disappears if the reviewer list includes the person who pushed the code. They could push a change and approve their own deployment, so no one else ever looked at it.
The prevent self-review setting closes that gap. When it is on, the user who triggered the workflow run cannot approve the deployment for that run. Someone else on the reviewer list must do it.
What counts as the triggering user
The triggering user is the person whose action started the run. For a push, that is the person who pushed. For a manual run with workflow_dispatch, it is the person who clicked the button. If you re-run a workflow, the person who re-ran it is the triggering user for that run.
The setting only restricts approval of that run. The same person can still approve deployments that other people triggered.
Turning it on
In the repository, open Settings, then Environments, then choose the environment. Under Deployment protection rules, enable Required reviewers, add reviewers, and check Prevent self-review. You can also set it through the API, as a later chapter shows. The relevant field is prevent_self_review:
{
"prevent_self_review": true,
"reviewers": [{ "type": "User", "id": 12345 }]
}Replace 12345 with a real user ID.
A common error: a one-person reviewer list
If the only reviewer is also the person who triggers deployments, the deployment can never be approved. The job waits until it times out or someone cancels it.
The table shows how the setting behaves with different reviewer lists.
| Reviewers | Self-review prevented | Who triggered the run | Result |
|---|---|---|---|
| Alice | Off | Alice | Alice can approve |
| Alice | On | Alice | Nobody can approve, so the run is stuck |
| Alice, Bob | On | Alice | Bob can approve |
| Alice, Bob | On | Carol (not a reviewer) | Alice or Bob can approve |
For a small team, list at least two reviewers before you enable the setting. A team can also be a reviewer, which keeps the list current as people join or leave.
Limits to remember
- The rule compares the approver with the user who triggered the run. It does not check who wrote the code. If Alice writes a change and Bob pushes it, Alice can approve.
- Repository administrators can still change the environment settings, including turning this rule off. Pair it with the branch restrictions covered in a later chapter.
- It does not replace pull request review. It gates the deployment step, not the merge.
Exercise
A repository has an environment named production with one required reviewer, Dana, and prevent self-review enabled. Dana pushes to main, which starts a deploy job that targets production. What happens, and how do you fix it?
Show answer
The job waits for approval, but Dana triggered the run, so she cannot approve it. No one else is on the reviewer list, so the deployment is stuck. Fix it by adding a second reviewer (or a team that includes someone other than Dana) to the environment's required reviewers.