diff options
| author | dev <dev@example> | 2026-11-13 22:28:22 +0000 |
|---|---|---|
| committer | dev <dev@example> | 2026-11-13 22:28:22 +0000 |
| commit | 50f296cf7609ce77d41b9fb3df51d6aeec8330d6 (patch) | |
| tree | a84e367145fa7f86f285b844144c55b3b3452cf3 /src/authz.h | |
| parent | e12fc6e1c14afaab8711c6c9ac695ce911d83df5 (diff) | |
| download | access-control-50f296cf7609ce77d41b9fb3df51d6aeec8330d6.tar.gz access-control-50f296cf7609ce77d41b9fb3df51d6aeec8330d6.zip | |
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.
Diffstat (limited to 'src/authz.h')
| -rw-r--r-- | src/authz.h | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/src/authz.h b/src/authz.h index 53f251d..794c12c 100644 --- a/src/authz.h +++ b/src/authz.h @@ -49,20 +49,14 @@ typedef struct { rule_t *rules; size_t nrules, rcap; - char *protected_global; /* space separated normalised patterns, or NULL */ - char **prot_repo; /* repositories with their own list */ - char **prot_refs; /* and the list that goes with each */ - size_t nprot, pcap; - int errors; - int warnings; int unreadable; /* the file itself could not be opened */ char *path; /* what messages call the file */ } policy_t; typedef struct { int allowed; - level_t need; /* what it cost in the end, after any raise */ + level_t need; /* what it cost in the end */ char why[512]; /* the sentence the person pushing reads */ } decision_t; @@ -83,8 +77,8 @@ void policy_init(policy_t *p, const char *path); void policy_free(policy_t *p); /* Read and parse. Returns 0 when the file is usable, -1 when it produced - * errors, -2 when it could not be read at all. Errors and warnings are - * reported as they are found, on stderr, with the line number. */ + * errors, -2 when it could not be read at all. Errors are reported as they are + * found, on stderr, with the line number. */ int policy_load(policy_t *p); /* Refs and repositories have one spelling each internally. A bare name is a @@ -115,13 +109,14 @@ int authz_level_of(const char *name); * "everybody this policy already knows about", and never invents a name. */ int authz_user_known(const policy_t *p, const char *user); -/* What a ref really costs. Anything that is not a branch or a tag is for - * maintainers; on a protected ref 'write' is not enough and 'force' is not - * enough either. When the answer is higher than 'have', the reason - * ("protected", "neither a branch nor a tag") is written to raised, which must - * hold at least 64 bytes. */ -level_t authz_need_for(const policy_t *p, const char *repo, const char *ref, - level_t have, char *raised, size_t raisedsz); +/* What a ref really costs beyond what the rule said. Anything that is not a + * branch or a tag is for maintainers, whatever a rule about it appears to + * grant: refs/notes, refs/merge-requests, whatever a tool invents next, are not + * part of the namespace a policy was written with in mind, and the safe reading + * of "not mentioned" is "not granted". When the answer is higher than 'have', + * the reason is written to raised, which must hold at least 64 bytes. */ +level_t authz_need_for(const char *ref, level_t have, char *raised, + size_t raisedsz); /* The decision. 'ref' may be NULL, which asks "may this user do this * somewhere in the repository" rather than about one ref. */ @@ -133,10 +128,6 @@ void authz_check(const policy_t *p, const char *user, const char *repo, * matching rather than a decision. */ int authz_repo_reachable(const policy_t *p, const char *repo); -/* The protected list in force for one repository, as stored (normalised - * patterns, space separated). Never NULL. */ -const char *authz_protected_for(const policy_t *p, const char *repo); - /* --------------------------------------------------------------- hook.c */ /* authorize mode: identity from the environment, ref lines from stdin, the @@ -179,7 +170,7 @@ typedef struct { const char *out; /* NULL edits in place; "-" is stdout */ } edit_opts; -/* Shared by the three editing commands: pulls --out and --stdout out of the +/* Shared by the two editing commands: pulls --out and --stdout out of the * argument list wherever they sit (an option at the end reads better in a * shell history) and compacts what is left into argv, returning the count in * *consumed. Returns -1 on a missing value. */ @@ -191,7 +182,6 @@ int authz_reject_options(int argc, char **argv); int cmd_grant(const char *path, edit_opts o, int argc, char **argv); int cmd_revoke(const char *path, edit_opts o, int argc, char **argv); -int cmd_protect(const char *path, edit_opts o, int argc, char **argv); /* ---------------------------------------------------------------- main.c * Shared little helpers, so that no file invents its own way to fail. */ |
