Repository navigation
feat: Add bypass allowlist for branch protection - #36514
Conversation
03c404c to
36d1fbf
Compare
There was a problem hiding this comment.
Pull request overview
This pull request introduces a "Bypass Protection Allowlist" feature for branch protection rules, allowing specific users and teams to bypass branch protection checks (required approvals, status checks, and protected files) without requiring full administrator privileges. This addresses the need for "Merge Masters" or "Technical Leads" who need bypass capabilities while following the Principle of Least Privilege.
Changes:
- Added database columns
EnableBypassAllowlist,BypassAllowlistUserIDs, andBypassAllowlistTeamIDsto theProtectedBranchmodel with migration v326 - Implemented
CanBypassBranchProtectionhelper function that checks both admin privileges and allowlist membership - Extended API endpoints and Swagger documentation to support bypass allowlist configuration
- Updated branch protection settings UI to allow configuration of bypass users and teams
- Modified pull request merge box to display appropriate messages for bypass-capable users
- Applied bypass logic in pre-receive hooks and merge checks to allow allowlisted users to override unmet requirements
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| models/migrations/v1_26/v326.go | Migration adding three new columns to ProtectedBranch table for bypass allowlist feature |
| models/migrations/migrations.go | Registers the new migration v326 |
| models/git/protected_branch.go | Adds bypass allowlist fields to ProtectedBranch model and implements CanBypassBranchProtection function |
| models/git/protected_branch_test.go | Unit tests for CanBypassBranchProtection covering various scenarios |
| modules/structs/repo_branch.go | Extends API structs (BranchProtection, CreateBranchProtectionOption, EditBranchProtectionOption) with bypass allowlist fields |
| routers/api/v1/repo/branch.go | Updates API endpoints to handle bypass allowlist users and teams during branch protection creation and editing |
| routers/web/repo/setting/protected_branch.go | Handles bypass allowlist data in web UI forms for branch protection settings |
| routers/web/repo/issue_view.go | Sets template data for bypass permissions to control merge button visibility and messages |
| routers/private/hook_pre_receive.go | Applies bypass logic in pre-receive hook to allow bypass users to push despite protection checks |
| services/pull/check.go | Uses CanBypassBranchProtection in merge checks instead of admin-only check, updates comment |
| services/pull/check_test.go | Removes redundant queue.Has() checks that could cause test flakiness |
| services/forms/repo_form.go | Adds bypass allowlist fields to ProtectBranchForm |
| services/convert/convert.go | Converts bypass allowlist IDs to usernames/team names for API responses |
| templates/repo/settings/protected_branch.tmpl | UI form for configuring bypass allowlist users and teams |
| templates/repo/issue/view_content/pull_merge_box.tmpl | Displays context-appropriate message when bypass user can force merge |
| templates/swagger/v1_json.tmpl | Swagger documentation for bypass allowlist fields in API |
| options/locale/locale_en-US.json | Locale strings for bypass allowlist UI elements and messages |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
36d1fbf to
da1f775
Compare
ReviewI reviewed the full diff. The overall structure follows existing patterns well (model fields, migration, API plumbing, settings UI, template). A few observations: 1. Breaking behavior change in pre-receive hookThe original if ctx.userPerm.IsAdmin() {
return
}The new code replaces this with This is arguably more correct behavior (closing an inconsistency), but it is a breaking change for existing setups and should be called out explicitly in the PR description and release notes. 2. Unrelated test change in
|
|
What do we do about point 1? Is it worth calling out a breaking change? I think not as it's probably too obscure of a feature. |
|
I would not call it breaking but idk |
|
Ok, please address points 3 and 4 if you can. |
|
both are already done - I think |
|
any screenshot of the added ui? |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 17 out of 17 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
fixed |
|
Fix merge conflicts please and show a screenshot of the added UI. |
03d5b44 to
b108b00
Compare
|
@silverwind Done - here a screenshot |
|
Updated so no conflicts |
|
Also added a test which I somehow forgot back then :-( |
- Drop unused `cachegroup.BypassAllowlist` constant (cache path was
already removed) and unused `repo.pulls.required_status_check_bypass_allowlist`
locale key (no caller in this PR).
- Collapse `CanBypassBranchProtection` `(byAdmin, byAllowList bool)` return
into a single `bool`; both callers discarded the first value, and the
second was `true` even when only admin bypass applied.
- Guard the force-merge path against a nil protected-branch rule (race if
the rule is deleted between `CheckPullBranchProtections` and the reload
in the force-merge branch) and rename `adminForceMerge` -> `forceMerge`
since the semantics now cover non-admin bypass users.
- Reshape the `EditBranchProtection` bypass user/team blocks to mirror
the sibling allowlists (2-way `if name != nil { validate } else { keep }`)
and clear both lists once at the end when the allowlist is disabled,
instead of asymmetric per-block `else if !Enable` branches.
Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Added it back |
* origin/main: (39 commits) fix: Add missed token scope checking (go-gitea#37735) chore: Use giteabot instead of backporter (go-gitea#37422) fix: Allow direct commits for unprotected files with push restrictions (go-gitea#37657) chore: Conventional adjustments (go-gitea#37677) chore(db): introduce db.Session and db.EngineMigration interfaces (go-gitea#37746) fix(migrations): preserve unique constraints in v334 sync (go-gitea#37743) feat(web): also display PR counts in repo list (go-gitea#37739) feat: execute post run cleanup when workflow is cancelled (go-gitea#37275) fix(actions): wrong assumption that run id always >= job id (go-gitea#37737) fix(icon): use repo-forked icon to display forks count (go-gitea#37731) fix(oauth): strengthen PKCE validation and refresh token replay protection (go-gitea#37706) fix(web): enforce token scopes on raw, media, and attachment downloads (go-gitea#37698) feat: Add bypass allowlist for branch protection (go-gitea#36514) refactor(glob): use strings.Builder for regexp compilation (go-gitea#37730) feat(oauth): Support AWS Cognito OAuth2 provider (go-gitea#37607) feat: Add default PR branch update style setting (go-gitea#37410) refactor: move `workflowpattern` into `modules/actions` (go-gitea#37717) ci: add `zizmor` to `lint-actions` (go-gitea#37720) chore(doctor): remove four obsolete doctor check implementations (go-gitea#37728) chore(renovate): enable dockerfile manager (go-gitea#37719) ... # Conflicts: # modules/globallock/locker_test.go
I'd like to apply as a maintainer. Thanks to @TheFox0x7 for the suggestion. Merged PRs: - go-gitea#36441 - go-gitea#36571 - go-gitea#36603 - go-gitea#36768 - go-gitea#36776 - go-gitea#36783 - go-gitea#36876 - go-gitea#36883 - go-gitea#36924 Ongoing work: - go-gitea#36514 - go-gitea#36752 - go-gitea#36912
- Introduce a “Bypass Protection Allowlist” on branch rules (users/teams) alongside admins, with BlockAdminMergeOverride still respected. - Surface the allowlist in API (create/edit options, structs) and settings UI; merge box now shows the red button + message for bypass-capable users. - Apply bypass logic to merge checks and pre-receive so allowlisted users can override unmet approvals/status checks/ protected files when force-merging. - Add migration for new columns, locale strings, and unit tests (bypass helper; queue test tweak). <img width="1069" height="218" alt="image" src="/api/public/p/aHR0cHM6Ly9naXRodWIuY29tL2dvLWdpdGVhL2dpdGVhL3B1bGwvJTNDYSUyMGhyZWY9"/api/public/p/aHR0cHM6Ly9naXRodWIuY29tL3VzZXItYXR0YWNobWVudHMvYXNzZXRzLzBiNjFiYzJhLWEyN2YtNDdmMy1hOTIzLTYxMzY4ODAwOGU2NQ">https://github.com/user-attachments/assets/0b61bc2a-a27f-47f3-a923-613688008e65" /> Fixes go-gitea#36476 --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Giteabot <teabot@gitea.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Hanzo Dev <dev@hanzo.ai> Co-authored-by: Hanzo Dev <dev@hanzo.ai> Co-authored-by: Hanzo Dev <dev@hanzo.ai> Co-authored-by: Hanzo Dev <dev@hanzo.ai>
still respected.
message for bypass-capable users.
protected files when force-merging.
Fixes #36476