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.go +158−29
| @@ -1,11 +1,13 @@ | |||
| 1 | 1 | // Package sshdconfig renders the sshd drop-in that puts the system sshd in front | |
| 2 | 2 | // of Vole. | |
| 3 | 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. | ||
| 4 | // It exists so one function decides what the files say. Two are shipped: | ||
| 5 | // packaging/sshd/vole-linux.conf, installed as /usr/share/vole/sshd/vole.conf, | ||
| 6 | // and packaging/sshd/vole-darwin.conf for macOS. A test compares each with | ||
| 7 | // Render(LinuxDefaults()) and Render(DarwinDefaults()), so the Match block, the | ||
| 8 | // account sshd runs, the binary path, and the config path cannot drift from what | ||
| 9 | // `vole ssh-authorized-keys` is given. The platform changes the commands in the | ||
| 10 | // header, the paths, and the accounts; the Match block is the same on both. | ||
| 9 | 11 | package sshdconfig | |
| 10 | 12 | ||
| 11 | 13 | import ( | |
| @@ -13,11 +15,26 @@ import ( | |||
| 13 | 15 | "strings" | |
| 14 | 16 | ) | |
| 15 | 17 | ||
| 16 | // Options are the three things the drop-in names. | ||
| 18 | // Options are the things the drop-in names. | ||
| 17 | 19 | type Options struct { | |
| 20 | // Platform selects the commands and defaults in the header: "linux" or | ||
| 21 | // "darwin". It is the platform sshd runs on, not the one that rendered the | ||
| 22 | // file. | ||
| 23 | Platform string | ||
| 24 | // Destination is where the operator will put this file; the header's Include | ||
| 25 | // line names it. | ||
| 26 | Destination string | ||
| 18 | 27 | // User is the operating-system account sshd runs the forced command as, and | |
| 19 | 28 | // the account in generated clone URLs (ssh_user). | |
| 20 | 29 | User string | |
| 30 | // ServiceUser is the account sshd runs AuthorizedKeysCommand as. It reads the | ||
| 31 | // roster and mints a session token, so it is the account Vole itself runs as. | ||
| 32 | ServiceUser string | ||
| 33 | // Shell is the login shell of User: the wrapper that recognises the one | ||
| 34 | // command sshd is allowed to run. | ||
| 35 | Shell string | ||
| 36 | // Socket is the front door's Unix socket, printed as ssh_socket. | ||
| 37 | Socket string | ||
| 21 | 38 | // Vole is the absolute path to the binary sshd runs. It is the same binary | |
| 22 | 39 | // whose ssh-exec becomes the forced command, so the two cannot disagree. | |
| 23 | 40 | Vole string | |
| @@ -25,64 +42,176 @@ type Options struct { | |||
| 25 | 42 | Config string | |
| 26 | 43 | } | |
| 27 | 44 | ||
| 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 { | ||
| 45 | // LinuxDefaults is what packaging/sshd/vole-linux.conf is rendered from: the | ||
| 46 | // account and paths the Linux package installs. An operator who changes ssh_user | ||
| 47 | // changes the Match line in their copy of the file, and the header says so. | ||
| 48 | func LinuxDefaults() Options { | ||
| 49 | return defaultsFor("linux") | ||
| 50 | } | ||
| 51 | |||
| 52 | // DarwinDefaults is what packaging/sshd/vole-darwin.conf is rendered from: a | ||
| 53 | // /usr/local install, which is where a system install puts its files. Apple | ||
| 54 | // Silicon Homebrew uses /opt/homebrew instead; the header tells the reader to | ||
| 55 | // substitute the prefix it prints. | ||
| 56 | func DarwinDefaults() Options { | ||
| 57 | return defaultsFor("darwin") | ||
| 58 | } | ||
| 59 | |||
| 60 | // defaultsFor is the fallback for every field an Options leaves empty. The two | ||
| 61 | // platforms differ in where a package puts its files and in which service | ||
| 62 | // manager owns sshd and Vole. | ||
| 63 | func defaultsFor(platform string) Options { | ||
| 64 | if platform == "darwin" { | ||
| 65 | return Options{ | ||
| 66 | Platform: "darwin", | ||
| 67 | Destination: "/etc/ssh/vole.conf", | ||
| 68 | User: "git", | ||
| 69 | ServiceUser: "vole", | ||
| 70 | Shell: "/usr/local/lib/vole/ssh-shell", | ||
| 71 | Socket: "/usr/local/var/vole/ssh.sock", | ||
| 72 | Vole: "/usr/local/bin/vole", | ||
| 73 | Config: "/usr/local/etc/vole/vole.toml", | ||
| 74 | } | ||
| 75 | } | ||
| 32 | 76 | return Options{ | |
| 33 | User: "git", | ||
| 34 | Vole: "/usr/bin/vole", | ||
| 35 | Config: "/etc/vole/vole.toml", | ||
| 77 | Platform: "linux", | ||
| 78 | Destination: "/usr/share/vole/sshd/vole.conf", | ||
| 79 | User: "git", | ||
| 80 | ServiceUser: "vole", | ||
| 81 | Shell: "/usr/lib/vole/ssh-shell", | ||
| 82 | Socket: "/run/vole/ssh.sock", | ||
| 83 | Vole: "/usr/bin/vole", | ||
| 84 | Config: "/etc/vole/vole.toml", | ||
| 36 | 85 | } | |
| 37 | 86 | } | |
| 38 | 87 | ||
| 88 | // filled replaces every empty field with the default for its platform. | ||
| 89 | func (o Options) filled() Options { | ||
| 90 | d := defaultsFor(o.Platform) | ||
| 91 | if o.Platform == "" { | ||
| 92 | o.Platform = d.Platform | ||
| 93 | } | ||
| 94 | if o.Destination == "" { | ||
| 95 | o.Destination = d.Destination | ||
| 96 | } | ||
| 97 | if o.User == "" { | ||
| 98 | o.User = d.User | ||
| 99 | } | ||
| 100 | if o.ServiceUser == "" { | ||
| 101 | o.ServiceUser = d.ServiceUser | ||
| 102 | } | ||
| 103 | if o.Shell == "" { | ||
| 104 | o.Shell = d.Shell | ||
| 105 | } | ||
| 106 | if o.Socket == "" { | ||
| 107 | o.Socket = d.Socket | ||
| 108 | } | ||
| 109 | if o.Vole == "" { | ||
| 110 | o.Vole = d.Vole | ||
| 111 | } | ||
| 112 | if o.Config == "" { | ||
| 113 | o.Config = d.Config | ||
| 114 | } | ||
| 115 | return o | ||
| 116 | } | ||
| 117 | |||
| 39 | 118 | // Render is the whole drop-in, comments included. | |
| 40 | 119 | func Render(o Options) string { | |
| 120 | o = o.filled() | ||
| 41 | 121 | var b strings.Builder | |
| 42 | 122 | fmt.Fprintf(&b, `# The system sshd as Vole's front door. | |
| 43 | 123 | # | |
| 44 | # The package ships this file and does not install it, and it never edits | ||
| 45 | # /etc/ssh. To enable the front door: | ||
| 124 | # This file is rendered, not installed: Vole never edits /etc/ssh. To enable the | ||
| 125 | # front door: | ||
| 46 | 126 | # | |
| 47 | 127 | # 1. Append this line at the END of /etc/ssh/sshd_config. It must be last: a | |
| 48 | 128 | # Match block applies to everything after it, so an Include placed above | |
| 49 | 129 | # other settings would silently scope them to the matched user. | |
| 50 | 130 | # | |
| 51 | # Include /usr/share/vole/sshd/vole.conf | ||
| 131 | # Include %s | ||
| 132 | # | ||
| 133 | `, o.Destination) | ||
| 134 | if o.Platform == "darwin" { | ||
| 135 | fmt.Fprint(&b, `# 2. sudo sshd -t && sudo launchctl kickstart -k system/com.openssh.sshd | ||
| 52 | 136 | # | |
| 53 | # 2. sshd -t && systemctl reload ssh # the unit is sshd on RHEL | ||
| 137 | # Remote Login must be on: sudo systemsetup -setremotelogin on | ||
| 54 | 138 | # | |
| 55 | # 3. In /etc/vole/vole.toml set: | ||
| 139 | `) | ||
| 140 | } else { | ||
| 141 | fmt.Fprint(&b, `# 2. sshd -t && systemctl reload ssh # the unit is sshd on RHEL | ||
| 142 | # | ||
| 143 | `) | ||
| 144 | } | ||
| 145 | fmt.Fprintf(&b, `# 3. In %s set: | ||
| 56 | 146 | # | |
| 57 | 147 | # ssh_listen = "socket" | |
| 58 | 148 | # ssh_addr = "0.0.0.0:22" | |
| 149 | # ssh_socket = %q | ||
| 59 | 150 | # ssh_public_host_key_file = "/etc/ssh/ssh_host_ed25519_key.pub" | |
| 60 | 151 | # | |
| 61 | 152 | # ssh_addr is what generated clone URLs carry: port 22 is omitted, so the | |
| 62 | 153 | # URL is ssh://git@host/repo.git. | |
| 63 | 154 | # | |
| 64 | # 4. systemctl restart vole | ||
| 155 | `, o.Config, o.Socket) | ||
| 156 | if o.Platform == "darwin" { | ||
| 157 | fmt.Fprint(&b, `# 4. Restart vole serve the way it was started: brew services restart vole, | ||
| 158 | # or the launchd job or shell that runs it. | ||
| 159 | # | ||
| 160 | `) | ||
| 161 | } else { | ||
| 162 | fmt.Fprint(&b, `# 4. systemctl restart vole | ||
| 163 | # | ||
| 164 | `) | ||
| 165 | } | ||
| 166 | fmt.Fprintf(&b, `# If this instance uses a different ssh_user, change the Match line below to | ||
| 167 | # name it, and `) | ||
| 168 | if o.Platform == "darwin" { | ||
| 169 | fmt.Fprintf(&b, `give that account this file as its shell: | ||
| 65 | 170 | # | |
| 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: | ||
| 171 | # sudo sysadminctl -addUser %s -shell %s ... | ||
| 68 | 172 | # | |
| 69 | # useradd --system --shell /usr/lib/vole/ssh-shell ... | ||
| 173 | `, o.User, o.Shell) | ||
| 174 | } else { | ||
| 175 | fmt.Fprintf(&b, `create that account with this file as its shell: | ||
| 70 | 176 | # | |
| 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. | ||
| 177 | # useradd --system --shell %s ... | ||
| 178 | # | ||
| 179 | `, o.Shell) | ||
| 180 | } | ||
| 181 | if o.Platform == "darwin" { | ||
| 182 | if strings.HasPrefix(o.Vole, "/usr/local/") { | ||
| 183 | fmt.Fprint(&b, `# The command below runs /usr/local/bin/vole with | ||
| 184 | # /usr/local/etc/vole/vole.toml, the paths of a system install. A Homebrew | ||
| 185 | # install uses the prefix "brew --prefix" prints (/opt/homebrew on Apple | ||
| 186 | # Silicon): change both paths to match, or sshd will run a binary that is not | ||
| 187 | # there. | ||
| 188 | # | ||
| 189 | `) | ||
| 190 | } | ||
| 191 | fmt.Fprintf(&b, `# AuthorizedKeysCommandUser below names %s: the account that runs | ||
| 192 | # vole serve. Give the launchd job that name, or change this line to the account | ||
| 193 | # it uses, because sshd runs the roster lookup as it. | ||
| 194 | # | ||
| 195 | `, o.ServiceUser) | ||
| 196 | } else { | ||
| 197 | fmt.Fprint(&b, `# AuthorizedKeysCommandUser is the service account. | ||
| 198 | # | ||
| 199 | `) | ||
| 200 | } | ||
| 201 | fmt.Fprintf(&b, `# That account reads the roster and mints a session token. The forced command | ||
| 202 | # runs as %s, which has no access to the instance's data directory. | ||
| 203 | # AuthorizedKeysFile none means sshd never reads an authorized_keys file on this | ||
| 204 | # machine: the only keys it accepts are the ones Vole answers for. | ||
| 76 | 205 | ||
| 77 | 206 | Match User %s | |
| 78 | 207 | AuthorizedKeysFile none | |
| 79 | 208 | AuthorizedKeysCommand %s ssh-authorized-keys --config %s --fingerprint %%f --type %%t --key %%k --connection %%C | |
| 80 | AuthorizedKeysCommandUser vole | ||
| 209 | AuthorizedKeysCommandUser %s | ||
| 81 | 210 | PasswordAuthentication no | |
| 82 | 211 | KbdInteractiveAuthentication no | |
| 83 | 212 | DisableForwarding yes | |
| 84 | 213 | PermitTTY no | |
| 85 | 214 | PermitUserRC no | |
| 86 | `, o.User, o.User, o.Vole, o.Config) | ||
| 215 | `, o.User, o.User, o.Vole, o.Config, o.ServiceUser) | ||
| 87 | 216 | return b.String() | |
| 88 | 217 | } | |