| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
option() in hook.c and one_option() in cmd/main.c were the same function
under two names, and validate's seven options were a chain of seven calls
to one of them. getopt_long does all of it - both --opt value and
--opt=value, the lot - so the parsers are gone and what is left is a table
and what each entry sets.
Two small helpers carry what getopt_long cannot: the name behind a long
option's val, for the 'wants a value' message, and the optind reset that
lets a run parse options twice on two different argv slices.
A command now gets argv[0] as its own name, which is where getopt_long
expects argv[0]; the commands that take names step over it.
strip() in validate.c was authz_trim() again, and cmd_authorize freed the
same three pointers on four exit paths.
One behaviour change: 'authorize --' is now the end-of-options marker
rather than an unknown argument. Anything after it is still refused.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Every one was found by reading a module against what the program promises, or by
driving the built binary with input the suite never sends. None of them was
visible from a green run: the run was already green.
Two are validate saying "ok" about a machine that is wide open:
ForceCommand none is how a Match block turns a forced command back off. It
is the same state as having none at all, which is the
state this check exists to catch.
sshd directives sshd keeps the first value it reads for a keyword, not the
last. "PermitUserEnvironment no" with a later "yes" read
as yes, and every push arrives anonymous.
One is a grant that grants more than was typed. A ref argument went into the
file verbatim, so
grant x team write 'refs/heads/a b'
landed as "x team write refs/heads/a b", which reads back as two patterns and
quietly grants refs/heads/b as well. A '#' argument was cut short at the comment
marker, and a newline argument wrote a file that no longer parses - which denies
every push there is. An argument that is not one field is refused now.
authorize did not accept the options its own usage text prints. The help says
"--user U" and "--ff auto|yes|no"; the parser took only --user=U, so the
documented spelling came back "unknown argument" while validate accepted both
forms. Both work now, and an option with no value says so.
Three are the boundary and status distinctions the exit codes are made of. A
rule with exactly MAX_FIELDS fields was refused as "too many", and a file that
does not parse denies every push. A directory passed as the policy read as a
policy that happens to be empty, so every push answered 1, person not allowed,
where the host is broken and the answer has to be 3. A gitconfig section name
was matched case-sensitively, so [CORE] reported a broken host that is not
broken; git folds section names without regard to case.
Two are smaller. "appended as line N" was printed when the pair's rule was the
last line and had been replaced rather than appended. And the Makefile tracked
no header dependencies, so editing src/authz.h rebuilt nothing and make test
passed against a binary that was not the code on disk.
Each fix went in as a failing test first, so the suite goes from 162 cases to
176 and no existing test was changed. Clean under -Werror and clean under
ASan/UBSan.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The comments had grown into essays. A file header explaining why the file
exists, then a paragraph above each function restating what the next eight
lines do, then a paragraph above that one explaining why that matters. The
reader gets no further than the first paragraph, and the second is the one that
goes stale: it describes code that has since changed, and nothing fails when it
does.
Cut by about half. What is left is the three things a comment can do that code
cannot: say why the constraint exists (no regex because a hook must not depend
on what might be missing at 3am), say what is not obvious from the shape (a
bare ref name is a branch, never a tag; the seventh field of /etc/passwd is the
shell), and say where it hurts (the NULL in an execvp array, the mode and owner
that have to survive an atomic rewrite, the child that must not keep the hook's
stdin).
Block comments became // lines, which is also what the other C trees here use,
and the file headers went to two or three lines. Section banners stayed: they
are navigation, not prose.
Behaviour is unchanged and the suites prove it: 171 direct checks, 162
behavioural, clean under -Werror and under ASan/UBSan.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
`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.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
"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.
|
|
|
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.
|