From 819edbefbe5ce363a1bc53de796344792271d6bc Mon Sep 17 00:00:00 2001 From: clover caruso Date: Fri, 23 Oct 2026 16:44:33 -0700 Subject: [PATCH] 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 --- nixos/knife-linux.nix | 20 ++++++++++++++++++++ tools/knife-linux.md | 6 ++++++ tools/router.py | 11 +++++++++++ 3 files changed, 37 insertions(+) diff --git a/nixos/knife-linux.nix b/nixos/knife-linux.nix index e74671c9f08d21ff968ad086fda9570ec46aec5b..1abcf1b63b0e0f988799a98eb0f7a4316783bfbe 100644 --- a/nixos/knife-linux.nix +++ b/nixos/knife-linux.nix @@ -15,10 +15,30 @@ let exec ${pkgs.podman}/bin/podman --root=${root}/containers/storage --runroot=/run/knife-linux/containers "$@" ''; run = "${podman}/bin/knife-linux-podman"; + web = "13773"; in { environment.systemPackages = [ podman ]; + # Knife listens on the container's loopback; the router publishes this port behind + # Snow Globe sign-in, and Knife still requires its own paired session. + systemd.services.knife-linux-web = { + description = "Host port for the Knife web client"; + wantedBy = [ "multi-user.target" "knife-linux.service" ]; + bindsTo = [ "knife-linux.service" ]; + after = [ "knife-linux.service" ]; + serviceConfig = { + ExecStart = pkgs.writeShellScript "knife-linux-web" '' + pid=$(${run} inspect --format '{{.State.Pid}}' knife-linux) + exec ${pkgs.socat}/bin/socat TCP-LISTEN:${web},bind=127.0.0.1,fork,reuseaddr \ + "EXEC:${pkgs.util-linux}/bin/nsenter --target=$pid --net ${pkgs.socat}/bin/socat STDIO TCP\:127.0.0.1\:3773" + ''; + Restart = "always"; + RestartSec = 5; + }; + }; + systemd.services.snowglobe-router.environment.SNOWGLOBE_KNIFE_PORT = web; + systemd.services.knife-linux = { description = "The Knife Linux agent container"; wantedBy = [ "multi-user.target" ]; diff --git a/tools/knife-linux.md b/tools/knife-linux.md index 959c2bf1e30420732abf7c53d56ead7b0776e6b9..0e42be1614fbed93e00eb92509bfb4bbb215d0ba 100644 --- a/tools/knife-linux.md +++ b/tools/knife-linux.md @@ -17,6 +17,12 @@ agent. Image and unit changes apply at the next manual last only until then, so add them to the Containerfile too. Devices cannot be added to the running container. +`https://personal.knife.paperclover.net` serves the Knife web client behind Snow +Globe sign-in for `infra-admin`. `knife-linux-web` relays host port 13773 into the +container's loopback, so Knife still needs its own session: pair each browser +once with `knife pair --label NAME` inside the container, then open the printed +`/pair#token=…` path on that host. + | Container path | Host source | | --- | --- | | `/Volumes/Code` | the Mac VM's NFS export, `/srv/mac-studio-vm/sandbox` | diff --git a/tools/router.py b/tools/router.py index 113adcfb37a50a2b7b3277ac696a21a991be5306..b6e3c5eb689c7a9a4b6e707b8865825e160fd507 100644 --- a/tools/router.py +++ b/tools/router.py @@ -268,6 +268,17 @@ def render(token): route = routes.setdefault((listener, ""), {"upstreams": set(), "services": set()}) route["upstreams"].add(upstream) + knife_port = os.environ.get("SNOWGLOBE_KNIFE_PORT") + if knife_port is not None: + knife_host = "personal.knife." + os.environ["SNOWGLOBE_DOMAIN"] + if not knife_port.isdecimal() or not 1 <= int(knife_port) <= 65535 or not HOST.fullmatch(knife_host): + raise ValueError("invalid Knife route") + if (80, knife_host) in routes: + raise ValueError(f"Knife route conflicts with a Nomad service: {knife_host}") + routes[(80, knife_host)] = {"upstreams": {f"127.0.0.1:{int(knife_port)}"}, "services": {"knife-linux"}, + "authRole": "infra-admin", "userHeader": None, "internal": False, + "realIp": False, "secureCookies": False} + lines = [] for (listener, host), route in sorted(routes.items()): if host: -- 2.54.1