diff options
| -rw-r--r-- | .dockerignore | 5 | ||||
| -rw-r--r-- | ci/build.yaml | 88 | ||||
| -rw-r--r-- | container/Dockerfile | 96 | ||||
| -rw-r--r-- | container/auth.conf | 10 | ||||
| -rw-r--r-- | container/cgitrc | 18 | ||||
| -rwxr-xr-x | container/create-repo | 60 | ||||
| -rwxr-xr-x | container/entrypoint.sh | 59 | ||||
| -rwxr-xr-x | container/git-host-key | 186 | ||||
| -rw-r--r-- | container/git-http-backend.cgi | 20 | ||||
| -rw-r--r-- | container/healthz | 1 | ||||
| -rw-r--r-- | container/lighttpd.conf | 43 | ||||
| -rw-r--r-- | container/sshd_config | 35 |
12 files changed, 621 insertions, 0 deletions
diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6a3c2a0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +# Build artifacts. An object file or a test binary built on the machine doing the building is the wrong libc for the image, and the failure it produces is "no such file" for a file that is plainly there. +*.o +/git-authz +/tests/unit +/tests/tmp/ diff --git a/ci/build.yaml b/ci/build.yaml new file mode 100644 index 0000000..e8db98c --- /dev/null +++ b/ci/build.yaml @@ -0,0 +1,88 @@ +resources: +- name: repo + type: git + source: + uri: ssh://git@git.jnsn.dev:52502/~/git-host-c.git + branch: main + private_key: ((vbump.repo-key)) +- name: final-image + type: registry-image + icon: docker + source: + repository: registry.jnsn.dev/git-host-c + username: ((vbump.username)) + password: ((vbump.password)) + tag: latest + +jobs: +- name: update-pipeline + plan: + - get: repo + trigger: true + - set_pipeline: self + file: repo/ci/build.yaml + +# The whole point of a C rewrite was to have one binary with no moving parts, so +# the gate is: compile it under the strictest warnings the compiler has, run the +# unit suite and the behavioural suite, and run both again under the sanitizers. +# Alpine, because that is the libc the image is built against - a suite that +# passes against glibc and segfaults on musl has told us nothing. +# +# The container suite (../git-host-integration) is deliberately not here: it +# needs a container runtime inside the build, and a suite that fails because the +# sandbox cannot mount an overlay is not a signal about the policy. +- name: test + plan: + - get: repo + trigger: true + - task: build-and-test + config: + platform: linux + image_resource: + type: registry-image + source: + repository: alpine + tag: "3.22" + inputs: + - name: repo + run: + path: sh + args: + - -ec + - | + apk add --no-cache build-base git >/dev/null + cd repo + make clean + make WARN="-Wall -Wextra -Wpedantic -Werror" 2>&1 | tail -3 + make test | tail -1 + make clean + make sanitizer | tail -1 + printf 'install: ' + make install DESTDIR=/tmp/stage >/dev/null && \ + readlink /tmp/stage/usr/local/share/git-host/hooks/pre-receive + +- name: build-container + plan: + - get: repo + trigger: true + passed: [test] + privileged: true + config: + platform: linux + image_resource: + type: registry-image + source: + repository: concourse/oci-build-task + inputs: + - name: repo + outputs: + - name: image + params: + CONTEXT: repo + DOCKERFILE: repo/container/Dockerfile + UNPACK_ROOTFS: "true" + run: + path: build + - put: final-image + params: + image: image/image.tar diff --git a/container/Dockerfile b/container/Dockerfile new file mode 100644 index 0000000..e73ed34 --- /dev/null +++ b/container/Dockerfile @@ -0,0 +1,96 @@ +# 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. +# +# The build context is the program's directory, with this file in container/: +# +# podman build -t git-host-c -f container/Dockerfile . + +FROM alpine:3.22.4 AS build +RUN apk add --no-cache build-base +WORKDIR /src +COPY Makefile README authz.conf ./ +COPY src ./src +COPY build ./build +COPY tests ./tests +# 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. +RUN make -j2 && make test && make install DESTDIR=/install + + +FROM alpine:3.22.4 + +# git-daemon is not a typo: it is the package that ships git-http-backend and +# git-shell. +RUN apk add --no-cache \ + cgit \ + git \ + git-daemon \ + lighttpd \ + lighttpd-mod_auth \ + openssh-server \ + tini + +RUN addgroup -g 1000 -S git \ + && adduser -u 1000 -S -D -G git -h /var/lib/git -s /usr/bin/git-shell git \ + && adduser git tty \ + && passwd -u git \ + && mkdir -p \ + /etc/git-host/secrets \ + /usr/local/libexec \ + /var/lib/git \ + /run/git-host/secrets \ + /run/lighttpd \ + /run/sshd \ + /var/tmp/lighttpd \ + /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. +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. +COPY container/git-http-backend.cgi /usr/local/libexec/git-http-backend.cgi + +COPY container/sshd_config /etc/ssh/sshd_config +COPY container/cgitrc /etc/cgitrc +COPY container/lighttpd.conf /etc/lighttpd/lighttpd.conf +COPY container/auth.conf /etc/lighttpd/auth.conf +COPY container/healthz /var/www/localhost/htdocs/healthz + +RUN chmod 0755 \ + /usr/local/bin/entrypoint.sh \ + /usr/local/bin/git-host-key \ + /usr/local/bin/create-repo \ + /usr/local/libexec/git-http-backend.cgi \ + && chmod 0644 /etc/git-host/authz.conf \ + && chown git:git /var/lib/git /run/lighttpd /var/tmp/lighttpd /var/www/localhost/htdocs \ + && chmod 0755 /run/git-host /run/git-host/secrets \ + && git config --file /etc/gitconfig core.hooksPath /usr/local/share/git-host/hooks \ + && grep -q "^git:" /etc/passwd \ + && lighttpd -tt -f /etc/lighttpd/lighttpd.conf \ + && /usr/local/bin/git-authz validate --no-host + +EXPOSE 8080 2222 +VOLUME ["/var/lib/git"] + +ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/entrypoint.sh"] diff --git a/container/auth.conf b/container/auth.conf new file mode 100644 index 0000000..39c7550 --- /dev/null +++ b/container/auth.conf @@ -0,0 +1,10 @@ +auth.backend = "htpasswd" +auth.backend.htpasswd.userfile = "/run/git-host/secrets/htpasswd" + +$HTTP["querystring"] =~ "(^|&)service=git-receive-pack(&|$)" { + auth.require = ("" => ("method" => "basic", "realm" => "Git Host", "require" => "valid-user")) +} + +$HTTP["url"] =~ "^/git/.*/git-receive-pack$" { + auth.require = ("" => ("method" => "basic", "realm" => "Git Host", "require" => "valid-user")) +} diff --git a/container/cgitrc b/container/cgitrc new file mode 100644 index 0000000..cd70b52 --- /dev/null +++ b/container/cgitrc @@ -0,0 +1,18 @@ +css=/cgit.css +logo=/cgit.png +favicon=/favicon.ico +scan-path=/var/lib/git +remove-suffix=1 +enable-http-clone=1 +snapshots=tar.gz zip +root-title=Repositories +root-desc=Simple Git host +section-from-path=1 +clone-url=ssh://git@$HTTP_HOST:$CGIT_REPO_URL +about-filter=/usr/lib/cgit/filters/about-formatting.sh +enable-log-filecount=1 +enable-log-linecount=1 +enable-commit-graph=1 +max-stats=quarter +virtual-root=/cgit/ +mimetype-file=/etc/mime.types diff --git a/container/create-repo b/container/create-repo new file mode 100755 index 0000000..3accca8 --- /dev/null +++ b/container/create-repo @@ -0,0 +1,60 @@ +#!/bin/sh +# create-repo - create a bare repository the policy can talk about. +# +# 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. +set -eu + +GIT_REPO_ROOT="${GIT_REPO_ROOT:-/var/lib/git}" +GIT_USER="${GIT_USER:-git}" +GIT_GROUP="${GIT_GROUP:-git}" +DEFAULT_BRANCH="${GIT_HOST_DEFAULT_BRANCH:-main}" + +usage() { + cat >&2 <<USAGE +usage: create-repo <name> [description] + +Creates $GIT_REPO_ROOT/<name>.git - bare, owned by $GIT_USER, HEAD at +refs/heads/$DEFAULT_BRANCH - and prints the policy line to add. +USAGE + exit 64 +} + +[ "$#" -ge 1 ] || usage + +name="$1" +description="${2:-Unnamed repository}" + +case "${name}" in + */* | .* | *" "* | *".."* ) + printf 'invalid repository name: %s\n' "${name}" >&2 + exit 64 + ;; +esac + +case "${name}" in + *.git) repo_name="${name}" ;; + *) repo_name="${name}.git" ;; +esac + +repo_path="${GIT_REPO_ROOT}/${repo_name}" + +if [ -e "${repo_path}" ]; then + printf 'repository already exists: %s\n' "${repo_path}" >&2 + exit 1 +fi + +install -d -o "${GIT_USER}" -g "${GIT_GROUP}" "${repo_path}" +git init --bare -b "${DEFAULT_BRANCH}" "${repo_path}" >/dev/null +printf '%s\n' "${description}" >"${repo_path}/description" +chown -R "${GIT_USER}:${GIT_GROUP}" "${repo_path}" + +printf 'created %s\n' "${repo_path}" +printf 'policy line to add: <user> %s write refs/heads/*\n' "${name%.git}" +printf ' (edit the policy source and roll the ConfigMap; nothing here writes it)' 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}" diff --git a/container/git-host-key b/container/git-host-key new file mode 100755 index 0000000..a7fdfc8 --- /dev/null +++ b/container/git-host-key @@ -0,0 +1,186 @@ +#!/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: +# +# 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. +set -eu + +KEYS="${GIT_HOST_AUTHORIZED_KEYS:-/etc/git-host/secrets/authorized_keys}" +RUNTIME_KEYS="${GIT_HOST_AUTHORIZED_KEYS_RUNTIME:-/run/git-host/secrets/authorized_keys}" +SSH_SHELL="${GIT_HOST_SSH_SHELL:-/usr/bin/git-shell}" +POLICY="${GIT_HOST_AUTHZ:-/etc/git-host/authz.conf}" +KEY_TYPES='ssh-rsa ssh-dss ssh-ed25519 ssh-ed448 ecdsa-sha2-nistp256 ecdsa-sha2-nistp384 ecdsa-sha2-nistp521 sk-ssh-ed25519@openssh.com sk-ecdsa-sha2-nistp256@openssh.com' + +usage() { + cat <<'USAGE' +git-host-key - manage ssh keys and the user identity attached to them + +Usage: + git-host-key add <user> [keyfile|-] add key(s) owned by <user> (default: stdin) + git-host-key list user, fingerprint and comment per key + git-host-key rm <user> remove every key of <user> + +Keys are cross-checked by 'git-authz validate', which also checks the rest of +the wiring: identity-less keys, keys pinned somewhere other than git-shell, and +identities with no policy rule. + +Files: + GIT_HOST_AUTHORIZED_KEYS authoritative file (default /etc/git-host/secrets/authorized_keys) + GIT_HOST_AUTHORIZED_KEYS_RUNTIME file sshd reads (default /run/git-host/secrets/authorized_keys) + +After editing, the runtime copy is refreshed and sshd picks it up on the next +connection (no reload needed). A key only names somebody; what they may do comes +from the policy file, which is a read-only mount in a deployed container: edit +your source copy and roll the ConfigMap that provides it. +USAGE +} + +key_options() { + printf 'command="%s",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-user-rc,environment="GIT_HOST_USER=%s"' "$SSH_SHELL" "$1" +} + +identity_of() { + printf '%s' "$1" | sed -n 's/.*GIT_HOST_USER=\([^",[:space:]]*\).*/\1/p' +} + +# strip any pre-existing option list, returning "<type> <base64> [comment]" +strip_options() { + printf '%s\n' "$1" | awk -v types="$KEY_TYPES" ' + BEGIN { n = split(types, t, " "); for (i = 1; i <= n; i++) is[t[i]] = 1 } + { + for (i = 1; i <= NF; i++) { + if (is[$i]) { + out = "" + for (j = i; j <= NF; j++) out = out (j > i ? " " : "") $j + print out + found = 1 + exit + } + } + } + END { if (!found) exit 1 }' +} + +valid_key_line() { + _body="$(strip_options "$1")" || return 1 + _tmp="$(mktemp)" + printf '%s\n' "$_body" >"$_tmp" + if command -v ssh-keygen >/dev/null 2>&1; then + ssh-keygen -l -f "$_tmp" >/dev/null 2>&1 || { rm -f "$_tmp"; return 1; } + fi + rm -f "$_tmp" + return 0 +} + +fingerprint_of() { + _body="$(strip_options "$1")" || return 1 + _tmp="$(mktemp)" + printf '%s\n' "$_body" >"$_tmp" + if command -v ssh-keygen >/dev/null 2>&1; then + ssh-keygen -l -f "$_tmp" 2>/dev/null | awk '{print $2}' + else + printf 'unknown\n' + fi + rm -f "$_tmp" +} + +sync_runtime() { + [ -f "$KEYS" ] || return 0 + if [ ! -d "$(dirname "$RUNTIME_KEYS")" ]; then return 0; fi + if install -m 0640 "$KEYS" "$RUNTIME_KEYS.tmp" 2>/dev/null; then + mv -f "$RUNTIME_KEYS.tmp" "$RUNTIME_KEYS" 2>/dev/null || rm -f "$RUNTIME_KEYS.tmp" + else + printf 'git-host-key: warning: could not refresh %s (run as root and re-run, or restart the container)\n' "$RUNTIME_KEYS" >&2 + fi +} + +write_keys() { + _tmp="$(mktemp)" + printf '%s\n' "$1" >"$_tmp" + install -m 0600 "$_tmp" "$KEYS" || { rm -f "$_tmp"; exit 1; } + rm -f "$_tmp" + sync_runtime +} + +cmd_add() { + [ "$#" -ge 1 ] || { usage; exit 64; } + user="$1" + src="${2:--}" + case "$user" in + ''|*[!A-Za-z0-9._@-]*) printf 'git-host-key: invalid user name: %s\n' "$user" >&2; exit 64 ;; + esac + [ -e "$KEYS" ] || { mkdir -p "$(dirname "$KEYS")"; : >"$KEYS"; } + + _added=0 + _out="$(cat "$KEYS")" + while IFS= read -r line; do + case "$line" in ''|\#*) continue ;; esac + if ! valid_key_line "$line"; then + printf 'git-host-key: skipping unparseable key: %s\n' "$(printf '%s' "$line" | cut -c1-60)" >&2 + continue + fi + body="$(strip_options "$line")" + _out="${_out:+$_out +}$(key_options "$user") $body" + _added=$((_added + 1)) + done <"$src" + + [ "$_added" -gt 0 ] || { printf 'git-host-key: no usable key found in %s\n' "$src" >&2; exit 1; } + write_keys "$_out" + printf 'git-host-key: added %s key(s) for %s\n' "$_added" "$user" + if ! grep -Eq "^[[:space:]]*${user}[[:space:]]" "$POLICY" 2>/dev/null; then + printf 'git-host-key: note: %s has no policy rule yet, so their pushes will be denied.\n' "$user" >&2 + printf 'git-host-key: add "%s <repo> write <ref pattern>" to the policy source.\n' "$user" >&2 + fi +} + +cmd_list() { + [ -f "$KEYS" ] || return 0 + _n=0 + while IFS= read -r line; do + case "$line" in ''|\#*) continue ;; esac + _n=$((_n + 1)) + _u="$(identity_of "$line")" + [ -n "$_u" ] || _u='<no identity>' + printf '%s\t%s\t%s\n' "$_u" "$(fingerprint_of "$line")" "$(printf '%s' "$line" | awk '{print $NF}')" + done <"$KEYS" + [ "$_n" -gt 0 ] || printf 'git-host-key: no keys in %s\n' "$KEYS" >&2 +} + +cmd_rm() { + [ "$#" -ge 1 ] || { usage; exit 64; } + user="$1" + [ -f "$KEYS" ] || exit 0 + _new='' + _removed=0 + while IFS= read -r line; do + case "$line" in ''|\#*) continue ;; esac + if [ "$(identity_of "$line")" = "$user" ]; then + _removed=$((_removed + 1)) + continue + fi + _new="${_new:+$_new +}$line" + done <"$KEYS" + write_keys "${_new:+$_new +}" + printf 'git-host-key: removed %s key(s) of %s\n' "$_removed" "$user" +} + +cmd="${1:-}"; shift || true +case "$cmd" in + add) cmd_add "$@" ;; + list) cmd_list "$@" ;; + rm) cmd_rm "$@" ;; + -h|--help|'') usage ;; + *) printf 'git-host-key: unknown command: %s\n' "$cmd" >&2; usage >&2; exit 64 ;; +esac diff --git a/container/git-http-backend.cgi b/container/git-http-backend.cgi new file mode 100644 index 0000000..e086525 --- /dev/null +++ b/container/git-http-backend.cgi @@ -0,0 +1,20 @@ +#!/bin/sh +# git-http-backend.cgi - a .cgi-named door to the stock git-http-backend. +# +# 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. +set -eu + +BACKEND="${GIT_HOST_HTTP_BACKEND:-/usr/libexec/git-core/git-http-backend}" +[ -x "$BACKEND" ] || { printf 'Status: 500 Internal Server Error\r\n\r\n' >&2; exit 1; } + +exec "$BACKEND" diff --git a/container/healthz b/container/healthz new file mode 100644 index 0000000..9766475 --- /dev/null +++ b/container/healthz @@ -0,0 +1 @@ +ok diff --git a/container/lighttpd.conf b/container/lighttpd.conf new file mode 100644 index 0000000..cd9d562 --- /dev/null +++ b/container/lighttpd.conf @@ -0,0 +1,43 @@ +server.modules = ( + "mod_alias", + "mod_auth", + "mod_authn_file", + "mod_cgi", + "mod_rewrite", + "mod_setenv" +) + +server.bind = "0.0.0.0" +server.port = 8080 +server.username = "git" +server.groupname = "git" +server.document-root = "/var/www/localhost/htdocs" +server.pid-file = "/run/lighttpd/lighttpd.pid" + +index-file.names = ("index.html") + +alias.url = ( + "/cgit.cgi" => "/usr/share/webapps/cgit/cgit.cgi", + "/cgit.css" => "/usr/share/webapps/cgit/cgit.css", + "/cgit.png" => "/usr/share/webapps/cgit/cgit.png", + "/cgit" => "/usr/share/webapps/cgit/cgit.cgi", + "/favicon.ico" => "/usr/share/webapps/cgit/favicon.ico", + "/robots.txt" => "/usr/share/webapps/cgit/robots.txt", + "/git" => "/usr/local/libexec/git-http-backend.cgi" +) + +url.rewrite-once = ( + "^/$" => "/cgit" +) + +cgi.assign = ( + ".cgi" => "" +) + +setenv.add-environment = ( + "CGIT_CONFIG" => "/etc/cgitrc", + "GIT_PROJECT_ROOT" => "/var/lib/git", + "GIT_HTTP_EXPORT_ALL" => "1" +) + +include "/etc/lighttpd/auth.conf" diff --git a/container/sshd_config b/container/sshd_config new file mode 100644 index 0000000..c180f50 --- /dev/null +++ b/container/sshd_config @@ -0,0 +1,35 @@ +Port 2222 +ListenAddress 0.0.0.0 +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 +# +# 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 +# (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. +ForceCommand /usr/bin/git-shell + +PasswordAuthentication no +KbdInteractiveAuthentication no +ChallengeResponseAuthentication no +PermitRootLogin no +PermitTunnel no +AllowTcpForwarding no +X11Forwarding no +PermitTTY no +PrintMotd no +AllowUsers git +Subsystem sftp internal-sftp |
