summaryrefslogtreecommitdiffstats
path: root/container
diff options
context:
space:
mode:
authordev <dev@example>2026-11-14 01:05:08 +0000
committerdev <dev@example>2026-11-14 01:05:08 +0000
commit312ddd4936f09ae27a180ca495cacf2c06faf33e (patch)
tree2fa46ab568ad55f7e8fb844c3447b1d296b2e340 /container
parente737f3d560de2b8172e6dd83901bc1359283303c (diff)
downloadaccess-control-312ddd4936f09ae27a180ca495cacf2c06faf33e.tar.gz
access-control-312ddd4936f09ae27a180ca495cacf2c06faf33e.zip
Comments: cut to what the code cannot say
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.
Diffstat (limited to 'container')
-rw-r--r--container/Dockerfile37
-rwxr-xr-xcontainer/create-repo13
-rwxr-xr-xcontainer/entrypoint.sh19
-rwxr-xr-xcontainer/git-host-key14
-rw-r--r--container/git-http-backend.cgi16
-rw-r--r--container/sshd_config16
6 files changed, 41 insertions, 74 deletions
diff --git a/container/Dockerfile b/container/Dockerfile
index 1828748..ac0d898 100644
--- a/container/Dockerfile
+++ b/container/Dockerfile
@@ -1,22 +1,11 @@
-# git-host on top of the C program.
-#
-# podman build -t git-host-c .
-#
-# Two stages, because the runtime image has no business carrying a compiler.
-# The build stage compiles, runs the test suite, and installs into a staging
-# root; the runtime stage copies that staging root wholesale, so the paths in
-# the image are the paths `make install` produces - including the hook symlink
-# and its relative target - rather than a second list of destinations kept here,
-# which is how an image and a build start to disagree.
-#
-# The build stage is Alpine so that git-authz is musl-linked like everything
-# else in the runtime image. A glibc binary built on the machine doing the
-# building would not run in there, and would announce itself as "no such file"
-# for a file that is plainly present.
+# podman build -t git-host-c -f container/Dockerfile .
#
-# The build context is the program's directory, with this file in container/:
+# Two stages: the runtime image carries no compiler, and copies what `make
+# install` staged, so image paths cannot drift from build paths.
#
-# podman build -t git-host-c -f container/Dockerfile .
+# The build stage is Alpine so the binary is musl-linked like the rest of the
+# image. A glibc binary reports "no such file" for a file that is plainly there.
+
FROM alpine:3.22.4 AS build
RUN apk add --no-cache build-base
@@ -26,9 +15,8 @@ COPY src ./src
COPY cmd ./cmd
COPY test ./test
COPY build ./build
-# The suite runs in the image it ships in, against the musl build: that is the
-# only place the two are guaranteed to meet, and an image built from a tree
-# whose tests fail should not exist.
+# The suite runs against the musl build, which is the only place the two meet.
+
RUN make -j2 && make test && make install DESTDIR=/install
@@ -60,16 +48,17 @@ RUN addgroup -g 1000 -S git \
/var/www/localhost/htdocs \
&& chown -R git:git /var/lib/git
-# The binary, the hook symlink beside it, and the example policy, all placed by
-# the program's own installer.
+# Placed by the program's own installer.
+
COPY --from=build /install/ /
COPY container/create-repo /usr/local/bin/create-repo
COPY container/git-host-key /usr/local/bin/git-host-key
COPY container/entrypoint.sh /usr/local/bin/entrypoint.sh
-# lighttpd's mod_cgi dispatches by extension, so /git needs a *.cgi door. It
-# only execs the stock backend, leaving REMOTE_USER for the hooks to find.
+# mod_cgi dispatches by extension, so /git needs a *.cgi door onto the stock
+# backend. It must not touch the environment: REMOTE_USER is the identity.
+
COPY container/git-http-backend.cgi /usr/local/libexec/git-http-backend.cgi
COPY container/sshd_config /etc/ssh/sshd_config
diff --git a/container/create-repo b/container/create-repo
index 3accca8..5f80c92 100755
--- a/container/create-repo
+++ b/container/create-repo
@@ -1,14 +1,9 @@
#!/bin/sh
-# create-repo - create a bare repository the policy can talk about.
+# Create a bare repository. Nothing is installed in it: every repository reaches
+# the shared hook through core.hooksPath, so one made by hand is enforced the same.
#
-# Nothing is installed here, which is the point: every repository reaches the
-# shared hook through the global core.hooksPath in /etc/gitconfig, so a bare
-# repository you make by hand is enforced exactly like one made here.
-#
-# The policy is a read-only mount in a deployment, so this cannot grant
-# anything. It prints the line to add to your policy source; until a rule
-# reaches the new repository, 'git-authz validate' says so and every push to it
-# is refused.
+# The policy is a read-only mount, so this only prints the line to add.
+
set -eu
GIT_REPO_ROOT="${GIT_REPO_ROOT:-/var/lib/git}"
diff --git a/container/entrypoint.sh b/container/entrypoint.sh
index e82ae4f..df33b47 100755
--- a/container/entrypoint.sh
+++ b/container/entrypoint.sh
@@ -16,9 +16,9 @@ need_secret() { # <name> [mode] [owner-group]
chmod "$mode" "$SECRETS_DIR/$name"
}
-# Copy the secrets to /run and fix their modes. Mounted secrets arrive with
-# whatever mode the volume plugin chose, and sshd refuses keys that are too
-# loose while lighttpd must be able to read htpasswd as the git user.
+# Mounted secrets arrive with whatever mode the volume plugin chose. sshd refuses
+# keys that are too loose; lighttpd must read htpasswd as the git user.
+
mkdir -p "$SECRETS_DIR"
need_secret authorized_keys 0640 git
need_secret htpasswd 0640 git
@@ -28,15 +28,14 @@ need_secret ssh_host_rsa_key
need_secret ssh_host_rsa_key.pub 0644
chmod 0755 /run/git-host "$SECRETS_DIR"
-# One hook for every repository. This is the single most important line in the
-# container: without it a repository carries no policy and pushes go unchecked.
-# The policy file itself stays wherever it is mounted; it is never copied, so a
-# ConfigMap update takes effect on the next push with no restart.
+# The single most important line in the container: without it a repository carries
+# no policy and pushes go unchecked. The policy is never copied, so a ConfigMap
+# update takes effect on the next push.
+
git config --file /etc/gitconfig core.hooksPath "${GIT_HOST_HOOK_DIR:-/usr/local/share/git-host/hooks}"
-# Fail rather than serve a host that cannot enforce anything. A policy that
-# does not parse is only a warning inside validate: reads keep working and
-# pushes are denied, which is the correct direction for a mistake to fall in.
+# Do not serve a host that cannot enforce anything.
+
git-authz validate
/usr/sbin/sshd -D -e -f /etc/ssh/sshd_config &
diff --git a/container/git-host-key b/container/git-host-key
index a7fdfc8..10d8131 100755
--- a/container/git-host-key
+++ b/container/git-host-key
@@ -1,17 +1,11 @@
#!/bin/sh
-# git-host-key - ssh public keys that carry their own identity.
-#
-# sshd only knows the OS account, and every git user shares the single 'git'
-# account. So identity is written into the key's option list:
+# ssh public keys that carry their own identity. sshd only knows the OS account,
+# which every user shares, so identity goes in the key's option list:
#
# command="/usr/bin/git-shell",...,environment="GIT_HOST_USER=alice"
#
-# sshd puts that into the session environment (sshd_config needs
-# PermitUserEnvironment yes), git-receive-pack inherits it, and the pre-receive
-# hook authorises the push from it. A key without the option is anonymous as
-# far as policy is concerned, so its pushes are denied. 'git-authz validate'
-# reports keys with no identity, keys that pin something other than git-shell,
-# and identities the policy has never heard of.
+# A key without it is anonymous to the policy and every push with it is denied.
+
set -eu
KEYS="${GIT_HOST_AUTHORIZED_KEYS:-/etc/git-host/secrets/authorized_keys}"
diff --git a/container/git-http-backend.cgi b/container/git-http-backend.cgi
index e086525..c69758b 100644
--- a/container/git-http-backend.cgi
+++ b/container/git-http-backend.cgi
@@ -1,17 +1,9 @@
#!/bin/sh
-# git-http-backend.cgi - a .cgi-named door to the stock git-http-backend.
+# A .cgi-named door onto the stock backend, because mod_cgi dispatches by
+# extension. No policy in here: writes are decided by the pre-receive hook.
#
-# There is no policy in here. Reads are open, and writes are decided by the
-# global pre-receive hook, which is a symlink to git-authz and is reached by
-# every repository through core.hooksPath in /etc/gitconfig.
-#
-# This file exists for one reason: lighttpd's mod_cgi dispatches by extension,
-# and the alias in lighttpd.conf needs something named *.cgi in front of it.
-#
-# REMOTE_USER is set by mod_auth on push requests (auth.conf) and the receive
-# hooks authorise the push from it, so this script must stay a plain exec:
-# unsetting or rewriting the environment here turns every push into "no
-# identity" and denies them all.
+# It must stay a plain exec. REMOTE_USER is the identity the hooks authorise
+# from, and rewriting the environment here denies every push.
set -eu
BACKEND="${GIT_HOST_HTTP_BACKEND:-/usr/libexec/git-core/git-http-backend}"
diff --git a/container/sshd_config b/container/sshd_config
index c180f50..fca7e7b 100644
--- a/container/sshd_config
+++ b/container/sshd_config
@@ -4,22 +4,20 @@ HostKey /run/git-host/secrets/ssh_host_ed25519_key
HostKey /run/git-host/secrets/ssh_host_rsa_key
PidFile /run/sshd/sshd.pid
-# One OS account for everyone; the *name* behind a key comes from the key
-# itself. git-host-key writes
+# One OS account for everyone; the name behind a key comes from the key itself:
#
# environment="GIT_HOST_USER=alice",command="/usr/bin/git-shell",... ssh-ed25519 ...
-#
-# and git-authz reads GIT_HOST_USER out of the push environment.
+
AuthorizedKeysFile /run/git-host/secrets/authorized_keys
-# Without this line sshd silently drops the environment= key option, every
-# connection arrives anonymous, and every push is denied. The usual objection
-# does not apply here: the git account has no login shell worth having
+# Without this sshd silently drops the environment= option and every push arrives
+# anonymous. The usual objection does not apply: there is no login shell here
# (ForceCommand below), no writable files and no user rc file.
+
PermitUserEnvironment yes
-# Belt and braces for a hand-added key that forgot its command= option: nobody
-# gets a shell, only the git transport.
+# For a hand-added key that forgot its command= option: git transport, no shell.
+
ForceCommand /usr/bin/git-shell
PasswordAuthentication no