Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

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.

internal/sshdconfig/sshdconfig.go +88

@@ -0,0 +1,88 @@
1 // Package sshdconfig renders the sshd drop-in that puts the system sshd in front
2 // of Vole.
3 //
4 // It exists so one function decides what the file says. The package ships the
5 // result of Render(PackageDefaults()) as /usr/share/vole/sshd/vole.conf, and a
6 // test compares the shipped file with this function's output, so the Match block,
7 // the account sshd runs, the binary path, and the config path cannot drift from
8 // what `vole ssh-authorized-keys` is given.
9 package sshdconfig
10
11 import (
12 "fmt"
13 "strings"
14 )
15
16 // Options are the three things the drop-in names.
17 type Options struct {
18 // User is the operating-system account sshd runs the forced command as, and
19 // the account in generated clone URLs (ssh_user).
20 User string
21 // Vole is the absolute path to the binary sshd runs. It is the same binary
22 // whose ssh-exec becomes the forced command, so the two cannot disagree.
23 Vole string
24 // Config is the absolute path to vole.toml, handed to ssh-authorized-keys.
25 Config string
26 }
27
28 // PackageDefaults is what the shipped file is rendered from: the account and
29 // paths the package installs. An operator who changes ssh_user changes the Match
30 // line in their copy of the file, and the header says so.
31 func PackageDefaults() Options {
32 return Options{
33 User: "git",
34 Vole: "/usr/bin/vole",
35 Config: "/etc/vole/vole.toml",
36 }
37 }
38
39 // Render is the whole drop-in, comments included.
40 func Render(o Options) string {
41 var b strings.Builder
42 fmt.Fprintf(&b, `# The system sshd as Vole's front door.
43 #
44 # The package ships this file and does not install it, and it never edits
45 # /etc/ssh. To enable the front door:
46 #
47 # 1. Append this line at the END of /etc/ssh/sshd_config. It must be last: a
48 # Match block applies to everything after it, so an Include placed above
49 # other settings would silently scope them to the matched user.
50 #
51 # Include /usr/share/vole/sshd/vole.conf
52 #
53 # 2. sshd -t && systemctl reload sshd
54 #
55 # 3. In /etc/vole/vole.toml set:
56 #
57 # ssh_listen = "socket"
58 # ssh_addr = "0.0.0.0:22"
59 # ssh_public_host_key_file = "/etc/ssh/ssh_host_ed25519_key.pub"
60 #
61 # ssh_addr is what generated clone URLs carry: port 22 is omitted, so the
62 # URL is ssh://git@host/repo.git.
63 #
64 # 4. systemctl restart vole
65 #
66 # If this instance uses a different ssh_user, change the Match line below to
67 # name it, and create that account with this file as its shell:
68 #
69 # useradd --system --shell /usr/lib/vole/ssh-shell ...
70 #
71 # AuthorizedKeysCommandUser is the service account: it reads the roster and mints
72 # a session token. The forced command runs as %s, which has no access to
73 # /var/lib/vole. AuthorizedKeysFile none means sshd never reads an
74 # authorized_keys file on this machine: the only keys it accepts are the ones
75 # Vole answers for.
76
77 Match User %s
78 AuthorizedKeysFile none
79 AuthorizedKeysCommand %s ssh-authorized-keys --config %s --fingerprint %%f --type %%t --key %%k --connection %%C
80 AuthorizedKeysCommandUser vole
81 PasswordAuthentication no
82 KbdInteractiveAuthentication no
83 DisableForwarding yes
84 PermitTTY no
85 PermitUserRC no
86 `, o.User, o.User, o.Vole, o.Config)
87 return b.String()
88 }