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 an sshd drop-in for each platform instead of rendering one at runtime
883ffcc941bdeb32f0587cf0574b0cfbdcd33695 · Keenan Nemetz · 12d ago · parent a4a6d1e9
Ship an sshd drop-in for each platform instead of rendering one at runtime The drop-in was Linux-only prose: systemctl, useradd, /usr/lib/vole/ssh-shell, /usr/bin/vole, /etc/vole/vole.toml. The Match block works on macOS, but every operation around it differs — there is no sshd_config.d, reload is launchctl, accounts come from sysadminctl, and the binary and config live wherever the install put them. The only copy was rendered at build time from one fixed set of paths, so a Mac had nothing to install. Render two files from the same function instead: vole-linux.conf, which the package still installs as /usr/share/vole/sshd/vole.conf, and vole-darwin.conf, which the release publishes as vole-darwin-sshd.conf. The -update test rewrites both and compares both, and Linux sshd parses the macOS file too because the directives are identical and only the comments differ. Options gain the platform, the destination the Include line names, the account sshd runs AuthorizedKeysCommand as, the forced-command account's shell, and the socket path. The header branches on platform; the Match block does not. The macOS file names /usr/local paths and says so, with the one-line substitution a Homebrew prefix needs. check-deploy.py and nfpm.yaml follow the renamed Linux file; the package still installs it as vole.conf, so nothing on a Debian host changes. The front-door page gains the macOS steps, including that ssh_socket must be a directory both accounts can reach. Closes: 01M7ZVF5NWM5S9SV5AD00KFGC7
internal/sshdconfig/sshdconfig_test.go +97−47
| @@ -1,9 +1,9 @@ | |||
| 1 | 1 | package sshdconfig | |
| 2 | 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. | ||
| 3 | // The shipped drop-ins are rendered results, not hand-written files: the test | ||
| 4 | // below compares each one with the renderer, so what the package installs and | ||
| 5 | // what the binary expects cannot drift. `go test ./internal/sshdconfig -update` | ||
| 6 | // rewrites both, which is the only way they should ever change. | ||
| 7 | 7 | ||
| 8 | 8 | import ( | |
| 9 | 9 | "flag" | |
| @@ -14,23 +14,38 @@ import ( | |||
| 14 | 14 | "testing" | |
| 15 | 15 | ) | |
| 16 | 16 | ||
| 17 | var update = flag.Bool("update", false, "rewrite packaging/sshd/vole.conf from PackageDefaults") | ||
| 17 | var update = flag.Bool("update", false, "rewrite the shipped drop-ins from the renderer") | ||
| 18 | 18 | ||
| 19 | const shippedPath = "../../packaging/sshd/vole.conf" | ||
| 19 | // shippedDropIn is one committed file and the defaults it is rendered from. | ||
| 20 | type shippedDropIn struct { | ||
| 21 | platform string | ||
| 22 | path string | ||
| 23 | options Options | ||
| 24 | } | ||
| 20 | 25 | ||
| 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 | } | ||
| 26 | func shippedDropIns() []shippedDropIn { | ||
| 27 | return []shippedDropIn{ | ||
| 28 | {"linux", "../../packaging/sshd/vole-linux.conf", LinuxDefaults()}, | ||
| 29 | {"darwin", "../../packaging/sshd/vole-darwin.conf", DarwinDefaults()}, | ||
| 27 | 30 | } | |
| 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) | ||
| 31 | } | ||
| 32 | |||
| 33 | func TestShippedDropInsMatchTheRenderer(t *testing.T) { | ||
| 34 | for _, dropIn := range shippedDropIns() { | ||
| 35 | got := Render(dropIn.options) | ||
| 36 | if *update { | ||
| 37 | if err := os.WriteFile(dropIn.path, []byte(got), 0o644); err != nil { | ||
| 38 | t.Fatal(err) | ||
| 39 | } | ||
| 40 | } | ||
| 41 | want, err := os.ReadFile(dropIn.path) | ||
| 42 | if err != nil { | ||
| 43 | t.Fatalf("read %s: %v (run: go test ./internal/sshdconfig -update)", dropIn.path, err) | ||
| 44 | } | ||
| 45 | if string(want) != got { | ||
| 46 | t.Errorf("%s (%s) is not what the renderer produces (run: go test ./internal/sshdconfig -update)", | ||
| 47 | dropIn.platform, dropIn.path) | ||
| 48 | } | ||
| 34 | 49 | } | |
| 35 | 50 | } | |
| 36 | 51 | ||
| @@ -51,9 +66,40 @@ func TestRenderNamesTheConfiguredAccountAndPaths(t *testing.T) { | |||
| 51 | 66 | } | |
| 52 | 67 | } | |
| 53 | 68 | ||
| 69 | // TestDarwinRenderNamesTheMacCommands is the whole reason the renderer knows a | ||
| 70 | // platform: the Match block is the same, and every command around it is not. | ||
| 71 | func TestDarwinRenderNamesTheMacCommands(t *testing.T) { | ||
| 72 | t.Parallel() | ||
| 73 | got := Render(Options{ | ||
| 74 | Platform: "darwin", | ||
| 75 | User: "you", | ||
| 76 | Vole: "/opt/homebrew/bin/vole", | ||
| 77 | Config: "/opt/homebrew/etc/vole/vole.toml", | ||
| 78 | Socket: "/opt/homebrew/var/vole/ssh.sock", | ||
| 79 | }) | ||
| 80 | for _, want := range []string{ | ||
| 81 | "sudo sshd -t && sudo launchctl kickstart -k system/com.openssh.sshd", | ||
| 82 | "systemsetup -setremotelogin on", | ||
| 83 | "brew services restart vole", | ||
| 84 | "sudo sysadminctl -addUser you -shell /usr/local/lib/vole/ssh-shell ...", | ||
| 85 | `ssh_socket = "/opt/homebrew/var/vole/ssh.sock"`, | ||
| 86 | "Include /etc/ssh/vole.conf", | ||
| 87 | "AuthorizedKeysCommand /opt/homebrew/bin/vole ssh-authorized-keys --config /opt/homebrew/etc/vole/vole.toml", | ||
| 88 | } { | ||
| 89 | if !strings.Contains(got, want) { | ||
| 90 | t.Errorf("the macOS render is missing %q:\n%s", want, got) | ||
| 91 | } | ||
| 92 | } | ||
| 93 | for _, unwanted := range []string{"systemctl", "useradd"} { | ||
| 94 | if strings.Contains(got, unwanted) { | ||
| 95 | t.Errorf("the macOS render names %q, which does not exist there", unwanted) | ||
| 96 | } | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 54 | 100 | func TestDropInDisablesEverythingButTheForcedCommand(t *testing.T) { | |
| 55 | 101 | t.Parallel() | |
| 56 | got := Render(PackageDefaults()) | ||
| 102 | got := Render(LinuxDefaults()) | ||
| 57 | 103 | // Every one of these is a way in that must not exist for this account. A | |
| 58 | 104 | // dropped line is silent, so each is checked by name. | |
| 59 | 105 | for _, line := range []string{ | |
| @@ -88,36 +134,40 @@ func TestSshdAcceptsTheDropIn(t *testing.T) { | |||
| 88 | 134 | if out, err := exec.Command("ssh-keygen", "-q", "-t", "ed25519", "-N", "", "-f", key).CombinedOutput(); err != nil { | |
| 89 | 135 | t.Fatalf("ssh-keygen: %v\n%s", err, out) | |
| 90 | 136 | } | |
| 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 | } | ||
| 137 | // Both files carry the same directives; only the comments around them differ | ||
| 138 | // by platform, and sshd ignores those. So Linux sshd checks the macOS file too. | ||
| 139 | for _, dropIn := range shippedDropIns() { | ||
| 140 | // A host key is the minimum sshd needs to consider a file a whole config; the | ||
| 141 | // drop-in itself is only a Match block. | ||
| 142 | config := filepath.Join(dir, dropIn.platform+"_sshd_config") | ||
| 143 | body := "HostKey " + key + "\nPidFile none\n" + Render(dropIn.options) | ||
| 144 | if err := os.WriteFile(config, []byte(body), 0o600); err != nil { | ||
| 145 | t.Fatal(err) | ||
| 146 | } | ||
| 98 | 147 | ||
| 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))) | ||
| 148 | // -T parses the file and prints the effective configuration. -C supplies a | ||
| 149 | // connection spec, without which the dump is the global context and the Match | ||
| 150 | // block would not be applied at all: a drop-in that sshd ignored would pass. | ||
| 151 | out, err := exec.Command(sshd, "-T", "-f", config, | ||
| 152 | "-C", "user="+dropIn.options.User+",host=example.test,addr=127.0.0.1").CombinedOutput() | ||
| 153 | if err != nil { | ||
| 154 | if strings.Contains(string(out), "privilege separation") { | ||
| 155 | t.Skipf("sshd cannot validate a config in this environment: %s", strings.TrimSpace(string(out))) | ||
| 156 | } | ||
| 157 | t.Fatalf("sshd rejected the %s drop-in: %v\n%s", dropIn.platform, err, out) | ||
| 107 | 158 | } | |
| 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) | ||
| 159 | effective := strings.ToLower(string(out)) | ||
| 160 | for _, want := range []string{ | ||
| 161 | "authorizedkeysfile none", | ||
| 162 | "authorizedkeyscommand " + strings.ToLower(dropIn.options.Vole) + " ssh-authorized-keys", | ||
| 163 | "authorizedkeyscommanduser " + strings.ToLower(dropIn.options.ServiceUser), | ||
| 164 | "permittty no", | ||
| 165 | "permituserrc no", | ||
| 166 | "disableforwarding yes", | ||
| 167 | } { | ||
| 168 | if !strings.Contains(effective, want) { | ||
| 169 | t.Errorf("sshd did not apply %q to the %s drop-in:\n%s", want, dropIn.platform, effective) | ||
| 170 | } | ||
| 121 | 171 | } | |
| 122 | 172 | } | |
| 123 | 173 | } | |