summaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authordev <dev@example>2026-11-13 19:04:50 +0000
committerdev <dev@example>2026-11-13 19:04:50 +0000
commitf87a792743227ea06cfa1580f8d30a618b4d1a04 (patch)
tree7af494393b4a316f620bab7de79b15230df2cf36 /Makefile
downloadaccess-control-f87a792743227ea06cfa1580f8d30a618b4d1a04.tar.gz
access-control-f87a792743227ea06cfa1580f8d30a618b4d1a04.zip
git-authz: one C program for who may move which refs
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.
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile66
1 files changed, 66 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..167c6ed
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,66 @@
+# git-authz - who may move which refs. C99 and libc, nothing else.
+#
+# make build ./git-authz
+# make test build, then run the unit suite and the behavioural suite
+# make install install into $(DESTDIR)$(PREFIX)
+# make clean
+#
+# No configure script, no cmake, no generated headers: the only portability
+# knob this program needs is CFLAGS. Warnings are variables so that a strict
+# build is a command line and not a build system:
+#
+# make WARN="-Wall -Wextra -Wpedantic -Werror"
+
+CC ?= cc
+PREFIX ?= /usr/local
+BINDIR ?= $(PREFIX)/bin
+SHAREDIR ?= $(PREFIX)/share/git-host
+SYSCONFDIR ?= /etc/git-host
+HOOKDIR ?= $(SHAREDIR)/hooks
+
+STD ?= -std=c99
+WARN ?= -Wall -Wextra -Wpedantic
+CFLAGS ?= -O2 -g
+CPPFLAGS += -D_POSIX_C_SOURCE=200809L
+
+PROG = git-authz
+UNIT = tests/unit
+OBJS = src/util.o src/glob.o src/policy.o src/hook.o src/validate.o src/edit.o \
+ src/main.o
+
+all: $(PROG)
+
+$(PROG): $(OBJS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS)
+
+src/%.o: src/%.c src/authz.h
+ $(CC) $(STD) $(WARN) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
+
+# The unit test links the parts it tests, not the command line, so that a
+# broken argument parser cannot hide a working matcher (or the other way round).
+$(UNIT): tests/unit.c src/util.o src/glob.o src/policy.o
+ $(CC) $(STD) $(WARN) $(CPPFLAGS) $(CFLAGS) -o $@ tests/unit.c \
+ src/util.o src/glob.o src/policy.o
+
+test: $(PROG) $(UNIT)
+ mkdir -p tests/tmp
+ $(UNIT)
+ AUTHZ=./$(PROG) sh tests/run.sh
+
+install: $(PROG)
+ install -d $(DESTDIR)$(BINDIR) $(DESTDIR)$(HOOKDIR) $(DESTDIR)$(SYSCONFDIR)
+ install -m 0755 $(PROG) $(DESTDIR)$(BINDIR)/$(PROG)
+ install -m 0644 authz.conf $(DESTDIR)$(SYSCONFDIR)/authz.conf
+ rm -f $(DESTDIR)$(HOOKDIR)/pre-receive
+ cd $(DESTDIR)$(HOOKDIR) && \
+ ln -s "`awk -v from='$(SHAREDIR)/hooks' -v to='$(BINDIR)/$(PROG)' \
+ -f build/relpath.awk`" pre-receive
+
+uninstall:
+ rm -f $(DESTDIR)$(BINDIR)/$(PROG) $(DESTDIR)$(HOOKDIR)/pre-receive
+
+clean:
+ rm -f $(OBJS) $(PROG) $(UNIT)
+ rm -rf tests/tmp
+
+.PHONY: all test install uninstall clean