codefloe/forgejo-codefloe
Watch
4
12
Fork
You've already forked forgejo-codefloe
0

feat(branch-protection): force-push allowlist + admin override #36

Merged
pat-s merged 23 commits from t3code/47e77305 into v15.0/forgejo-codefloe 2026-05-24 16:15:24 +00:00
Owner

Summary

Allows repo admins and selected users/teams to force-push to a protected branch via a per-rule allowlist that mirrors the existing merge whitelist.

What changed

Adds an opt-in Enable force-push allowlist toggle to each branch protection rule.
When enabled, only listed users and teams can force-push.
Repo admins can also force-push when Enforce this rule for repository admins is off — the same admin-exemption flag used by other branch protection rules.

When a force-push is allowed via override, the git client sees a one-line note in the push output:

remote: Forgejo: Note: force-push to protected branch "main" allowed (force-push allowlist).

…or (admin override) for the admin path.
This uses a new general-purpose Messages channel on the private pre-receive hook response, so future "allowed but worth telling the user" cases can reuse it.

Compatibility

Behavior is opt-in.
Existing protected branches default to Enable force-push allowlist = false, which preserves the previous "force-push is always rejected" behavior.
A forward-only migration adds three columns to the protected_branch table with safe defaults.

Surface area

  • Model: EnableForcePushAllowlist, ForcePushAllowlistUserIDs, ForcePushAllowlistTeamIDs fields plus migration; cleanup wired into Remove{User,Team}IDFromProtectedBranch so removed users/teams are pruned from the lists.
  • Access check: git_model.IsUserForcePushAllowlisted mirroring IsUserMergeWhitelisted.
  • Pre-receive hook: unconditional force-push rejection replaced by a three-way decision (admin override → allowlist override → reject).
  • Web settings: new fieldset in the branch protection settings UI mirroring the merge whitelist.
  • API: enable_force_push_allowlist, force_push_allowlist_usernames, force_push_allowlist_teams on BranchProtection, CreateBranchProtectionOption, and EditBranchProtectionOption (plus swagger).
  • i18n: five new English keys.

Tests included

  • Unit test for IsUserForcePushAllowlisted (toggle off, user listed, user not listed).
  • Cleanup test extended to verify removal-on-user-delete prunes the new list.
  • Integration tests for three force-push scenarios: allowlist-allowed (with override message asserted), allowlist enabled but pusher not listed (still rejected), and admin override (with override message asserted).
  • API round-trip test: POST → PATCH → GET → DELETE.

Notes for reviewers

The first commit (docs(superpowers): spec + plan …) adds design documentation under docs/superpowers/.
Drop or squash it before merge if you'd rather keep the design notes out of upstream.

## Summary Allows repo admins and selected users/teams to force-push to a protected branch via a per-rule allowlist that mirrors the existing merge whitelist. ## What changed Adds an opt-in **Enable force-push allowlist** toggle to each branch protection rule. When enabled, only listed users and teams can force-push. Repo admins can also force-push when **Enforce this rule for repository admins** is off — the same admin-exemption flag used by other branch protection rules. When a force-push is allowed via override, the git client sees a one-line note in the push output: ``` remote: Forgejo: Note: force-push to protected branch "main" allowed (force-push allowlist). ``` …or `(admin override)` for the admin path. This uses a new general-purpose `Messages` channel on the private pre-receive hook response, so future "allowed but worth telling the user" cases can reuse it. ## Compatibility Behavior is opt-in. Existing protected branches default to `Enable force-push allowlist = false`, which preserves the previous "force-push is always rejected" behavior. A forward-only migration adds three columns to the `protected_branch` table with safe defaults. ## Surface area - **Model:** `EnableForcePushAllowlist`, `ForcePushAllowlistUserIDs`, `ForcePushAllowlistTeamIDs` fields plus migration; cleanup wired into `Remove{User,Team}IDFromProtectedBranch` so removed users/teams are pruned from the lists. - **Access check:** `git_model.IsUserForcePushAllowlisted` mirroring `IsUserMergeWhitelisted`. - **Pre-receive hook:** unconditional force-push rejection replaced by a three-way decision (admin override → allowlist override → reject). - **Web settings:** new fieldset in the branch protection settings UI mirroring the merge whitelist. - **API:** `enable_force_push_allowlist`, `force_push_allowlist_usernames`, `force_push_allowlist_teams` on `BranchProtection`, `CreateBranchProtectionOption`, and `EditBranchProtectionOption` (plus swagger). - **i18n:** five new English keys. ## Tests included - Unit test for `IsUserForcePushAllowlisted` (toggle off, user listed, user not listed). - Cleanup test extended to verify removal-on-user-delete prunes the new list. - Integration tests for three force-push scenarios: allowlist-allowed (with override message asserted), allowlist enabled but pusher not listed (still rejected), and admin override (with override message asserted). - API round-trip test: POST → PATCH → GET → DELETE. ## Notes for reviewers The first commit (`docs(superpowers): spec + plan …`) adds design documentation under `docs/superpowers/`. Drop or squash it before merge if you'd rather keep the design notes out of upstream.
Add Messages []string to Response and ResponseExtra, wire it through
requestJSONResp, switch HookPreReceive client to decode JSON (Response{})
instead of plain text, switch the server-side success response to JSON,
and print any messages to the git client output at both batch call sites.
polish(branch-protection): distinct legend label + reject-when-not-listed test
Some checks failed
testing / backend-checks (pull_request) Failing after 5m2s
testing / test-unit (pull_request) Has been skipped
testing / test-pgsql (pull_request) Has been skipped
testing / test-remote-cacher (redis) (pull_request) Has been skipped
testing / frontend-checks (pull_request) Successful in 1m35s
testing / test-e2e (pull_request) Has been skipped
testing / test-sqlite (pull_request) Has been skipped
testing / test-mysql (pull_request) Has been skipped
testing / test-remote-cacher (valkey) (pull_request) Has been skipped
testing / test-remote-cacher (redict) (pull_request) Has been skipped
testing / test-remote-cacher (garnet) (pull_request) Has been skipped
testing / security-check (pull_request) Has been skipped
867e64023a
fix(lint): suppress dupl on Remove*FromProtectedBranch + gofmt test map
Some checks failed
testing / test-mysql (pull_request) Has been skipped
testing / test-sqlite (pull_request) Has been skipped
testing / frontend-checks (pull_request) Successful in 1m58s
testing / test-e2e (pull_request) Has been skipped
testing / backend-checks (pull_request) Failing after 7m1s
testing / test-unit (pull_request) Has been skipped
testing / test-pgsql (pull_request) Has been skipped
testing / test-remote-cacher (redis) (pull_request) Has been skipped
testing / test-remote-cacher (redict) (pull_request) Has been skipped
testing / test-remote-cacher (valkey) (pull_request) Has been skipped
testing / test-remote-cacher (garnet) (pull_request) Has been skipped
testing / security-check (pull_request) Has been skipped
bd36b53b18
chore: regenerate swagger after force-push allowlist additions
Some checks failed
testing / backend-checks (pull_request) Failing after 5m32s
testing / test-unit (pull_request) Has been skipped
testing / test-e2e (pull_request) Has been skipped
testing / test-sqlite (pull_request) Has been skipped
testing / security-check (pull_request) Has been skipped
testing / frontend-checks (pull_request) Successful in 1m54s
testing / test-mysql (pull_request) Has been skipped
testing / test-pgsql (pull_request) Has been skipped
testing / test-remote-cacher (valkey) (pull_request) Has been skipped
testing / test-remote-cacher (redis) (pull_request) Has been skipped
testing / test-remote-cacher (redict) (pull_request) Has been skipped
testing / test-remote-cacher (garnet) (pull_request) Has been skipped
003a5806c6
fix(swagger): add trailing newline for editorconfig
Some checks failed
testing / frontend-checks (pull_request) Successful in 1m59s
testing / test-unit (pull_request) Successful in 7m53s
testing / backend-checks (pull_request) Successful in 13m45s
testing / test-remote-cacher (valkey) (pull_request) Successful in 5m0s
testing / test-remote-cacher (redict) (pull_request) Successful in 4m53s
testing / test-remote-cacher (garnet) (pull_request) Successful in 5m0s
testing / test-remote-cacher (redis) (pull_request) Successful in 5m0s
testing / security-check (pull_request) Has been cancelled
testing / test-e2e (pull_request) Successful in 29m46s
testing / test-sqlite (pull_request) Failing after 36m31s
testing / test-mysql (pull_request) Failing after 31m28s
testing / test-pgsql (pull_request) Has been cancelled
f6409bdc31
fix(branch-protection): emit override messages on stdout + enforce on admins in pre-existing test
Some checks failed
testing / test-remote-cacher (redict) (pull_request) Successful in 4m58s
testing / frontend-checks (pull_request) Successful in 2m13s
testing / backend-checks (pull_request) Successful in 9m57s
testing / test-unit (pull_request) Successful in 9m2s
testing / test-remote-cacher (valkey) (pull_request) Successful in 4m19s
testing / test-remote-cacher (redis) (pull_request) Successful in 4m21s
testing / test-remote-cacher (garnet) (pull_request) Successful in 4m20s
testing / test-pgsql (pull_request) Failing after 42m40s
testing / test-mysql (pull_request) Failing after 31m31s
testing / test-e2e (pull_request) Successful in 31m55s
testing / test-sqlite (pull_request) Failing after 38m37s
testing / security-check (pull_request) Has been skipped
c754dbe162
cmd/hook.go: extra.Messages from the pre-receive hook were being written to
the muted `out` writer (nilWriter when VerbosePush is off), so the override
note never reached the git client. Write them directly to os.Stdout instead.

tests/integration/git_test.go: the existing WhitelistedUserFailToForcePushToProtectedBranch
test ran with apply_to_admins unset (default false). Under the new admin-override
semantic the repo owner (an admin) is now allowed to force-push, so the test no
longer rejects. Set apply_to_admins=true on the surrounding WhitelistUsers
setup so the existing test continues to exercise the rejection path.
test(branch-protection): restore protected branch lineage after force-push tests
Some checks failed
testing / frontend-checks (pull_request) Successful in 3m6s
testing / backend-checks (pull_request) Successful in 14m29s
testing / test-unit (pull_request) Successful in 18m44s
testing / test-remote-cacher (valkey) (pull_request) Successful in 3m39s
testing / test-remote-cacher (redict) (pull_request) Successful in 3m38s
testing / test-remote-cacher (garnet) (pull_request) Successful in 5m43s
testing / test-remote-cacher (redis) (pull_request) Successful in 5m44s
testing / test-mysql (pull_request) Successful in 30m47s
testing / test-e2e (pull_request) Successful in 33m42s
testing / test-pgsql (pull_request) Successful in 42m58s
testing / test-sqlite (pull_request) Successful in 39m10s
testing / security-check (pull_request) Failing after 3m37s
173406777e
The force-push allowlist is a Codefloe-specific feature, not an upstream Forgejo
schema change. Move the migration accordingly so it lives next to the other
Codefloe-specific schema migrations and uses the codefloe_version tracker.
docs: remove docs/superpowers spec and plan
All checks were successful
testing / test-remote-cacher (garnet) (pull_request) Successful in 3m3s
testing / test-remote-cacher (valkey) (pull_request) Successful in 5m50s
testing / frontend-checks (pull_request) Successful in 2m4s
testing / backend-checks (pull_request) Successful in 14m22s
testing / test-unit (pull_request) Successful in 17m45s
testing / test-remote-cacher (redict) (pull_request) Successful in 3m2s
testing / test-remote-cacher (redis) (pull_request) Successful in 5m50s
testing / test-mysql (pull_request) Successful in 29m16s
testing / test-e2e (pull_request) Successful in 30m50s
testing / test-pgsql (pull_request) Successful in 41m32s
testing / test-sqlite (pull_request) Successful in 38m42s
c802aedc25
fix(branch-protection): admin override only applies when force-push allowlist is enabled
All checks were successful
testing / frontend-checks (pull_request) Successful in 1m54s
testing / backend-checks (pull_request) Successful in 13m17s
testing / test-unit (pull_request) Successful in 17m59s
testing / test-remote-cacher (garnet) (pull_request) Successful in 5m15s
testing / test-remote-cacher (valkey) (pull_request) Successful in 5m36s
testing / test-remote-cacher (redict) (pull_request) Successful in 5m41s
testing / test-mysql (pull_request) Successful in 24m22s
testing / test-pgsql (pull_request) Successful in 32m30s
testing / test-remote-cacher (redis) (pull_request) Successful in 5m36s
testing / test-sqlite (pull_request) Successful in 30m27s
testing / test-e2e (pull_request) Successful in 31m19s
milestone / set (pull_request_target) Has been skipped
issue-labels / backporting (pull_request_target) Has been skipped
4cb291c8ac
Previously the admin-override path fired regardless of the allowlist toggle, so
selecting "Disable force-push" still let admins force-push (when ApplyToAdmins
was false). That contradicts the user-facing semantic of the radio: "disable"
should mean disabled, even for admins. Gate the admin-override branch inside the
EnableForcePushAllowlist check so the toggle is the master switch.

Updated semantic:
- Allowlist OFF: force-push rejected for everyone, including admins.
- Allowlist ON: listed users/teams can force-push; admins also bypass when
  ApplyToAdmins is off.

Updated the i18n description to reflect the corrected behavior, restored the
pre-existing WhitelistedUserFailToForcePushToProtectedBranch test to its original
shape (it now also doubles as a regression test for the "admins can't force-push
when allowlist is off" case), and reworked the admin-override scenario to
enable the allowlist with an empty user list so the admin-override path is
actually exercised.
pat-s merged commit 3aeee8bf79 into v15.0/forgejo-codefloe 2026-05-24 16:15:24 +00:00
pat-s deleted branch t3code/47e77305 2026-05-24 16:15:24 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
codefloe/forgejo-codefloe!36
No description provided.