-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only allow admins to rename default/protected branches #33276
Only allow admins to rename default/protected branches #33276
Conversation
@@ -351,6 +352,9 @@ func RenameBranchPost(ctx *context.Context) { | |||
msg, err := repository.RenameBranch(ctx, ctx.Repo.Repository, ctx.Doer, ctx.Repo.GitRepo, form.From, form.To) | |||
if err != nil { | |||
switch { | |||
case repo_model.IsErrUserDoesNotHaveAccessToRepo(err): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm iffy about using ErrUserDoesNotHaveAccessToRepo
as an error here. Technically the user does have access to the repo, just not the access required to rename default/protected branches. Open to ideas
FYI: Make admins adhere to branch protection rules #32248 : there is a feature to block admins from bypassing the branch protection, maybe it should also be considered (or has it been considered already) ? |
The current change doesn't consider this. I found a GitHub changelog that seem to match my current implementation. I not familiar with setting up branch protection rules, but from messing around with GitHub's rulesets I don't see a way to disable the ability to rename protected branches |
Hmm I think we already (in a buggy way) handle this?? Using my changes, when I define a rule without special characters (i.e. But if I introduce wildcard characters (i.e. Not sure why we don't throw this error for the previous case? In the code we seem to honor the update and reflect it in the |
I think I might understand this design. It looks like if the new branch name == rule name, we treat it as "oh since the user wants to rename the branch I assume they also want to rename the rule". But if is a glob-based rule we don't make this assumption and instead throw this error. I'll make the necessary changes to follow this design closely. |
* giteaofficial/main: Only allow admins to rename default/protected branches (go-gitea#33276) Enable Typescript `noImplicitThis` (go-gitea#33250) Prepare for support performance trace (go-gitea#33286) Fix closed dependency title (go-gitea#33285) Move some Actions related functions from `routers` to `services` (go-gitea#33280) Fix incorrect TagName/BranchName usages (go-gitea#33279)
Currently, anyone with write permissions to a repo are able to rename default or protected branches.
This change follows GitHub's design by only allowing repo/site admins to change these branches. However, it also follows are current design for protected branches and only allows admins to modify branch names == branch protection rule names. Glob-based rules cannot be renamed by anyone (as was already the case, but we now catch
ErrBranchIsProtected
which we previously did not catch, throwing a 500).