diff options
| author | delusionalai <delusionalai@jnsn.dev> | 2026-11-15 13:54:36 +0000 |
|---|---|---|
| committer | delusionalai <delusionalai@jnsn.dev> | 2026-11-15 13:54:36 +0000 |
| commit | ed62c4ccf06c2c85d871a6334e3e0d82c6e4257a (patch) | |
| tree | 69897b0d2be0fab353fa4bac3bbe9cb14171da24 /entrypoint.sh | |
| parent | cad3e5f4dff0c77c8eed020308c5bf8ffbff5964 (diff) | |
| download | git-host-ed62c4ccf06c2c85d871a6334e3e0d82c6e4257a.tar.gz git-host-ed62c4ccf06c2c85d871a6334e3e0d82c6e4257a.zip | |
The host, built around the access control executable
git-host is now the single home of the git repo configuration. The Dockerfile
grew a build stage that installs git-authz from its own repository (the
access-control / git-host-c project) via `make install`, so the image carries
the executable, its example policy and the pre-receive hook symlink, all placed
by the program's own installer rather than copied by hand.
The server configuration is the git-authz-aware set that used to live beside the
program: the entrypoint sets core.hooksPath and refuses to serve on a policy the
hook cannot use, sshd carries PermitUserEnvironment and ForceCommand so a key's
identity survives to the hook, create-repo prints the policy line to add, and
git-host-key manages keys that name their user. cgitrc keeps the corrected
ordering (repo-scoped settings above scan-path).
Diffstat (limited to 'entrypoint.sh')
| -rw-r--r-- | entrypoint.sh | 66 |
1 files changed, 37 insertions, 29 deletions
diff --git a/entrypoint.sh b/entrypoint.sh index 3737a7e..df33b47 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,41 +1,49 @@ #!/bin/sh set -Eeuo pipefail -# Copy over the secrets to fix permissions -mkdir -p /run/git-host/secrets -cp /etc/git-host/secrets/authorized_keys /run/git-host/secrets/authorized_keys -cp /etc/git-host/secrets/htpasswd /run/git-host/secrets/htpasswd -cp /etc/git-host/secrets/ssh_host_ed25519_key /run/git-host/secrets/ssh_host_ed25519_key -cp /etc/git-host/secrets/ssh_host_ed25519_key.pub /run/git-host/secrets/ssh_host_ed25519_key.pub -cp /etc/git-host/secrets/ssh_host_rsa_key /run/git-host/secrets/ssh_host_rsa_key -cp /etc/git-host/secrets/ssh_host_rsa_key.pub /run/git-host/secrets/ssh_host_rsa_key.pub -chown -R root:root /run/git-host/secrets -chown root:git /run/git-host/secrets/authorized_keys -chown root:git /run/git-host/secrets/htpasswd -chown root:root /run/git-host/secrets/ssh_host_ed25519_key -chown root:root /run/git-host/secrets/ssh_host_ed25519_key.pub -chown root:root /run/git-host/secrets/ssh_host_rsa_key -chown root:root /run/git-host/secrets/ssh_host_rsa_key.pub -chmod 0755 /run/git-host /run/git-host/secrets -chmod 0640 /run/git-host/secrets/authorized_keys -chmod 0640 /run/git-host/secrets/htpasswd -chmod 0600 /run/git-host/secrets/ssh_host_ed25519_key -chmod 0644 /run/git-host/secrets/ssh_host_ed25519_key.pub -chmod 0600 /run/git-host/secrets/ssh_host_rsa_key -chmod 0644 /run/git-host/secrets/ssh_host_rsa_key.pub - -# Validate -/usr/sbin/sshd -t -f /etc/ssh/sshd_config -lighttpd -tt -f /etc/lighttpd/lighttpd.conf - -# Start servers +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" +} + +# 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 +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" + +# 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}" + +# Do not serve a host that cannot enforce anything. + +git-authz validate + /usr/sbin/sshd -D -e -f /etc/ssh/sshd_config & sshd_pid=$! lighttpd -D -f /etc/lighttpd/lighttpd.conf & lighttpd_pid=$! -# Wait for them to end, kill if either does terminate() { kill "${sshd_pid}" "${lighttpd_pid}" 2>/dev/null || true } |
