vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Ship the front door without installing it
09610c0f2f7abc5c729973a6a8680d25ed41571f · Keenan Nemetz · 16d ago · parent c5f2c5d4
Ship the front door without installing it The front door works, but nothing puts it on a machine. This adds the account, the login shell, the socket directory, the sshd drop-in, and the two deployment templates, and it leaves every one of them opt-in. The drop-in is rendered, not written twice. internal/sshdconfig produces the whole file, the package ships the output for the default account and paths, and a test compares the two, so the Match block, the account, the binary and the config path cannot drift from what ssh-authorized-keys is given. The file is shipped at /usr/share/vole/sshd/vole.conf and never installed: putting a Match block in somebody's sshd is their decision, and the header says where it must go — appended last, because everything after a Match block applies only to that match. The account's shell is a wrapper, /usr/lib/vole/ssh-shell, because ssh_user is an account name and a shell is a path. It execs `vole ssh-shell` with its arguments untouched; sshd runs a forced command through the login shell, so that subcommand has to be reachable from an account whose pw_shell cannot hold a command line. postinstall creates git:git with no access to /var/lib/vole, creates /run/vole as vole:git 2770, and adds vole to the group. An existing `git` account is left exactly as it is, shell included: taking it over would break whatever forge put it there, and the install says so and points at ssh_user. The setgid bit on /run/vole is what gives the socket the group both sides share, and the unit gets ReadWritePaths=/run/vole because ProtectSystem=strict would otherwise make /run read-only — the front door needs no capability, since sshd owns 22. The cloud-init templates take SSH_PORT, defaulting to 2222. With 2222 they render exactly what they rendered before. With 22 they name no port at all: the runner's --remote, its ssh-keyscan, the forge's ssh_addr and its final clone URL all switch, and check-deploy renders both flavours and fails if anything still says 2222. The forge templates also carry the commented front-door block, and packaging/vole.toml documents the four settings. check-deploy now also parses the four packaging files after one account name, and `sh -n`s the postinstall and the shell wrapper: both run as root or as a login shell, where a syntax error is found at the worst possible moment. The documentation and migration are #307.
packaging/scripts/postinstall.sh +41
| @@ -18,6 +18,47 @@ fi | |||
| 18 | 18 | ||
| 19 | 19 | install -d -o vole -g vole -m 0750 /var/lib/vole | |
| 20 | 20 | ||
| 21 | # The front door's account. | ||
| 22 | # | ||
| 23 | # sshd authenticates a Vole key and runs the forced command as this account, which | ||
| 24 | # must not be able to read the instance's data: /var/lib/vole stays 0750 vole:vole, | ||
| 25 | # and this account is not in the vole group. Its shell is the wrapper that execs | ||
| 26 | # `vole ssh-shell`, because sshd runs a forced command through the login shell and | ||
| 27 | # an account name cannot be a command line. | ||
| 28 | # | ||
| 29 | # A machine may already have a `git` account for another forge. Taking it over | ||
| 30 | # would break that forge, and pointing its shell at Vole would make sshd hand it | ||
| 31 | # keys Vole answers for, so an existing account that is not ours is left exactly | ||
| 32 | # as it is. The operator then sets ssh_user to an account they create for Vole and | ||
| 33 | # changes the Match line in /usr/share/vole/sshd/vole.conf to name it. | ||
| 34 | SSH_ACCOUNT=git | ||
| 35 | SSH_SHELL=/usr/lib/vole/ssh-shell | ||
| 36 | if ! getent group "$SSH_ACCOUNT" >/dev/null 2>&1; then | ||
| 37 | groupadd --system "$SSH_ACCOUNT" | ||
| 38 | fi | ||
| 39 | if ! getent passwd "$SSH_ACCOUNT" >/dev/null 2>&1; then | ||
| 40 | useradd --system --gid "$SSH_ACCOUNT" --create-home \ | ||
| 41 | --home-dir "/home/$SSH_ACCOUNT" --shell "$SSH_SHELL" \ | ||
| 42 | --comment "Vole Git over SSH" "$SSH_ACCOUNT" | ||
| 43 | fi | ||
| 44 | # Present at install time rather than at the next boot: the package manager | ||
| 45 | # triggers tmpfiles on Debian, but a container or a chroot may not, and the unit's | ||
| 46 | # ReadWritePaths=/run/vole refuses to start when the directory is missing. The | ||
| 47 | # setgid bit is what gives the socket the group both sides share. | ||
| 48 | install -d -o vole -g "$SSH_ACCOUNT" -m 2770 /run/vole | ||
| 49 | |||
| 50 | if [ "$(getent passwd "$SSH_ACCOUNT" | cut -d: -f7)" = "$SSH_SHELL" ]; then | ||
| 51 | # The service account is a member so the two sides stay in step if either the | ||
| 52 | # account or the directory is changed later. | ||
| 53 | if ! id -nG vole | tr ' ' '\n' | grep -qx "$SSH_ACCOUNT"; then | ||
| 54 | usermod -aG "$SSH_ACCOUNT" vole | ||
| 55 | fi | ||
| 56 | else | ||
| 57 | echo "vole: an existing $SSH_ACCOUNT account was left alone; the sshd front door needs" >&2 | ||
| 58 | echo "vole: an account whose shell is $SSH_SHELL. Create one, set ssh_user to it, and" >&2 | ||
| 59 | echo "vole: change the Match line in /usr/share/vole/sshd/vole.conf to name it." >&2 | ||
| 60 | fi | ||
| 61 | |||
| 21 | 62 | # Init is idempotent: it leaves an existing config, repository tree, and database | |
| 22 | 63 | # alone. Running it as the service account keeps the data it creates writable by | |
| 23 | 64 | # the service, and a failed upgrade never leaves root-owned state behind. | |