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:
Enabling branch protection may:
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.
Remediation:
Test Plan:
Log in to GitLab with access to the project.
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:
If the default branch is not protected:
Log in to GitLab with Maintainer or Owner privileges.
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:
If branch protection was enabled as part of this remediation and must be reverted:
Log in to GitLab with Maintainer or Owner privileges.
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.
References: