diff options
| author | dev <dev@example> | 2026-11-13 21:32:38 +0000 |
|---|---|---|
| committer | dev <dev@example> | 2026-11-13 21:32:38 +0000 |
| commit | 47c9b98ea3fb91833d6d0847fa4345fa23593a97 (patch) | |
| tree | 3b68994aa774e9b758f8cb2296770a49adef87d7 /container/entrypoint.sh | |
| parent | 2b53cf54acd3d84bd6edfd0b98cf58794e30ec7d (diff) | |
| download | access-control-47c9b98ea3fb91833d6d0847fa4345fa23593a97.tar.gz access-control-47c9b98ea3fb91833d6d0847fa4345fa23593a97.zip | |
container: the host, built from the program's own install
The image is two stages: one compiles, runs the suite and installs into a
staging root, the other is the host and receives that staging root whole. The
reason for the copy-whole is that the paths in the image are then the paths
`make install` produces - including the hook symlink and its relative target -
rather than a second list of destinations kept in a Dockerfile, which is how an
image and a build start to disagree about where the hook is.
The build stage is Alpine so the binary is musl-linked like the rest of the
runtime image; a glibc binary would fail as "no such file" about a file that is
plainly there. `make test` runs in that stage, so an image built from a tree
whose tests fail does not get to exist.
The lighttpd config, sshd config, CGI shim, cgitrc and the two operator tools
come from the shell implementation, with the comments corrected: there is no
refcheck any more, and the hook the comments point at is now a symlink to this
binary. Nothing about the wiring changed, which is the point - the C program
drops into a host that was already built around one hook and one policy file.
Diffstat (limited to 'container/entrypoint.sh')
| -rwxr-xr-x | container/entrypoint.sh | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/container/entrypoint.sh b/container/entrypoint.sh new file mode 100755 index 0000000..e82ae4f --- /dev/null +++ b/container/entrypoint.sh @@ -0,0 +1,59 @@ +#!/bin/sh +set -Eeuo pipefail + +SECRETS_SRC=/etc/git-host/secrets +SECRETS_DIR=/run/git-host/secrets + +need_secret() { # <name> [mode] [owner-group] + name="$1"; mode="${2:-0600}"; group="${3:-root}" + if [ ! -r "$SECRETS_SRC/$name" ]; then + printf 'entrypoint: missing secret %s\n' "$SECRETS_SRC/$name" >&2 + printf 'entrypoint: mount it there (a Kubernetes Secret works as-is)\n' >&2 + exit 1 + fi + cp "$SECRETS_SRC/$name" "$SECRETS_DIR/$name" + chown "root:$group" "$SECRETS_DIR/$name" + 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. +mkdir -p "$SECRETS_DIR" +need_secret authorized_keys 0640 git +need_secret htpasswd 0640 git +need_secret ssh_host_ed25519_key +need_secret ssh_host_ed25519_key.pub 0644 +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. +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. +git-authz validate + +/usr/sbin/sshd -D -e -f /etc/ssh/sshd_config & +sshd_pid=$! + +lighttpd -D -f /etc/lighttpd/lighttpd.conf & +lighttpd_pid=$! + +terminate() { + kill "${sshd_pid}" "${lighttpd_pid}" 2>/dev/null || true +} + +trap terminate INT TERM + +status=0 +wait -n "${sshd_pid}" "${lighttpd_pid}" || status=$? +terminate +wait "${sshd_pid}" 2>/dev/null || true +wait "${lighttpd_pid}" 2>/dev/null || true +exit "${status}" |
