diff options
| author | dev <dev@example> | 2026-11-15 11:28:47 +0000 |
|---|---|---|
| committer | dev <dev@example> | 2026-11-15 11:28:47 +0000 |
| commit | c2b95afc6aefbab69133a202cab95a50a2df82fc (patch) | |
| tree | 4788b1b9302ef77b244c4107de2f3da15982f303 /src/authz.h | |
| parent | 5a9afae082f36812a2e7c9e61d8662628b798f41 (diff) | |
| download | access-control-c2b95afc6aefbab69133a202cab95a50a2df82fc.tar.gz access-control-c2b95afc6aefbab69133a202cab95a50a2df82fc.zip | |
Drop grant/revoke and validate's host-wiring checks
Two features out, to answer a size target: src/ and cmd/ go from 2,306
non-blank lines to 1,495.
`grant` and `revoke` were a convenience wrapper over a file that is a
read-only mount in production by design, so they sat outside the
enforcement path. src/edit.c is gone; both names now report an unknown
command with exit 64.
`validate` keeps the policy checks - parse errors with their line
numbers, an unreadable policy, the @all-whole-repo and not-readable-by-
the-git-account warnings - and stops cross-checking the machine around
it. The repository cross-check, hook/hooksPath, sshd, the git account's
shell and the key/htpasswd identity checks are deleted, along with
--root, --hook-dir, --gitconfig, --sshd-config, --passwd, --keys,
--htpasswd and --no-host; plain `validate` is what `validate --no-host`
used to be. The container's build gate and the test suite are updated to
match, since both called the removed flag.
Orphaned by the removals and deleted with them: authz_repo_reachable,
and authz_rule_validate's ref_ok parameter, which existed only so grant
could interleave its own ref-pattern test.
Surviving behaviour is unchanged. A 1,370-invocation differential run
against the pre-removal binary - the check matrix, every authorize path,
the hook reached through its own name, fake-git ancestry and HEAD,
policy-only validate, the failure modes - differs only in the usage text
that documented the removed surface. make strict, make test and
make sanitizer are all clean, with ASan and UBSan silent.
Also folded in from the same effort, since it touched the same files:
authz_rule_validate as the single grammar, rule_covers() as the single
answer for rule/ref coverage, vmsgv() behind the validate message tags,
one kv reader for gitconfig and sshd_config while both were still there,
and `sanitizer:` in the Makefile appending to CFLAGS rather than
replacing it.
Diffstat (limited to 'src/authz.h')
| -rw-r--r-- | src/authz.h | 52 |
1 files changed, 21 insertions, 31 deletions
diff --git a/src/authz.h b/src/authz.h index d107fd8..ad39b35 100644 --- a/src/authz.h +++ b/src/authz.h @@ -10,7 +10,10 @@ #include <getopt.h> #include <stddef.h> -#define MAX_FIELDS 64 // one rule line, split on whitespace // one rule line, split on whitespace +#define MAX_FIELDS 64 // one rule line, split on whitespace +#define AUTHZ_MSGSZ 512 // one complaint, in the words the caller prints +#define DEFAULT_ROOT "/var/lib/git" // where the repositories live; the hook + // derives a repo name from this too typedef enum { LV_NONE = 0, @@ -67,6 +70,9 @@ char *authz_norm_ref(const char *in); char *authz_trim(char *s); +// A policy line's body: trimmed, comment and all after it gone. Edits the line. +char *authz_line_body(char *line); + // More than 'max' fields returns max+1, so the caller complains rather than // reading past the array. int authz_split_ws(char *line, char **fields, int max); @@ -83,6 +89,14 @@ int authz_level_of(const char *name); // -1 for anything that is not one // '@all' means everybody this policy already names; it never invents a name. int authz_user_known(const policy_t *p, const char *user); +// The grammar, in one place: check and the file parser must refuse the same +// lines for the same reason, because a rule the parser rejects denies every push +// in the repository. Fills msg with the complaint in the words the caller +// prints; returns 0 when the fields parse. A NULL user or repo is a field the +// caller is not asking about. +int authz_rule_validate(const char *user, const char *repo, const char *level, + char *const *refs, int nrefs, char *msg, size_t msgs); + // What a ref costs beyond what the rule said. Neither a branch nor a tag is // admin whatever a rule grants - refs/notes, refs/merge-requests, whatever a tool // invents next. The reason goes in raised (>= 64 bytes). @@ -95,10 +109,6 @@ level_t authz_need_for(const char *ref, level_t have, char *raised, void authz_check(const policy_t *p, const char *user, const char *repo, level_t need, const char *ref, decision_t *out); -// False means no rule reaches it at all - usually a name that stopped matching. - -int authz_repo_reachable(const policy_t *p, const char *repo); - // hook.c -------------------------------------------------------------------- // authorize mode: identity from the environment, "old new ref" on stdin, the @@ -121,35 +131,11 @@ int cmd_authorize(const policy_t *p, hook_opts o, int argc, char **argv); // validate.c ---------------------------------------------------------------- typedef struct { - const char *root; // where the repositories live - const char *hook_dir; - const char *gitconfig; - const char *sshd_config; - const char *passwd; - const char *keys; - const char *htpasswd; int strict; // warnings are errors } validate_opts; int cmd_validate(const policy_t *p, validate_opts o); -// edit.c -------------------------------------------------------------------- - -typedef struct { - const char *out; // NULL edits in place; "-" is stdout -} edit_opts; - -// Pulls --out and --stdout out of argv wherever they sit and compacts what is -// left, returning the count in *consumed. -1 on a missing value. -int authz_parse_out(int argc, char **argv, edit_opts *o, int *consumed); - -// A name starting with "--" is a mistyped option, not something to grant. -// Prints and returns 1 when it finds one. -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); - // util.c -------------------------------------------------------------------- // A growing string. strncat with hand-computed room is how buffer bugs are @@ -174,8 +160,8 @@ void lines_free(lines_t *l); // 0, -1 when the file cannot be opened, or -2 when reading stopped before the // end - a directory, an I/O error halfway, a mount pulled out. errno says which. -// The caller decides what a missing file means: an emergency for the policy, a -// plain fact for a validator cross-checking a host. +// The caller decides what a missing file means: an emergency for the policy, +// nothing at all for a file that is optional here. int authz_read_lines(const char *path, lines_t *l); void sb_init(strbuf_t *b); @@ -202,4 +188,8 @@ const char *authz_optname(int val, const struct option *lo); void authz_opt_reset(void); +// The two complaints every getopt_long loop would otherwise write by hand. +void authz_opt_need_value(const struct option *lo); +void authz_opt_unknown(const char *cmd, const char *arg); + #endif /* AUTHZ_H */ |
