Learning center

Should GitHub Actions be allowed to approve pull requests?

Keep GitHub Actions from approving pull requests unless a workflow must, because an approval made with GITHUB_TOKEN can satisfy required approvals. If a workflow only needs to open pull requests, give it a GitHub App token and keep the setting off, since one switch covers both creating and approving.

What the setting controls#

Under Settings, Actions, General, "Workflow permissions," the option Allow GitHub Actions to create and approve pull requests configures "whether GITHUB_TOKEN can create and approve pull requests." For a new repository in a personal account, "workflows are not allowed to create or approve pull requests"; a repository in an organization inherits the organization's choice. Managing GitHub Actions settings for a repository For a new organization, the default is also off. Disabling or limiting GitHub Actions for your organization

The reason the switch exists is in the changelog that introduced it on 14 January 2022: it "protects against a user using Actions to satisfy the 'Required approvals' branch protection requirement and merging a change that was not reviewed by another user." The same post says that "to prevent breaking existing workflows," the setting was "enabled by default." Prevent GitHub Actions from approving pull requests On 3 May 2022 it was extended "to also limit Actions from creating pull requests." Prevent GitHub Actions from creating and approving pull requests An organization that existed before 2022 may therefore have the setting on without anyone having chosen it. Check it rather than assuming the current default.

A fictional label that turns into an approval#

Suppose a fictional organization, acme, has the setting on, and its acme/site repository requires one approval on main. A year ago someone added a workflow to the default branch that approves documentation-only pull requests when a maintainer labels them, to save reviewers a click:

name: approve-docs
on:
  pull_request:
    types: [labeled]
permissions:
  pull-requests: write
jobs:
  approve:
    if: github.event.label.name == 'docs-only'
    runs-on: ubuntu-latest
    steps:
      - run: gh pr review --approve "$PR_URL"
        env:
          PR_URL: ${{ github.event.pull_request.html_url }}
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

The workflow trusts the label, and the label proves nothing about the diff. Applying labels needs only the Triage role, below Write. Repository roles for an organization Nora opens a pull request that edits a README and also changes the site's content security policy header. She adds docs-only. The workflow approves, the approval satisfies the one required review, CI passes because nothing tests the header, and Nora merges a security change that no other person read.

Turning the setting off makes the gh pr review --approve step fail, and the pull request waits for a human approval like any other.

What turning it off does not catch#

The setting governs GITHUB_TOKEN. An approval made with a personal access token stored as a secret, or with a GitHub App's token, is outside it. Renovate's documentation, for example, describes helper apps that "will mark all automerging Pull Requests by Renovate as approved." Renovate: required pull request reviews Audit those tokens and apps separately.

It also does not stop a person from editing a workflow in a pull request to do something else with the token's permissions. The guide to pull requests that edit their own workflow covers protecting .github/workflows/ with code owners.

Some rules keep a bot approval from being enough on its own. If Require review from Code Owners is on, a changed file with an owner still needs that owner's approval, and code owners must be users or teams with write access, which an Actions approval is not. About code owners

The cost of leaving it off#

Two common workflows stop working. The first approves pull requests, usually dependency updates, such as the auto-approve example in GitHub's Dependabot docs, which runs gh pr review --approve with GITHUB_TOKEN. Automating Dependabot with GitHub Actions The dependency bot guide covers when those pull requests can merge on checks and how to allow it without a workflow approval.

The second opens pull requests, such as a release workflow that proposes a changelog or a scheduled job that regenerates files. Those fail too, because one switch covers both actions. The usual fix is to create those pull requests with a GitHub App installation token instead. That also changes how CI runs on them: when a workflow creates or updates a pull request with GITHUB_TOKEN, the resulting runs start "in an approval-required state," and the docs recommend "a GitHub App installation access token or a personal access token" if you need them to run without approval. GITHUB_TOKEN

Decide#

  1. Check the setting at the organization level and in each repository that overrides it.
  2. If it is on, search your workflows for gh pr review --approve, pulls/{pull_number}/reviews calls with event: APPROVE, and actions whose purpose is approving.
  3. For each approving workflow, ask what the approval stands for. If it stands for "checks passed," required status checks already record that, and the approval only removes the human review the rule asks for. Decide whether those pull requests need a person, and remove the workflow approval where they do.
  4. Move pull request creation to a GitHub App token, then turn the setting off.

Keep it on only when a workflow's approval is a deliberate, documented exception, for example in a repository whose only changes are generated, and say so in the repository's contributing guide.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading