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.

scripts/check-deploy.py +121−10

@@ -51,6 +51,12 @@ SAMPLE = {
51 51 "runner_tmpfs": "1G",
52 52 "runner_disk_reserve": "2G",
53 53 "runner_labels": "--label linux --label amd64",
54 # The SSH port the templates render. 2222 is the built-in listener; 22 is the
55 # sshd front door, and then the derived values are empty so nothing names a
56 # port. check_front_door_flavour renders both.
57 "ssh_port": "2222",
58 "ssh_url_port": ":2222",
59 "ssh_scan_args": "-p 2222",
54 60 }
55 61
56 62 # What each template has to produce. The files are the contract between the
@@ -113,15 +119,17 @@ def placeholder_lists():
113 119 return lists
114 120
115 121
116 def render(template, names):
117 missing = [n for n in names if n not in SAMPLE]
122 def render(template, names, overrides=None):
123 values = dict(SAMPLE)
124 values.update(overrides or {})
125 missing = [n for n in names if n not in values]
118 126 if missing:
119 127 raise SystemExit(f"render.sh names placeholders with no sample value: {missing}")
120 128 path = os.path.join(DEPLOY, "cloud-init", template)
121 129 with open(path, encoding="utf-8") as f:
122 130 text = f.read()
123 131 for name in names:
124 text = text.replace("${" + name + "}", SAMPLE[name])
132 text = text.replace("${" + name + "}", values[name])
125 133 return text
126 134
127 135
@@ -208,7 +216,7 @@ def check_runner_template(names):
208 216 args = [line for line in env.splitlines() if line.startswith("VOLE_RUNNER_ARGS=")]
209 217 if len(args) != 1:
210 218 return fail("runner.env must set VOLE_RUNNER_ARGS exactly once", where)
211 if f"--remote ssh://git@{SAMPLE['forge_host']}:2222" not in args[0]:
219 if f"--remote ssh://git@{SAMPLE['forge_host']}{SAMPLE['ssh_url_port']}" not in args[0]:
212 220 bad |= fail("VOLE_RUNNER_ARGS does not point at the instance", where)
213 221 if SAMPLE["runner_labels"] not in args[0]:
214 222 bad |= fail("VOLE_RUNNER_ARGS does not carry the labels", where)
@@ -287,17 +295,118 @@ def check_sh(text, where):
287 295 return 0
288 296
289 297
298 def check_front_door_flavour(lists):
299 """SSH_PORT=22 is the sshd front door: nothing rendered may name a port.
300
301 A leftover :2222 is the failure this check exists for. It is not a typo a
302 reader catches: a runner pinning a port nobody listens on fails its first
303 lease, and a clone URL with the wrong port fails at the first push.
304 """
305 bad = 0
306 overrides = {"ssh_port": "22", "ssh_url_port": "", "ssh_scan_args": ""}
307 where = "deploy/cloud-init (SSH_PORT=22)"
308 for template, names in lists.items():
309 rendered = render(template, names, overrides)
310 if ":2222" in rendered or "2222" in rendered:
311 bad |= fail(f"{template} still names 2222 with SSH_PORT=22", where)
312
313 if "runner.yaml" in lists:
314 runner = render("runner.yaml", lists["runner.yaml"], overrides)
315 if f"--remote ssh://git@{SAMPLE['forge_host']} " not in runner:
316 bad |= fail("the runner's remote keeps a port with SSH_PORT=22", where)
317 if 'ssh-keyscan -T 5 "$FORGE_HOST"' not in runner.replace(" ", " "):
318 bad |= fail("the runner still scans a port with SSH_PORT=22", where)
319
320 if "vole.yaml" in lists:
321 vole = render("vole.yaml", lists["vole.yaml"], overrides)
322 if 'ssh_addr = "0.0.0.0:22"' not in vole:
323 bad |= fail("the forge does not answer on sshd's port with SSH_PORT=22", where)
324 if f"ssh://git@{SAMPLE['hostname']}/" not in vole:
325 bad |= fail("the clone URL still carries a port with SSH_PORT=22", where)
326 return bad
327
328
329 def check_front_door_package():
330 """The package ships the front door and does not install it.
331
332 Three files have to agree across a package boundary: the account postinstall
333 creates, the shell it is given, and the Match block the drop-in carries. A
334 machine with any two of them is a forge nobody can push to, and the failure
335 shows up as an authentication error in sshd's log rather than as a package
336 problem.
337 """
338 bad = 0
339 where = "packaging/nfpm.yaml"
340 package = read("packaging/nfpm.yaml")
341 for src, dst in (
342 ("packaging/sshd/vole.conf", "/usr/share/vole/sshd/vole.conf"),
343 ("packaging/sshd/ssh-shell", "/usr/lib/vole/ssh-shell"),
344 ("packaging/systemd/vole.tmpfiles", "/usr/lib/tmpfiles.d/vole.conf"),
345 ):
346 if not os.path.exists(os.path.join(ROOT, src)):
347 bad |= fail("missing", src)
348 continue
349 if f"src: {src}" not in package or f"dst: {dst}" not in package:
350 bad |= fail(f"{src} is not shipped as {dst}", where)
351 if "dst: /etc/ssh" in package:
352 bad |= fail("the package writes into /etc/ssh; enabling sshd is the operator's decision", where)
353
354 post = read("packaging/scripts/postinstall.sh")
355 for needed in ("/usr/lib/vole/ssh-shell", 'install -d -o vole -g "$SSH_ACCOUNT" -m 2770 /run/vole',
356 "usermod -aG"):
357 if needed not in post:
358 bad |= fail(f"the postinstall never mentions {needed!r}", "packaging/scripts/postinstall.sh")
359 # One account name, four files: postinstall creates it, tmpfiles gives
360 # /run/vole its group, the unit gets that group, and the drop-in matches it.
361 # A name that drifts in one of them is a forge nobody can push to.
362 account = re.search(r"^SSH_ACCOUNT=(\S+)$", post, re.MULTILINE)
363 if not account:
364 bad |= fail("the postinstall does not name the account it creates",
365 "packaging/scripts/postinstall.sh")
366 return bad
367 account = account.group(1)
368
369 tmpfiles = read("packaging/systemd/vole.tmpfiles")
370 if f"d /run/vole 2770 vole {account} -" not in tmpfiles:
371 bad |= fail(f"does not create /run/vole with group {account}",
372 "packaging/systemd/vole.tmpfiles")
373
374 unit = read("packaging/systemd/vole.service")
375 for needed in (f"SupplementaryGroups={account}", "ReadWritePaths=/run/vole"):
376 if needed not in unit:
377 bad |= fail(f"the unit does not set {needed}", "packaging/systemd/vole.service")
378
379 dropin = read("packaging/sshd/vole.conf")
380 if f"Match User {account}" not in dropin:
381 bad |= fail(f"the drop-in does not match the account {account} the package creates",
382 "packaging/sshd/vole.conf")
383 if "AuthorizedKeysCommandUser vole" not in dropin:
384 bad |= fail("the drop-in runs the auth command as the wrong account", "packaging/sshd/vole.conf")
385 return bad
386
387
290 388 def check_scripts():
389 """Every shell script that runs as root or as a login shell must parse.
390
391 render.sh is run by whoever deploys, postinstall.sh by the package manager as
392 root on every install and upgrade, and ssh-shell by sshd as the account it is
393 the shell of. A syntax error in any of them is discovered at the worst moment,
394 so `sh -n` here costs nothing.
395 """
291 396 bad = 0
292 for rel in ("cloud-init/render.sh",):
293 path = os.path.join(DEPLOY, rel)
397 for rel, executable in (
398 ("deploy/cloud-init/render.sh", True),
399 ("packaging/scripts/postinstall.sh", False),
400 ("packaging/sshd/ssh-shell", True),
401 ):
402 path = os.path.join(ROOT, rel)
294 403 if not os.path.exists(path):
295 bad |= fail("missing", f"deploy/{rel}")
404 bad |= fail("missing", rel)
296 405 continue
297 if not os.access(path, os.X_OK):
298 bad |= fail("is not executable", f"deploy/{rel}")
406 if executable and not os.access(path, os.X_OK):
407 bad |= fail("is not executable", rel)
299 408 with open(path, encoding="utf-8") as f:
300 bad |= check_sh(f.read(), f"deploy/{rel}")
409 bad |= check_sh(f.read(), rel)
301 410 return bad
302 411
303 412
@@ -317,6 +426,8 @@ def main():
317 426 if "runner.yaml" in lists:
318 427 bad |= check_runner_template(lists["runner.yaml"])
319 428
429 bad |= check_front_door_flavour(lists)
430 bad |= check_front_door_package()
320 431 bad |= check_scripts()
321 432 return 1 if bad else 0
322 433