Description

Ensure a ruleset on the repository's default branch prevents that branch from being deleted.

Rationale

The default branch is typically the primary source of truth for the codebase and the target of CI/CD pipelines and deployments. Deleting it, whether by accident or through a compromised account, causes an immediate and severe availability impact.

Impact

  • Prevents accidental or malicious deletion of the repository's default branch

  • Protects the primary source of truth for the codebase and its history

  • Prevents CI/CD pipelines and deployments tied to the default branch from breaking unexpectedly

  • Reduces the impact of a compromised account with push access

Default Value

By default, a repository with no ruleset targeting its default branch has no restriction on deleting that branch; anyone with sufficient permissions can delete it.

Pre-Requisites

  • Admin access to the repository

Test Plan

  1. Sign in to GitHub at https://github.com.

  2. Select the relevant repository.

  3. Click Settings.

  4. In the "Code, planning, and automation" section of the sidebar, click Rulesets.

  5. Select the ruleset that targets the default branch.

  6. Verify that Restrict deletions is enabled.

  1. If Restrict deletions is not enabled, or no ruleset targets the default branch, follow the implementation steps.

Implementation Steps

  1. Sign in to GitHub at https://github.com.

  2. Select the relevant repository.

  3. Click Settings.

  4. In the "Code, planning, and automation" section of the sidebar, click Rulesets.

  1. Select the existing ruleset that targets the default branch, or click New ruleset, then New branch ruleset.

  2. Under Ruleset Name, enter a name, and set Enforcement status to Active.

  3. Under Target branches, click Add target, then select Include default branch.

  4. Under Rules, enable Restrict deletions.

  1. Click Create or Save changes.

Backout Plan

  1. Sign in to GitHub at https://github.com.

  2. Select the relevant repository.

  3. Click Settings.

  4. In the "Code, planning, and automation" section of the sidebar, click Rulesets.

  5. Select the ruleset that targets the default branch.

  6. Disable Restrict deletions.

  7. Click Save changes.

Reference