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/create-repo | |
| 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/create-repo')
| -rwxr-xr-x | container/create-repo | 60 |
1 files changed, 60 insertions, 0 deletions
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)' |
