summaryrefslogtreecommitdiffstats
path: root/container/git-host-key
diff options
context:
space:
mode:
authordev <dev@example>2026-11-15 13:54:31 +0000
committerdev <dev@example>2026-11-15 13:54:31 +0000
commitda06d4f56afa72ae832238f91358b9aeaeaf0da5 (patch)
tree7ead0d915bf4e388dcc55d3b63b4fc0628ef895b /container/git-host-key
parent85b7fa7f8456c84f65a0d81b760c430098ae7fd8 (diff)
downloadaccess-control-main.tar.gz
access-control-main.zip
Only build the access control executableHEADmain
The container image and all the server configuration (Dockerfile, entrypoint, cgitrc, sshd, lighttpd, create-repo, git-host-key) move to the git-host project. This repo is now just the program: cmd/, src/, test/, the Makefile that builds git-authz and installs it, and the example policy - the same cmd/src/test/obj layout the reference projects use. The CI pipeline keeps the compile-and-test gate (strict, test, sanitizer, install) and drops the container-build job, which belongs to git-host now.
Diffstat (limited to 'container/git-host-key')
-rwxr-xr-xcontainer/git-host-key181
1 files changed, 0 insertions, 181 deletions
diff --git a/container/git-host-key b/container/git-host-key
deleted file mode 100755
index 4c7c2dc..0000000
--- a/container/git-host-key
+++ /dev/null
@@ -1,181 +0,0 @@
-#!/bin/sh
-# 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"
-#
-# 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}"
-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>
-
-Each key is written with the option prefix above, so a push made with one arrives
-named rather than anonymous. Nothing re-checks that afterwards: a key edited in
-by hand can lose the identity option, and the name a key carries still needs a
-rule in the policy file.
-
-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