authoravatarclover caruso<git@paperclover.net>2026-10-23 16:44:33-07:00
committeravatarclover caruso<git@paperclover.net>2026-10-24 19:01:23-07:00
log819edbefbe5ce363a1bc53de796344792271d6bc
treec0a652ac67573cf8fef56345e5db3016e3ff46ce
parent1df9a8f395115e6c9d25e0df369674e7b542f4d9
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

Publish the Knife web client behind Snow Globe sign-in

personal.knife.paperclover.net reaches Knife on the container's loopback through a host relay, so neither the container nor Knife restarts. Only infra-admin accounts pass the sign-in, and browsers still pair with Knife. Assisted-by: claude-opus-5.5

3 files changed, 37 insertions(+), 0 deletions(-)

nixos/knife-linux.nix+20
......@@ -15,10 +15,30 @@ let
1515 exec ${pkgs.podman}/bin/podman --root=${root}/containers/storage --runroot=/run/knife-linux/containers "$@"
1616 '';
1717 run = "${podman}/bin/knife-linux-podman";
18 web = "13773";
1819in
1920{
2021 environment.systemPackages = [ podman ];
2122
23 # Knife listens on the container's loopback; the router publishes this port behind
24 # Snow Globe sign-in, and Knife still requires its own paired session.
25 systemd.services.knife-linux-web = {
26 description = "Host port for the Knife web client";
27 wantedBy = [ "multi-user.target" "knife-linux.service" ];
28 bindsTo = [ "knife-linux.service" ];
29 after = [ "knife-linux.service" ];
30 serviceConfig = {
31 ExecStart = pkgs.writeShellScript "knife-linux-web" ''
32 pid=$(${run} inspect --format '{{.State.Pid}}' knife-linux)
33 exec ${pkgs.socat}/bin/socat TCP-LISTEN:${web},bind=127.0.0.1,fork,reuseaddr \
34 "EXEC:${pkgs.util-linux}/bin/nsenter --target=$pid --net ${pkgs.socat}/bin/socat STDIO TCP\:127.0.0.1\:3773"
35 '';
36 Restart = "always";
37 RestartSec = 5;
38 };
39 };
40 systemd.services.snowglobe-router.environment.SNOWGLOBE_KNIFE_PORT = web;
41
2242 systemd.services.knife-linux = {
2343 description = "The Knife Linux agent container";
2444 wantedBy = [ "multi-user.target" ];
tools/knife-linux.md+6
......@@ -17,6 +17,12 @@ agent. Image and unit changes apply at the next manual
1717last only until then, so add them to the Containerfile too. Devices cannot be
1818added to the running container.
1919
20`https://personal.knife.paperclover.net` serves the Knife web client behind Snow
21Globe sign-in for `infra-admin`. `knife-linux-web` relays host port 13773 into the
22container's loopback, so Knife still needs its own session: pair each browser
23once with `knife pair --label NAME` inside the container, then open the printed
24`/pair#token=…` path on that host.
25
2026| Container path | Host source |
2127| --- | --- |
2228| `/Volumes/Code` | the Mac VM's NFS export, `/srv/mac-studio-vm/sandbox` |
tools/router.py+11
......@@ -268,6 +268,17 @@ def render(token):
268268 route = routes.setdefault((listener, ""), {"upstreams": set(), "services": set()})
269269 route["upstreams"].add(upstream)
270270
271 knife_port = os.environ.get("SNOWGLOBE_KNIFE_PORT")
272 if knife_port is not None:
273 knife_host = "personal.knife." + os.environ["SNOWGLOBE_DOMAIN"]
274 if not knife_port.isdecimal() or not 1 <= int(knife_port) <= 65535 or not HOST.fullmatch(knife_host):
275 raise ValueError("invalid Knife route")
276 if (80, knife_host) in routes:
277 raise ValueError(f"Knife route conflicts with a Nomad service: {knife_host}")
278 routes[(80, knife_host)] = {"upstreams": {f"127.0.0.1:{int(knife_port)}"}, "services": {"knife-linux"},
279 "authRole": "infra-admin", "userHeader": None, "internal": False,
280 "realIp": False, "secureCookies": False}
281
271282 lines = []
272283 for (listener, host), route in sorted(routes.items()):
273284 if host: