| author | |
| committer | |
| log | 59743720de1d8d1697c6f6fdea004e2fee95eb00 |
| tree | ab2b0b3525e9eabe0c7c5267450f1ffbf12ff916 |
| parent | 1414ed2ad23a167f046ee7c037ea3266d356fcdd |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
A Tart VM whose only egress is a WireGuard tunnel to Snow Globe. Snow Globe
NATs it to the public internet, drops private ranges and port 25, and forwards
public SSH (2222) and Screen Sharing (5900) back through the tunnel, mapped on
the router by the existing public-ports unit.
Assisted-by: claude-sonnet-5.58 files changed, 171 insertions(+), 2 deletions(-)
config/ext-mantikafasi.json created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | { | |
| 2 | "guestAddress": "10.100.0.2", | |
| 3 | "gatewayAddress": "10.100.0.1", | |
| 4 | "wireguardPort": 51820, | |
| 5 | "snowglobePublicKey": "W1kcRxAkF7t/LRffd4vl9ocQgMYscaoEAHOKkBzXmGM=", | |
| 6 | "sshPort": 2222, | |
| 7 | "vncPort": 5900, | |
| 8 | "guestPublicKey": "+AgCUT7xu8BXYNEnH8nR+qa7P/8cA7+69NH4DPZ0Cxw=" | |
| 9 | } |
nixos/ext-mantikafasi.nix created+51| ... | ... | @@ -0,0 +1,51 @@ |
| 1 | { ... }: | |
| 2 | let | |
| 3 | box = builtins.fromJSON (builtins.readFile ../config/ext-mantikafasi.json); | |
| 4 | keys = "/var/lib/snowglobe/ext-mantikafasi"; | |
| 5 | # The guest reaches the internet only through Snow Globe, never the networks behind it. | |
| 6 | privateRanges = [ "10.0.0.0/8" "172.16.0.0/12" "192.168.0.0/16" "100.64.0.0/10" "169.254.0.0/16" ]; | |
| 7 | in | |
| 8 | { | |
| 9 | networking.wireguard.interfaces.wg-ext = { | |
| 10 | ips = [ "${box.gatewayAddress}/24" ]; | |
| 11 | listenPort = box.wireguardPort; | |
| 12 | mtu = 1200; | |
| 13 | privateKeyFile = "${keys}/wg.key"; | |
| 14 | peers = [{ | |
| 15 | publicKey = box.guestPublicKey; | |
| 16 | presharedKeyFile = "${keys}/wg.psk"; | |
| 17 | allowedIPs = [ "${box.guestAddress}/32" ]; | |
| 18 | }]; | |
| 19 | }; | |
| 20 | ||
| 21 | networking.firewall.interfaces.tailscale0.allowedUDPPorts = [ box.wireguardPort ]; | |
| 22 | ||
| 23 | networking.nat = { | |
| 24 | enable = true; | |
| 25 | externalInterface = "enp4s0"; | |
| 26 | internalInterfaces = [ "wg-ext" ]; | |
| 27 | forwardPorts = [ | |
| 28 | { sourcePort = box.sshPort; destination = "${box.guestAddress}:22"; proto = "tcp"; } | |
| 29 | { sourcePort = box.vncPort; destination = "${box.guestAddress}:5900"; proto = "tcp"; } | |
| 30 | ]; | |
| 31 | }; | |
| 32 | ||
| 33 | networking.firewall.extraCommands = '' | |
| 34 | iptables -N ext-mantikafasi 2>/dev/null || iptables -F ext-mantikafasi | |
| 35 | iptables -A ext-mantikafasi -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT | |
| 36 | ${builtins.concatStringsSep "\n" (map (range: "iptables -A ext-mantikafasi -d ${range} -j DROP") privateRanges)} | |
| 37 | iptables -A ext-mantikafasi -p tcp --dport 25 -j DROP | |
| 38 | iptables -A ext-mantikafasi -j ACCEPT | |
| 39 | iptables -I FORWARD -i wg-ext -j ext-mantikafasi | |
| 40 | iptables -t mangle -A FORWARD -o wg-ext -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu | |
| 41 | iptables -t mangle -A FORWARD -i wg-ext -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu | |
| 42 | iptables -I nixos-fw 1 -i wg-ext -j DROP | |
| 43 | ''; | |
| 44 | networking.firewall.extraStopCommands = '' | |
| 45 | iptables -D FORWARD -i wg-ext -j ext-mantikafasi 2>/dev/null || true | |
| 46 | iptables -F ext-mantikafasi 2>/dev/null || true | |
| 47 | iptables -X ext-mantikafasi 2>/dev/null || true | |
| 48 | iptables -t mangle -D FORWARD -o wg-ext -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu 2>/dev/null || true | |
| 49 | iptables -t mangle -D FORWARD -i wg-ext -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu 2>/dev/null || true | |
| 50 | ''; | |
| 51 | } |
nixos/snowglobe.nix+3-2| ... | ... | @@ -7,6 +7,7 @@ let |
| 7 | 7 | xmppUDPPorts = [ xmppNetwork.turn xmppNetwork.turn_tls ]; |
| 8 | 8 | irohNetwork = builtins.fromJSON (builtins.readFile ../service/iroh-relay/network.json); |
| 9 | 9 | spacebarVoice = builtins.fromJSON (builtins.readFile ../service/spacebar/voice-network.json); |
| 10 | extMantikafasi = builtins.fromJSON (builtins.readFile ../config/ext-mantikafasi.json); | |
| 10 | 11 | udpPorts = xmppUDPPorts ++ [ irohNetwork.quic spacebarVoice.media spacebarVoice.nativeMedia ]; |
| 11 | 12 | encryptionRoots = { |
| 12 | 13 | clover = "clover"; |
| ... | ... | @@ -17,7 +18,7 @@ let |
| 17 | 18 | }; |
| 18 | 19 | in |
| 19 | 20 | { |
| 20 | imports = [ ./snowglobe-network.nix ./mac-studio-sandbox.nix ./knife-linux.nix ./mac-vm.nix ./vm-disks.nix ./zfs-read-cache.nix ./gpu-unlock.nix ]; | |
| 21 | imports = [ ./snowglobe-network.nix ./mac-studio-sandbox.nix ./knife-linux.nix ./mac-vm.nix ./ext-mantikafasi.nix ./vm-disks.nix ./zfs-read-cache.nix ./gpu-unlock.nix ]; | |
| 21 | 22 | |
| 22 | 23 | networking.hostName = "snowglobe"; |
| 23 | 24 | environment.etc."machine-info".text = '' |
| ... | ... | @@ -86,7 +87,7 @@ in |
| 86 | 87 | script = '' |
| 87 | 88 | description="$(${pkgs.python3}/bin/python3 ${./upnp-discover.py} ${lib.escapeShellArg config.networking.defaultGateway.address})" |
| 88 | 89 | exec ${pkgs.miniupnpc}/bin/upnpc -u "$description" -e "Snow Globe services" -r \ |
| 89 | ${lib.concatMapStringsSep " " (port: "${toString port} TCP") xmppTCPPorts} \ | |
| 90 | ${lib.concatMapStringsSep " " (port: "${toString port} TCP") (xmppTCPPorts ++ [ extMantikafasi.sshPort extMantikafasi.vncPort ])} \ | |
| 90 | 91 | ${lib.concatMapStringsSep " " (port: "${toString port} UDP") (udpPorts ++ lib.range xmppNetwork.relay_first xmppNetwork.relay_last)} |
| 91 | 92 | ''; |
| 92 | 93 | }; |
tools/ext-mantikafasi.md created+34| ... | ... | @@ -0,0 +1,34 @@ |
| 1 | # ext-mantikafasi | |
| 2 | ||
| 3 | `ext-mantikafasi` is a macOS 15 Tart VM (cloned from Cirrus's `macos-sequoia-base`, 8 vCPU, 16 GiB, | |
| 4 | 100 GB) for someone outside the house who has no Mac. It is reachable from the internet through Snow | |
| 5 | Globe and cannot reach anything on the LAN. Its Tart home, `private/ext-mantikafasi`, holds the | |
| 6 | account password (`password`), the WireGuard keys, and `run.log`. | |
| 7 | ||
| 8 | ``` | |
| 9 | internet ──UPnP──> Snow Globe :2222 ─DNAT─> 10.100.0.2:22 (sshd) | |
| 10 | Snow Globe :5900 ─DNAT─> 10.100.0.2:5900 (Screen Sharing, Apple ARD login) | |
| 11 | │ wg-ext 10.100.0.1 ▲ WireGuard over the tailnet, UDP 51820 on tailscale0 | |
| 12 | ▼ │ | |
| 13 | Mac NAT ── Softnet (only 100.64.0.1/32 allowed) ── guest utun 10.100.0.2 | |
| 14 | ``` | |
| 15 | ||
| 16 | - **Why a tunnel:** Tart's NAT on this Mac only leaves through Tailscale, so a guest otherwise has no internet. | |
| 17 | Softnet lets the guest reach exactly Snow Globe's tailnet address; WireGuard (`ext-mantikafasi/up`, started by a | |
| 18 | LaunchDaemon) carries all its traffic to Snow Globe, which NATs it out. Inbound SSH and VNC ride the same | |
| 19 | tunnel, so the Mac needs no listeners and no host-to-guest route. | |
| 20 | - **Isolation:** the guest is root on its own box but is enforced from outside it. Softnet limits what leaves | |
| 21 | the Mac; `nixos/ext-mantikafasi.nix` drops new connections from `wg-ext` to `10.0.0.0/8`, `172.16.0.0/12`, | |
| 22 | `192.168.0.0/16`, `100.64.0.0/10`, `169.254.0.0/16` and to port 25, and refuses all traffic to Snow Globe itself. | |
| 23 | The guest's egress address is Snow Globe's public one. | |
| 24 | - **Ports:** `config/ext-mantikafasi.json` owns the public ports; the `public-ports` unit maps them on the | |
| 25 | router. VNC is unencrypted past login, so tell the user to tunnel it: | |
| 26 | `ssh -p 2222 -L 5900:localhost:5900 admin@snowglobe.paperclover.net`, then connect to `localhost:5900`. | |
| 27 | - **Run it:** `runtime/control/start-ext-mantikafasi` (copy of `ext-mantikafasi/start`) starts it; the | |
| 28 | `net.paperclover.ext-mantikafasi-revive` LaunchAgent restarts it every 30 s unless | |
| 29 | `private/ext-mantikafasi/stopped` exists (`tart stop` plus `touch` that file to stop it on purpose; `start` clears it). | |
| 30 | Softnet cuts the Mac off from the guest, so maintain it over the public SSH port or `tart exec`. | |
| 31 | - **Guest files:** `ext-mantikafasi/{up,net.paperclover.ext-wg.plist}` install to `/usr/local/libexec/ext-wg/` | |
| 32 | and `/Library/LaunchDaemons`; the WireGuard config with the private key is `/etc/ext-wg.conf`. `wireguard-go` | |
| 33 | and `wg` were built with nix for aarch64-darwin. Snow Globe's side of the keys is `/var/lib/snowglobe/ext-mantikafasi/`. | |
| 34 | - **macOS VM limit:** Apple allows two macOS guests at once; `gui-agent` is the other, so `m3-phoenix-box` stays stopped. |
tools/ext-mantikafasi/net.paperclover.ext-mantikafasi-revive.plist created+32| ... | ... | @@ -0,0 +1,32 @@ |
| 1 | <?xml version="1.0" encoding="UTF-8"?> | |
| 2 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| 3 | <plist version="1.0"> | |
| 4 | <dict> | |
| 5 | 	<key>Label</key> | |
| 6 | 	<string>net.paperclover.ext-mantikafasi-revive</string> | |
| 7 | 	<key>ProgramArguments</key> | |
| 8 | 	<array> | |
| 9 | 		<string>/usr/bin/ssh</string> | |
| 10 | 		<string>-F</string> | |
| 11 | 		<string>/dev/null</string> | |
| 12 | 		<string>-i</string> | |
| 13 | 		<string>/Users/clo/.ssh/vm-localhost</string> | |
| 14 | 		<string>-o</string> | |
| 15 | 		<string>IdentitiesOnly=yes</string> | |
| 16 | 		<string>-o</string> | |
| 17 | 		<string>BatchMode=yes</string> | |
| 18 | 		<string>-o</string> | |
| 19 | 		<string>ConnectTimeout=10</string> | |
| 20 | 		<string>localhost</string> | |
| 21 | 		<string>'/Volumes/Documents/VM/macOS Code Sandbox/runtime/control/start-ext-mantikafasi' revive</string> | |
| 22 | 	</array> | |
| 23 | 	<key>RunAtLoad</key> | |
| 24 | 	<true/> | |
| 25 | 	<key>StandardErrorPath</key> | |
| 26 | 	<string>/Users/clo/Library/Logs/ext-mantikafasi-revive.log</string> | |
| 27 | 	<key>StandardOutPath</key> | |
| 28 | 	<string>/Users/clo/Library/Logs/ext-mantikafasi-revive.log</string> | |
| 29 | 	<key>StartInterval</key> | |
| 30 | 	<integer>30</integer> | |
| 31 | </dict> | |
| 32 | </plist> |
tools/ext-mantikafasi/net.paperclover.ext-wg.plist created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | <?xml version="1.0" encoding="UTF-8"?> | |
| 2 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| 3 | <plist version="1.0"><dict> | |
| 4 | <key>Label</key><string>net.paperclover.ext-wg</string> | |
| 5 | <key>ProgramArguments</key><array><string>/usr/local/libexec/ext-wg/up</string></array> | |
| 6 | <key>RunAtLoad</key><true/> | |
| 7 | <key>KeepAlive</key><true/> | |
| 8 | <key>StandardErrorPath</key><string>/var/log/ext-wg.log</string> | |
| 9 | </dict></plist> |
tools/ext-mantikafasi/start created+15| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | #!/bin/bash | |
| 2 | # Starts ext-mantikafasi headless. Softnet leaves the guest only Snow Globe's tailnet address, which carries its WireGuard tunnel. | |
| 3 | # `revive` (the LaunchAgent) starts it only when its runner is gone and nothing stopped it on purpose. | |
| 4 | set -euo pipefail | |
| 5 | ROOT="/Volumes/Documents/VM/macOS Code Sandbox" | |
| 6 | STOPPED="$ROOT/private/ext-mantikafasi/stopped" | |
| 7 | LOG="$ROOT/private/ext-mantikafasi/run.log" | |
| 8 | if [ "${1:-}" = revive ] && [ -e "$STOPPED" ]; then exit 0; fi | |
| 9 | if pgrep -f "tart run ext-mantikafasi" >/dev/null; then exit 0; fi | |
| 10 | if [ "${1:-}" = revive ]; then echo "$(date): ext-mantikafasi is down, starting"; fi | |
| 11 | rm -f "$STOPPED" | |
| 12 | : > "$LOG" | |
| 13 | chmod 600 "$LOG" | |
| 14 | # Closing an agent session kills its children, so sshd must own the VM. The loopback-only key works while the screen is locked. | |
| 15 | ssh -F /dev/null -i "$HOME/.ssh/vm-localhost" -o IdentitiesOnly=yes -o BatchMode=yes -o ConnectTimeout=10 localhost "nohup /usr/bin/env PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin TART_HOME='$ROOT/state' /usr/bin/caffeinate -i '$ROOT/runtime/tart.app/Contents/MacOS/tart' run ext-mantikafasi --no-graphics --no-audio --no-usb-accessories --no-clipboard --suspendable --net-softnet --net-softnet-block=0.0.0.0/0 --net-softnet-allow=100.64.0.1/32 >'$LOG' 2>&1 </dev/null &" |
tools/ext-mantikafasi/up created+18| ... | ... | @@ -0,0 +1,18 @@ |
| 1 | #!/bin/sh | |
| 2 | # Brings up the tunnel to Snow Globe, the guest's only way off this Mac. | |
| 3 | set -eu | |
| 4 | D=/usr/local/libexec/ext-wg | |
| 5 | gw=$(route -n get default | awk '/gateway:/ {print $2}') | |
| 6 | rm -f /var/run/ext-wg.name | |
| 7 | WG_TUN_NAME_FILE=/var/run/ext-wg.name "$D/wireguard-go" -f utun & | |
| 8 | pid=$! | |
| 9 | trap 'kill $pid' TERM INT | |
| 10 | until [ -s /var/run/ext-wg.name ]; do sleep 0.2; done | |
| 11 | if=$(cat /var/run/ext-wg.name) | |
| 12 | "$D/wg" setconf "$if" /etc/ext-wg.conf | |
| 13 | ifconfig "$if" inet 10.100.0.2 10.100.0.2 netmask 255.255.255.255 mtu 1200 up | |
| 14 | route -q -n add -host 100.64.0.1 "$gw" | |
| 15 | route -q -n add -inet 10.100.0.0/24 -interface "$if" | |
| 16 | route -q -n add -inet 0.0.0.0/1 -interface "$if" | |
| 17 | route -q -n add -inet 128.0.0.0/1 -interface "$if" | |
| 18 | wait $pid |