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_test.go +123
| @@ -0,0 +1,123 @@ | |||
| 1 | package sshdconfig | ||
| 2 | |||
| 3 | // The shipped drop-in is a rendered result, not a hand-written file: the test | ||
| 4 | // below compares it with Render(PackageDefaults()), so what the package installs | ||
| 5 | // and what the binary expects cannot drift. `go test ./internal/sshdconfig | ||
| 6 | // -update` rewrites it, which is the only way it should ever change. | ||
| 7 | |||
| 8 | import ( | ||
| 9 | "flag" | ||
| 10 | "os" | ||
| 11 | "os/exec" | ||
| 12 | "path/filepath" | ||
| 13 | "strings" | ||
| 14 | "testing" | ||
| 15 | ) | ||
| 16 | |||
| 17 | var update = flag.Bool("update", false, "rewrite packaging/sshd/vole.conf from PackageDefaults") | ||
| 18 | |||
| 19 | const shippedPath = "../../packaging/sshd/vole.conf" | ||
| 20 | |||
| 21 | func TestShippedDropInMatchesTheRenderer(t *testing.T) { | ||
| 22 | got := Render(PackageDefaults()) | ||
| 23 | if *update { | ||
| 24 | if err := os.WriteFile(shippedPath, []byte(got), 0o644); err != nil { | ||
| 25 | t.Fatal(err) | ||
| 26 | } | ||
| 27 | } | ||
| 28 | want, err := os.ReadFile(shippedPath) | ||
| 29 | if err != nil { | ||
| 30 | t.Fatalf("read %s: %v (run: go test ./internal/sshdconfig -update)", shippedPath, err) | ||
| 31 | } | ||
| 32 | if string(want) != got { | ||
| 33 | t.Errorf("%s is not what the renderer produces (run: go test ./internal/sshdconfig -update)", shippedPath) | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | func TestRenderNamesTheConfiguredAccountAndPaths(t *testing.T) { | ||
| 38 | t.Parallel() | ||
| 39 | got := Render(Options{User: "vole-git", Vole: "/opt/vole", Config: "/srv/vole.toml"}) | ||
| 40 | for _, want := range []string{ | ||
| 41 | "Match User vole-git", | ||
| 42 | `AuthorizedKeysCommand /opt/vole ssh-authorized-keys --config /srv/vole.toml --fingerprint %f --type %t --key %k --connection %C`, | ||
| 43 | "AuthorizedKeysCommandUser vole", | ||
| 44 | "AuthorizedKeysFile none", | ||
| 45 | "DisableForwarding yes", | ||
| 46 | "PermitTTY no", | ||
| 47 | } { | ||
| 48 | if !strings.Contains(got, want) { | ||
| 49 | t.Errorf("the rendered drop-in is missing %q:\n%s", want, got) | ||
| 50 | } | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | func TestDropInDisablesEverythingButTheForcedCommand(t *testing.T) { | ||
| 55 | t.Parallel() | ||
| 56 | got := Render(PackageDefaults()) | ||
| 57 | // Every one of these is a way in that must not exist for this account. A | ||
| 58 | // dropped line is silent, so each is checked by name. | ||
| 59 | for _, line := range []string{ | ||
| 60 | "AuthorizedKeysFile none", | ||
| 61 | "PasswordAuthentication no", | ||
| 62 | "KbdInteractiveAuthentication no", | ||
| 63 | "DisableForwarding yes", | ||
| 64 | "PermitTTY no", | ||
| 65 | "PermitUserRC no", | ||
| 66 | } { | ||
| 67 | if !strings.Contains(got, "\n "+line+"\n") { | ||
| 68 | t.Errorf("the drop-in does not set %q as a Match directive", line) | ||
| 69 | } | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | // TestSshdAcceptsTheDropIn runs the real sshd over the rendered file when sshd | ||
| 74 | // and ssh-keygen are installed. The verify image has neither, so it skips there; | ||
| 75 | // on a host that can check it, this is the answer that matters. | ||
| 76 | func TestSshdAcceptsTheDropIn(t *testing.T) { | ||
| 77 | t.Parallel() | ||
| 78 | sshd, err := exec.LookPath("sshd") | ||
| 79 | if err != nil { | ||
| 80 | t.Skip("sshd is not installed") | ||
| 81 | } | ||
| 82 | if _, err := exec.LookPath("ssh-keygen"); err != nil { | ||
| 83 | t.Skip("ssh-keygen is not installed") | ||
| 84 | } | ||
| 85 | |||
| 86 | dir := t.TempDir() | ||
| 87 | key := filepath.Join(dir, "host_ed25519") | ||
| 88 | if out, err := exec.Command("ssh-keygen", "-q", "-t", "ed25519", "-N", "", "-f", key).CombinedOutput(); err != nil { | ||
| 89 | t.Fatalf("ssh-keygen: %v\n%s", err, out) | ||
| 90 | } | ||
| 91 | // A host key is the minimum sshd needs to consider a file a whole config; the | ||
| 92 | // drop-in itself is only a Match block. | ||
| 93 | config := filepath.Join(dir, "sshd_config") | ||
| 94 | body := "HostKey " + key + "\nPidFile none\n" + Render(PackageDefaults()) | ||
| 95 | if err := os.WriteFile(config, []byte(body), 0o600); err != nil { | ||
| 96 | t.Fatal(err) | ||
| 97 | } | ||
| 98 | |||
| 99 | // -T parses the file and prints the effective configuration. -C supplies a | ||
| 100 | // connection spec, without which the dump is the global context and the Match | ||
| 101 | // block would not be applied at all: a drop-in that sshd ignored would pass. | ||
| 102 | out, err := exec.Command(sshd, "-T", "-f", config, | ||
| 103 | "-C", "user="+PackageDefaults().User+",host=example.test,addr=127.0.0.1").CombinedOutput() | ||
| 104 | if err != nil { | ||
| 105 | if strings.Contains(string(out), "privilege separation") { | ||
| 106 | t.Skipf("sshd cannot validate a config in this environment: %s", strings.TrimSpace(string(out))) | ||
| 107 | } | ||
| 108 | t.Fatalf("sshd rejected the drop-in: %v\n%s", err, out) | ||
| 109 | } | ||
| 110 | effective := string(out) | ||
| 111 | for _, want := range []string{ | ||
| 112 | "authorizedkeysfile none", | ||
| 113 | "authorizedkeyscommand /usr/bin/vole ssh-authorized-keys", | ||
| 114 | "authorizedkeyscommanduser vole", | ||
| 115 | "permittty no", | ||
| 116 | "permituserrc no", | ||
| 117 | "disableforwarding yes", | ||
| 118 | } { | ||
| 119 | if !strings.Contains(strings.ToLower(effective), want) { | ||
| 120 | t.Errorf("sshd did not apply %q:\n%s", want, effective) | ||
| 121 | } | ||
| 122 | } | ||
| 123 | } | ||