Description:

This control ensures that all pull requests (PRs) must receive approval from an authorized reviewer before they can be merged into a protected branch. GitHub provides two ways to enforce this: repository rulesets and classic branch protection rules. This review process helps validate code quality, security, and compliance with organizational standards prior to integration.


Rationale:

Requiring pull request approval before merging enforces peer review and segregation of duties, reducing the risk of introducing defects, security vulnerabilities, or unauthorized changes into critical branches. It also promotes accountability and knowledge sharing among development teams.


Impact:

  • Prevents direct merging of unreviewed code into protected branches.

  • May increase the time required to merge pull requests due to the review process.

  • Improves code quality, maintainability, and security.

  • Supports change management and compliance requirements.


Default Value:

  • Disabled by default. Repository administrators must explicitly configure a ruleset or a classic branch protection rule to require pull request approvals before merging.


Remediation:

Branch protection can be configured using rulesets, classic branch protection rules, or both. Complete the section that matches the repository’s configuration. The control is met if either configuration enforces the requirement.


Rulesets:

Test Plan:

  1. Sign in to GitHub with administrative access to the repository.

  2. Navigate to the target repository.

  3. Select Settings.

  4. Under Code and automation, select Rules → Rulesets.

  5. Verify that an active branch ruleset targets the protected branch (e.g., main) and that Require a pull request before merging is enabled with the required number of approvals.

  1. If the ruleset is not active or the pull request approval requirement is not configured, follow the Implementation Steps below to remediate the issue and repeat the test.


Implementation Steps:

  1. Sign in to GitHub with administrative access to the repository.

  2. Navigate to the target repository.

  3. Select Settings.

  4. Under Code and automation, select Rules → Rulesets.

  1. Click New ruleset and select New branch ruleset, or edit an existing branch ruleset.

  2. Enter a name for the ruleset.

  3. Under Enforcement status, select Active.

  4. Under Target branches, specify the branch or branch pattern to protect (e.g., main).

  1. In the Rules section, enable Require a pull request before merging.

  2. Configure the Required approvals setting and specify the minimum number of approving reviews required before a pull request can be merged.

  1. Configure any additional review requirements as required by organizational policy.

  2. Click Create (or Save changes for an existing ruleset) to apply the ruleset.


Backout Plan:

  1. Sign in to GitHub with administrative access to the repository.

  2. Navigate to the target repository.

  3. Select Settings.

  4. Under Code and automation, select Rules → Rulesets.

  5. Edit the applicable branch ruleset.

  6. Disable Require a pull request before merging or reduce the required approval count.

  7. Click Save changes.

  8. Verify that pull requests can be merged according to the updated configuration.


Classic Branch Protection Rule:

Test Plan:

  1. Sign in to GitHub with administrative access to the repository.

  2. Navigate to the target repository.

  3. Select Settings.

  4. Under Code and automation, select Branches.

  5. Under Branch protection rules, verify that a rule matches the protected branch (e.g., main) and that Require a pull request before merging and Require approvals are selected with the required number of approvals.

  1. If no matching branch protection rule exists or the pull request approval requirement is not configured, follow the Implementation Steps below to remediate the issue and repeat the test.


Implementation Steps:

  1. Sign in to GitHub with administrative access to the repository.

  2. Navigate to the target repository.

  3. Select Settings.

  4. Under Code and automation, select Branches.

  1. Next to Branch protection rules, click Add classic branch protection rule, or click Edit next to an existing rule.

  1. In Branch name pattern, enter the branch or pattern to protect (e.g., main).

  2. Select Require a pull request before merging.

  3. Select Require approvals.

  4. In Required number of approvals before merging, select the minimum number of approving reviews required.

  1. Configure any additional review requirements as required by organizational policy.

  2. Click Create (or Save changes for an existing rule) to apply the rule.


Backout Plan:

  1. Sign in to GitHub with administrative access to the repository.

  2. Navigate to the target repository.

  3. Select Settings.

  4. Under Code and automation, select Branches.

  5. Click Edit next to the applicable branch protection rule.

  6. Clear Require approvals, or clear Require a pull request before merging, or reduce the required number of approvals.

  7. Click Save changes.

  8. Verify that pull requests can be merged according to the updated configuration.


References: