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...@@ -15,10 +15,30 @@ let
15 exec ${pkgs.podman}/bin/podman --root=${root}/containers/storage --runroot=/run/knife-linux/containers "$@"15 exec ${pkgs.podman}/bin/podman --root=${root}/containers/storage --runroot=/run/knife-linux/containers "$@"
16 '';16 '';
17 run = "${podman}/bin/knife-linux-podman";17 run = "${podman}/bin/knife-linux-podman";
18 web = "13773";
18in19in
19{20{
20 environment.systemPackages = [ podman ];21 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
22 systemd.services.knife-linux = {42 systemd.services.knife-linux = {
23 description = "The Knife Linux agent container";43 description = "The Knife Linux agent container";
24 wantedBy = [ "multi-user.target" ];44 wantedBy = [ "multi-user.target" ];
tools/knife-linux.md+6
...@@ -17,6 +17,12 @@ agent. Image and unit changes apply at the next manual...@@ -17,6 +17,12 @@ agent. Image and unit changes apply at the next manual
17last only until then, so add them to the Containerfile too. Devices cannot be17last only until then, so add them to the Containerfile too. Devices cannot be
18added to the running container.18added 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
20| Container path | Host source |26| Container path | Host source |
21| --- | --- |27| --- | --- |
22| `/Volumes/Code` | the Mac VM's NFS export, `/srv/mac-studio-vm/sandbox` |28| `/Volumes/Code` | the Mac VM's NFS export, `/srv/mac-studio-vm/sandbox` |
tools/router.py+11
...@@ -268,6 +268,17 @@ def render(token):...@@ -268,6 +268,17 @@ def render(token):
268 route = routes.setdefault((listener, ""), {"upstreams": set(), "services": set()})268 route = routes.setdefault((listener, ""), {"upstreams": set(), "services": set()})
269 route["upstreams"].add(upstream)269 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
271 lines = []282 lines = []
272 for (listener, host), route in sorted(routes.items()):283 for (listener, host), route in sorted(routes.items()):
273 if host:284 if host: