From 7e80d37986d767a03d76815f7782be8c8cb8b7ca Mon Sep 17 00:00:00 2001 From: David Young Date: Tue, 17 Nov 2026 14:22:26 -0700 Subject: [PATCH] Plan: find storage and AI servers on the tailnet, not only over mDNS configure storage and configure ai-servers find machines only over mDNS, which stays on the LAN, so a laptop away from home finds nothing. This skill holds the plan for also looking at the Core's tailnet: a lib/tailnet.sh helper, probing tailnet peers in find_servers and find_storage, listing a machine found both ways once, tests, and what to check against headscale (MagicDNS, Online, the agent sandbox). Nothing is built yet. Written from the MiniServer session, which now runs Tailscale and joins the Core's headscale. Co-Authored-By: Claude Opus 5.5 --- .../coredesktop-tailnet-discovery/SKILL.md | 172 ++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 .claude/skills/coredesktop-tailnet-discovery/SKILL.md diff --git a/.claude/skills/coredesktop-tailnet-discovery/SKILL.md b/.claude/skills/coredesktop-tailnet-discovery/SKILL.md new file mode 100644 index 0000000..0bf460b --- /dev/null +++ b/.claude/skills/coredesktop-tailnet-discovery/SKILL.md @@ -0,0 +1,172 @@ +--- +name: coredesktop-tailnet-discovery +description: Plan and progress for making configure storage and configure ai-servers find servers on the Core's tailnet (Tailscale/headscale) as well as over mDNS, so a laptop away from home still finds the MiniServer and the LLM box. Use when resuming, continuing, checking the status of, or changing tailnet discovery, configure.d/lib/tailnet.sh, find_storage or find_servers. +--- + +# Find servers on the tailnet, not only the LAN + +## Where things stand + +This plan was written on 2026-11-17 from the MiniServer session, against +CoreDesktop `ffbaf71`. Nothing in it was built then. Check before starting: + +``` +git -C ~/Projects/coredesktop fetch && git -C ~/Projects/coredesktop log --oneline origin/main -10 +ls ~/Projects/coredesktop/configure.d/lib/tailnet.sh 2>/dev/null +grep -n 'tailnet' ~/Projects/coredesktop/configure.d/50-ai-servers.sh ~/Projects/coredesktop/configure.d/60-storage.sh +``` + +Map what you find onto the steps below, tell the user which step is next, and +confirm before starting it. + +## Why + +`configure storage` and `configure ai-servers` find machines only over mDNS +(`configure.d/lib/mdns.sh`, Avahi). mDNS is multicast and stays on the LAN: +Tailscale carries no multicast, so a laptop at a café, or a Core's machines in +different places, see nothing. + +MiniServer (`~/Projects/MiniServer`, commit `fb1b6e1`) now runs Tailscale and +joins the Core's headscale with `configure tailscale`, the same way +CoreDesktop's `configure.d/15-tailscale.sh` does +(`--login-server https://headscale.`). Its firewalld rules +(`firewall.conf`) apply on tailscale0 as on the LAN, so what it allows (SSH and +SFTP on 22, Cockpit on 9090, listed ports) is what a tailnet peer can reach. +MiniServer also advertises `_ssh._tcp`, `_sftp-ssh._tcp` and `_https._tcp` +over mDNS, which CoreDesktop's `find_storage` already picks up on the LAN. + +## What exists today (at ffbaf71) + +- `configure.d/lib/mdns.sh`: `mdns_services` ("name|type|host|address|port|txt"), + `mdns_hosts` (other machines' `.local` names), `mdns_own_host`. +- `configure.d/50-ai-servers.sh`: + - `is_installed` is `command -v avahi-browse`. + - `find_servers` probes every `mdns_hosts` entry on `LLM_PORTS` + (11434 1234 8080 8000) in parallel with `server_models` (`curl /v1/models`), + printing "host:port|model count". + - `sandbox_allow host:port` adds the server to the agents' `allowedDomains`. +- `configure.d/60-storage.sh`: + - `find_storage` prints "kind|host|name" for `_smb._tcp` and `_sftp-ssh._tcp`. + - `find_and_add` lists them as `%-26s` host plus kind, then calls `add_ host`. + - `mount_point` and `add_sftp`'s label strip only `.local` from the host. +- `configure.d/15-tailscale.sh`: `joined()` checks `TAILSCALE_DOMAIN` and + `tailscale status --json` `.BackendState == "Running"`. +- `tests/network.bats` stubs avahi-browse (machines `llm`, `basement` = this + machine, `pi-star`, `lab`), curl and smbclient. + +## Steps + +### 1. `configure.d/lib/tailnet.sh` + +```bash +#!/bin/bash +# +# Purpose : Find the other machines on the Core's tailnet, for the configure.d +# items that find servers (storage, ai-servers) beyond the LAN that +# mDNS reaches. Source this file. + +# The other online computers on the tailnet, one MagicDNS name per line +# (box.tail.example). Phones and tablets are left out: nobody serves files or +# models from them, and each one costs a probe. Nothing if Tailscale isn't +# installed or running. +tailnet_hosts() { + command -v tailscale > /dev/null || return 0 + tailscale status --json 2> /dev/null \ + | jq -r 'select(.BackendState == "Running") | .Peer // {} | .[] + | select(.Online) + | select(.OS | IN("linux", "macOS", "windows", "freebsd")) + | .DNSName | rtrimstr(".") | select(. != "")' 2> /dev/null \ + | sort -u +} + +# true if host $1 takes TCP connections on port $2 within 2 seconds +port_open() { + timeout 2 bash -c ': < "/dev/tcp/$1/$2"' 2> /dev/null +} + +# The name to show and to use in paths: box.tail.example -> box, box.local -> box +short_host() { + echo "${1%%.*}" +} +``` + +### 2. `configure ai-servers` + +- `find_servers`: loop over `mdns_hosts` and `tailnet_hosts` together (after + the de-duplication in step 4). The parallel probing is unchanged. +- `is_installed`: true if `avahi-browse` **or** `tailscale` is there. +- The intro/"nothing found" text: mention that servers on the Core's network + (Tailscale) are looked for too, or that `configure tailscale` would let it + find them away from home. +- `sandbox_allow` needs nothing new if a tailnet name works in + `allowedDomains` (see "To verify"). + +### 3. `configure storage` + +- `find_storage`: after the mDNS results, probe each tailnet host in parallel: + + ```bash + for host in $(tailnet_hosts); do + ( port_open "$host" 22 && echo "sftp|$host|$(short_host "$host")" + port_open "$host" 445 && echo "smb|$host|$(short_host "$host")" ) & + done + wait + ``` + + Keep the overall `| sort -u`. +- `mount_point` and `add_sftp`'s Files label: use `short_host` instead of + `${1%.local}`, so a tailnet server mounts at `/mnt/box`, not + `/mnt/box.tail.example`. Existing `.local` mounts keep their paths, since + `short_host box.local` is also `box`. +- `find_and_add`: say where each was found, e.g. `box (Tailscale)`; widen or + drop the `%-26s` column if tailnet names don't fit. +- A port answering on 22 isn't proof of SFTP, but `add_sftp` already checks the + key over ssh and says what's wrong, so that's enough. + +### 4. One machine found both ways + +A MiniServer on the LAN appears as `box.local` (mDNS) and `box.tail.example` +(Tailscale). **Recommended:** list it once, by its tailnet name, since that +keeps working when the laptop leaves home and Tailscale connects directly on +the same LAN. Match on `short_host`, case-insensitively. **This is the +user's call; ask before building it.** The other option is to keep both and +let the user pick. + +### 5. Tests in `tests/network.bats` + +Stub `tailscale` to print a `status --json` with: an online Linux peer +(`llm.tail.example`, also on mDNS as `llm.local`), an online Linux peer only +on the tailnet (`nas.tail.example`), an offline peer, an online iOS peer, and +`"Self"`. Stub `port_open` (or bash's /dev/tcp via a function override) so +`nas` answers on 22. Tests: + +- `tailnet_hosts` lists online computers only, without the trailing dot. +- `tailnet_hosts` prints nothing when `tailscale` is missing, or when + `BackendState` isn't `Running`. +- `find_servers` probes tailnet hosts too, and `llm` once. +- `find_storage` adds `sftp|nas.tail.example|nas` and lists `llm` once. +- `mount_point nas.tail.example` is `/mnt/nas`. + +Run `make check`. + +### 6. README and the MiniServer side + +- README sections for storage and AI servers: they also find servers on the + Core's network once `configure tailscale` is done. +- MiniServer needs no change for this. If MiniServer later syncs this change + (its `.claude/skills/coredesktop-sync`), it has no `configure storage`, so + only the shared lib and any ai-servers part would apply. + +## To verify (unconfirmed when written) + +- **MagicDNS in headscale.** Names like `box.tail.example` resolve only with + `dns.magic_dns: true` in headscale's config. If they don't, use the peer's + first `TailscaleIPs` address instead of `DNSName`, and show `HostName`. +- **`Online` from headscale.** Believed to be filled in like Tailscale's own + control server does; if headscale leaves it false or missing, drop the + `select(.Online)` and let the 2-second probes time out offline peers. +- **The sandbox and tailnet names.** Check that an agent run through + `sandbox/agent` reaches `box.tail.example:11434` once it's in + `allowedDomains`, i.e. that srt's proxy resolves MagicDNS names outside the + sandbox. If not, allow the `100.x` address. +- **How long `find_storage` takes** on a tailnet with ten or more peers.