summaryrefslogtreecommitdiffstats
path: root/create-repo.sh
diff options
context:
space:
mode:
authordelusionalai <delusionalai@jnsn.dev>2026-11-15 13:54:36 +0000
committerdelusionalai <delusionalai@jnsn.dev>2026-11-15 13:54:36 +0000
commited62c4ccf06c2c85d871a6334e3e0d82c6e4257a (patch)
tree69897b0d2be0fab353fa4bac3bbe9cb14171da24 /create-repo.sh
parentcad3e5f4dff0c77c8eed020308c5bf8ffbff5964 (diff)
downloadgit-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 'create-repo.sh')
-rw-r--r--create-repo.sh28
1 files changed, 20 insertions, 8 deletions
diff --git a/create-repo.sh b/create-repo.sh
index 5bc213a..5f80c92 100644
--- a/create-repo.sh
+++ b/create-repo.sh
@@ -1,13 +1,23 @@
#!/bin/sh
+# Create a bare repository. Nothing is installed in it: every repository reaches
+# the shared hook through core.hooksPath, so one made by hand is enforced the same.
+#
+# The policy is a read-only mount, so this only prints the line to add.
+
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() {
- echo "usage: create-repo <name> [description]" >&2
- echo "example: create-repo myrepo 'My application repository'" >&2
+ 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
}
@@ -18,26 +28,28 @@ description="${2:-Unnamed repository}"
case "${name}" in
*/* | .* | *" "* | *".."* )
- echo "invalid repository name: ${name}" >&2
+ printf 'invalid repository name: %s\n' "${name}" >&2
exit 64
;;
esac
case "${name}" in
*.git) repo_name="${name}" ;;
- *) repo_name="${name}.git" ;;
+ *) repo_name="${name}.git" ;;
esac
repo_path="${GIT_REPO_ROOT}/${repo_name}"
if [ -e "${repo_path}" ]; then
- echo "repository already exists: ${repo_path}" >&2
+ 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 "${repo_path}" >/dev/null
-printf '%s\n' "${description}" > "${repo_path}/description"
+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}"
-echo "created ${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)'