From 50f296cf7609ce77d41b9fb3df51d6aeec8330d6 Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 13 Nov 2026 22:28:22 +0000 Subject: Remove protected-refs: a rule covers what it names, and nothing else `set protected-refs` raised the price of a listed ref by one level: write needed force on main, force needed admin. It was a second, invisible list, and it was the one part of the model that could not be read off the rules. The question it was supposed to answer - "who can move main?" - stopped having an answer in the file: you had to hold both the rules and the protection list in your head and combine them, and the combination was where surprises lived. Giving someone force so they could rewrite their own branches quietly let them fast-forward main, because a fast-forward costs write, protection raised it to force, and there it was. Now a rule says what it says. An unscoped rule covers main; a rule that means to leave main alone names what it covers instead, and the refusal says "bob holds write on team, but not on refs/heads/main" rather than blaming a list nobody remembered. Excluding one person from one branch is a matter of what their lines name, which is the same mechanism as everything else here. The setting is refused by name rather than ignored. A policy that still carries one would otherwise mean "everyone with write can fast-forward main" while looking like it said the opposite, and the operator would learn that from a push rather than from the parser; so `set protected-refs` is now an error that says what to write instead, and the suite asserts both halves - that it is refused, and that cleaning it out makes the file valid again. What stays: refs outside refs/heads and refs/tags still need admin whatever a rule appears to grant about them. That one the policy genuinely cannot name in advance, because it is the part of the namespace no policy was written with in mind. `protect` goes with it, so the editing commands are grant and revoke. The example policy now names frank, whose two refs are main and the release tags, because that is the shape the file is now meant to be written in. --- authz.conf | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'authz.conf') diff --git a/authz.conf b/authz.conf index afea7d2..7881329 100644 --- a/authz.conf +++ b/authz.conf @@ -2,36 +2,40 @@ # # One file, read by the receive hook on every push and by nothing that serves # reads. The deployed copy is mounted read-only - a ConfigMap - so changes are -# made to the copy in git and rolled out; `git-authz grant`, `revoke` and -# `protect` edit a source copy and refuse, with an explanation, when pointed at -# the read-only one. +# made to the copy in git and rolled out; `git-authz grant` and `revoke` edit a +# source copy and refuse, with an explanation, when pointed at the read-only one. # # [ ... ] # # Levels stack: admin implies force implies write, and every rule for a user -# counts, so the strongest match wins. There is no 'deny': access is taken -# away by deleting the rule that gave it. +# counts, so the strongest match wins. There is no 'deny': access is taken away +# by deleting the rule that gave it, which means the file always says the whole +# of what it grants. +# +# A rule with no ref patterns covers the whole repository, refs included. With +# patterns, it covers exactly those refs and nothing else - so the answer to +# "who can move main" is the lines that name main, and there is no second list +# somewhere else in the file that can raise the price of a ref behind your back. # # A ref pattern is a glob in which '*' crosses '/'. "main", "heads/main" and # "refs/heads/main" name the same branch; a bare name is always a branch, so a -# tag has to be written "refs/tags/v1" or "tags/v1". With no patterns at all -# the rule covers the whole repository, refs included. +# tag has to be written "refs/tags/v1" or "tags/v1". # -# '@all' means everyone this policy already names somewhere. It is not a -# wildcard for anonymous users: nobody reaches it who has no rule of their own. - -# What costs an extra level to move. A write on these needs force, a force -# needs admin, and refs outside refs/heads and refs/tags need admin regardless. -set protected-refs refs/heads/main refs/tags/* +# '@all' means everyone this policy already names somewhere. It is not a wildcard +# for anonymous users: a name that appears nowhere in the file reaches nothing, +# so adding a rule for a person is the whole of onboarding. +# +# Whatever a rule says about them, refs outside refs/heads and refs/tags need +# admin: refs/notes, refs/merge-requests, whatever a tool invents next are not +# part of the namespace a policy was written with in mind. -# The account for break-glass and for the refs nobody else should touch: it is -# unscoped, so it covers the whole repository including refs/notes and friends. +# The account for break-glass and for the refs nobody else should touch. alice * admin -# Default for everyone the policy knows: their own branches, anywhere. Reads -# are open, so this is about writing, and there is no rule here to be the -# fall-through for someone the policy has never mentioned. -@all * write refs/heads/* +# Default for everyone the policy knows: their own working branches, anywhere. +# Reads are open, so this is only about writing - and it deliberately does not +# reach main, which is named below, person by person. +@all * write refs/heads/feature/* refs/heads/bugfix/* # Contributor on team: feature branches only. bob team write refs/heads/feature/* @@ -39,8 +43,11 @@ bob team write refs/heads/feature/* # Senior on team: may rewrite his feature branches and delete them. carol team force refs/heads/feature/* -# Maintainer of team: everything, including main, tags, and deletions. +# Maintainer of team: everything, including main, tags and deletions. dave team admin +# Frank does releases: main and the release tags, and nothing else. +frank team write refs/heads/main refs/tags/release/* + # Team A's repository, with an unrelated ACL. erin secrets admin -- cgit v1.2.3