Description:
This check verifies that the default branch in a GitLab project is configured as a protected branch. Protected branches restrict who can push, merge, or modify code on critical branches, helping to prevent unauthorized or accidental changes.
Rationale:
The default branch typically contains production-ready or business-critical code. Protecting the default branch ensures that changes are controlled through approved workflows and helps maintain the integrity, stability, and security of the codebase.
Impact:
Restrict direct pushes to the default branch.
Require users to submit changes through merge requests.
Limit merge permissions to authorized users.
Improve change control and code quality.
Default Value:
In this GitLab environment, the default branch is automatically created as a Protected Branch with the following settings: Allowed to Push: Maintainers Allowed to Merge: Maintainers Force Push: Disabled The actual default value may vary based on GitLab instance-level or group-level configuration.
Pre-Requisites:
Maintainer or Owner access to the project
An existing GitLab project
Test Plan:
Sign in to GitLab at https://gitlab.com.
Navigate to the project.
Select Settings → Repository.
Locate the Protected Branches section.
Identify the default branch (typically main).
Verify that the default branch appears in the list of protected branches.
Verify the branch protection settings:
Branch is marked as Protected.
Push permissions are restricted.
Merge permissions are restricted.
Force push is disabled.
Implementation Steps:
Sign in to GitLab at https://gitlab.com.
If the default branch is not protected:
Navigate to the project.
Select Settings → Repository.
Expand the Protected Branches section.
Under Protect a Branch, select the default branch.
Configure:
Allowed to Push: Maintainers or No One (recommended).
Allowed to Merge: Maintainers.
Allow Force Push: Disabled.
Click Protect.
Verify that the default branch appears in the protected branches list.
Backout Plan:
Sign in to GitLab at https://gitlab.com.
If branch protection was enabled as part of this remediation and must be reverted:
Navigate to the project.
Select Settings → Repository.
Expand the Protected Branches section.
Locate the protected default branch.
Click Unprotect or modify the protection settings to their previous values.
Save the changes.
Reference: