<feed xmlns='http://www.w3.org/2005/Atom'>
<title>access-control/tests, branch main</title>
<subtitle>Unnamed repository
</subtitle>
<link rel='alternate' type='text/html' href='http://git.jnsn.dev/cgit/access-control/'/>
<entry>
<title>Layout: cmd/, src/, test/, everything built into obj/</title>
<updated>2026-11-14T00:06:35+00:00</updated>
<author>
<name>dev</name>
<email>dev@example</email>
</author>
<published>2026-11-14T00:06:35+00:00</published>
<link rel='alternate' type='text/html' href='http://git.jnsn.dev/cgit/access-control/commit/?id=bc7f4da406fbd802b08985ba583e52f040bdba85'/>
<id>bc7f4da406fbd802b08985ba583e52f040bdba85</id>
<content type='text'>
The tree had grown sideways: main.c living among the sources it dispatches to,
one test binary covering everything, object files left in the source directory
because the Makefile put them there and, worse, tracked them.

Now the command line is cmd/main.c, the engine is src/ and nothing in it knows
about the command line, and each area of the engine has its own program under
test/ - glob, norm, parse, need, check - each linking the library and reporting
its own count.  A failure says which area broke instead of taking the whole run
down with a single "unit: 171" line, which is the only thing a per-file split
buys and it is worth the small duplication the shared test.h absorbs.

Objects go to obj/, test runners to obj/test_runner/, so a build leaves the
tree as it found it.  The stale src/*.o and tests/unit that were committed
earlier are gone; they were build output in a source tree and the .gitignore
that should have stopped them arrived after they did.

The Makefile follows the same shape as the other C trees here: directories in
variables, wildcards for the sources, one pattern rule that makes its own
directory, test runners built from the same objects as the binary so they
cannot test a different build than ships, and `test` running every runner with
a foreach so the first failure stops the line.  `strict` is `all` with -Werror,
which is what CI now calls instead of passing CFLAGS in from outside; the
sanitizer and install targets are unchanged in what they do.

Behaviour is unchanged: 171 direct checks and 154 behavioural ones, same as
before the move, and make install still stages a working hook symlink.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The tree had grown sideways: main.c living among the sources it dispatches to,
one test binary covering everything, object files left in the source directory
because the Makefile put them there and, worse, tracked them.

Now the command line is cmd/main.c, the engine is src/ and nothing in it knows
about the command line, and each area of the engine has its own program under
test/ - glob, norm, parse, need, check - each linking the library and reporting
its own count.  A failure says which area broke instead of taking the whole run
down with a single "unit: 171" line, which is the only thing a per-file split
buys and it is worth the small duplication the shared test.h absorbs.

Objects go to obj/, test runners to obj/test_runner/, so a build leaves the
tree as it found it.  The stale src/*.o and tests/unit that were committed
earlier are gone; they were build output in a source tree and the .gitignore
that should have stopped them arrived after they did.

The Makefile follows the same shape as the other C trees here: directories in
variables, wildcards for the sources, one pattern rule that makes its own
directory, test runners built from the same objects as the binary so they
cannot test a different build than ships, and `test` running every runner with
a foreach so the first failure stops the line.  `strict` is `all` with -Werror,
which is what CI now calls instead of passing CFLAGS in from outside; the
sanitizer and install targets are unchanged in what they do.

Behaviour is unchanged: 171 direct checks and 154 behavioural ones, same as
before the move, and make install still stages a working hook symlink.
</pre>
</div>
</content>
</entry>
<entry>
<title>Remove protected-refs: a rule covers what it names, and nothing else</title>
<updated>2026-11-13T22:28:22+00:00</updated>
<author>
<name>dev</name>
<email>dev@example</email>
</author>
<published>2026-11-13T22:28:22+00:00</published>
<link rel='alternate' type='text/html' href='http://git.jnsn.dev/cgit/access-control/commit/?id=50f296cf7609ce77d41b9fb3df51d6aeec8330d6'/>
<id>50f296cf7609ce77d41b9fb3df51d6aeec8330d6</id>
<content type='text'>
`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.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
`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.
</pre>
</div>
</content>
</entry>
<entry>
<title>tests: drive the binary the way a hook is driven</title>
<updated>2026-11-13T20:34:47+00:00</updated>
<author>
<name>dev</name>
<email>dev@example</email>
</author>
<published>2026-11-13T20:34:47+00:00</published>
<link rel='alternate' type='text/html' href='http://git.jnsn.dev/cgit/access-control/commit/?id=23b41dd208ca16712470a18c1f42d4f22f364f9e'/>
<id>23b41dd208ca16712470a18c1f42d4f22f364f9e</id>
<content type='text'>
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.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
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.
</pre>
</div>
</content>
</entry>
<entry>
<title>A refusal names the level held on the ref in question</title>
<updated>2026-11-13T20:34:17+00:00</updated>
<author>
<name>dev</name>
<email>dev@example</email>
</author>
<published>2026-11-13T20:33:51+00:00</published>
<link rel='alternate' type='text/html' href='http://git.jnsn.dev/cgit/access-control/commit/?id=1fd64267f678b8c6d17b2bcae702d577df1fc9e4'/>
<id>1fd64267f678b8c6d17b2bcae702d577df1fc9e4</id>
<content type='text'>
"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.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
"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.
</pre>
</div>
</content>
</entry>
<entry>
<title>git-authz: one C program for who may move which refs</title>
<updated>2026-11-13T19:04:50+00:00</updated>
<author>
<name>dev</name>
<email>dev@example</email>
</author>
<published>2026-11-13T19:04:50+00:00</published>
<link rel='alternate' type='text/html' href='http://git.jnsn.dev/cgit/access-control/commit/?id=f87a792743227ea06cfa1580f8d30a618b4d1a04'/>
<id>f87a792743227ea06cfa1580f8d30a618b4d1a04</id>
<content type='text'>
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.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
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.
</pre>
</div>
</content>
</entry>
</feed>
