summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* README: what the policy says, what an update costs, and why three is not onedev2026-11-131-0/+223
| | | | | | | | | | | | | Written as the questions get asked: what a rule means, what happens to a non-fast-forward, why "no policy" is a different exit status from "denied", which two facts belong to git and what is assumed when it cannot answer them, and why the editing commands refuse a read-only mount instead of writing somewhere surprising. The exit statuses are the interface, so they are stated once and up front: 0 allowed, 1 denied, 3 the host is broken, 64 you asked wrong. A refusal that a colleague reads is a support request; a refusal that a monitor reads is a page. The two must not share a status.
* tests: drive the binary the way a hook is drivendev2026-11-131-0/+786
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 148 checks against the real binary, with no git anywhere in the suite. The unit tests pin the semantics and were passing throughout. They cannot say that an option telling the program not to run git still runs it, that a repository is detected against a path built without the working directory in it, that "--out" is being granted as a branch name, or that a policy with no parse errors but no file behind it is announced as being in force. Those are four of the bugs this suite found. So it feeds the binary what a receive hook gets: an identity in the environment, "old new ref" lines on stdin, the repository as the working directory, the program reached through a symlink named pre-receive with git's own argument in hand - an argument that is git's, and must not be read as one of ours. The two facts only the object store knows are supplied rather than derived (--ff, --head), which is what makes it deterministic and what makes it a test of the consequences of each answer: an update that cannot be shown to be a fast-forward costs force, a deletion whose HEAD cannot be read costs admin. It covers the ladder and the ref grammar, the protected raise, @all, identity over both transports and the absence of one, a push of several refs stopping at the first refusal, input that is not a push, every way the policy can be unusable, validate against a tree that stands in for a host, the editing commands against real files (comments preserved, mode preserved, no temporary left behind, a file that does not parse refused without being touched), and make install into a DESTDIR - including that the link is relative and that an existing policy survives. Runs under dash and busybox ash as well as bash, because the container this eventually serves is Alpine.
* Install: the hook is a relative symlink, and the policy is configurationdev2026-11-133-24/+136
| | | | | | | | | | | | | | | | | | | | | | | | The hook is a symlink named pre-receive, because that name is what core.hooksPath looks for and what selects authorize mode inside the binary. It was built by cd'ing into the hook directory first, which left the awk script writing the relative path out of reach, and the recipe failed with the link never created. The path is computed where the script is, and the link is made from there. Relative rather than absolute for the reason that matters during an install: a staged tree under DESTDIR, an unpacked prefix, or an image assembled somewhere else must point at the binary that came with them, not at whatever lives at the same absolute path on the machine reading the link. relpath.awk walks both paths component by component - it is not a string-prefix operation, because /usr/local/share and /usr/local/bin share a prefix only up to the point where ".." starts - and falls back to the absolute path when a component cannot be named from where it stands. authz.conf is the example policy, and the installer treats it as configuration: an existing file is an operator's, so it is kept and the new example lands beside it as authz.conf.new rather than over the rules someone wrote down. `make sanitizer' builds both suites under AddressSanitizer and UBSan, which is how the editing bugs in the previous commit were found.
* Editing: options anywhere, a file that is not there yet, one owner per linedev2026-11-132-168/+268
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Three things the editing commands got wrong, two of them in the same direction - taking an argument for something it is not. --out and --stdout were only accepted before the names, which is not where people put them, and "grant bob team write --out /tmp/new.conf" therefore granted a ref pattern called "--out" and wrote it into the file. Options are now pulled out from wherever they sit and what is left compacted, and a name that starts with "--" is reported as the typo it is rather than granted. A file that does not exist was refused with "create one with --out", which tells the operator to do by hand what the command exists to do. grant and protect now start the file, grammar written at the top of it, and say so in the report; revoke reports that there was nothing to remove. A file that does not parse is still refused: editing something the parser cannot read would rewrite the parts that parse and keep the damage. And the line array. rule_text() handed its buffer to the array while the command also freed it, and protect handed a string literal to an array whose free function frees every entry it holds: the first was a use-after-free and the second corrupted the heap badly enough to write garbage into the file being edited. One owner per line now, the copy made where the array takes it, and finish() - where every command ends - releases the file it read. Found by running the suite against AddressSanitizer, which is why `make sanitizer` exists and why everything frees what it read: a process that exits in a millisecond does not need the memory back, but it does need that report to stay empty, or the one real leak hides among forty.
* A refusal names the level held on the ref in questiondev2026-11-134-20/+79
| | | | | | | | | | | | | | | | | | | | | | "carol has force on team; refs/heads/main needs force", said while refusing carol a force push to main, is a sentence nobody can act on: her force is on refs/heads/feature/*, and the message reported the strongest level she holds somewhere in the repository rather than the one she holds on the ref that was refused. scope() now records both, and the refusal uses the level that covers the ref, with a separate sentence for the case where nothing covers it at all - "a rule for team but nothing on this ref" is a different problem from "not enough for this ref", and the person pushing cannot tell them apart without reading the file the way the matcher does. Also: a policy that could not be opened is remembered (unreadable), so validate reports "every push is denied until it is mounted" instead of announcing that an empty policy is in force, and /etc/passwd is split by its seven fields rather than eight - the old loop marked the colons as the fields and so never found the git account at all, which meant a login shell for git passed validation. Both were found by driving the binary the way a receive hook is driven; that suite is in a later commit of this series.
* git-authz: one C program for who may move which refsdev2026-11-1312-0/+3371
A git host that anonymous-clones and shared-pushes has one question left to answer: which human may move which ref. This answers it from one plain file, in one binary, with no runtime beyond libc. Four modes, because they must agree exactly about what a rule means - a check that answers differently from the hook is a program that lies: check one question, for an operator or a script authorize a whole push, the way core.hooksPath hands it over: identity from GIT_HOST_USER (ssh key option) or REMOTE_USER (http auth), and one "old new ref" line per ref on stdin. Also runs as "pre-receive", which is how git finds it. validate does the policy parse, and is the host wired to run it edit grant, revoke, protect (the deployed policy is a read-only mount on purpose, so these are for the source copy and say so when told) The verdict is the exit status, since the caller is a hook: 0 allowed, 1 denied, 3 no usable policy, 64 usage. A policy that cannot be read or does not parse denies everything rather than guessing, and one bad line poisons the whole file on purpose: a mistyped rule that quietly widens access is worse than an evening of refused pushes. Semantics kept from the shell engine this replaces: levels are monotone (admin implies force implies write), rules add up rather than order, "@" is only everyone the policy already names, protected refs cost one step more than the action asked for, and refs that are neither branches nor tags are for admins. "main", "heads/main" and "refs/heads/main" are one branch; a bare name is never a tag. Two facts a push does not carry - is old an ancestor of new, and which branch HEAD points at - are asked of git, and an answer that cannot be had is taken the expensive way. tests/unit.c covers the matcher directly (173 checks); the behavioural suite that drives this the way git does follows next.