Skip to content

Desktop exposure carries a listen-interface selection (#7) - #14

Merged
Khang5687 merged 8 commits into
fork-mainfrom
feat/desktop-selection
Sep 16, 2026
Merged

Khang5687 merged 8 commits into
fork-mainfrom
feat/desktop-selection

Conversation

@Khang5687

Copy link
Copy Markdown
Owner

Ticket: #7 (parent spec #1, ADR 0003). Rebased onto #6 (multi-bind), so the desktop's loopback base URL and the full-selection envelope are both correct.

Desktop exposure carries a listen-interface selection end to end: contract field beside the derived legacy mode, persisted setting with one-way migration and dual write, bootstrap envelope carries the selection (never a pre-resolved IP), relaunch on set inequality, Tailscale Serve gated on a resolved tailnet address, advertised endpoints derived from the selection. No new UI; #8 adds the Connections preset control.

Deviations from the ticket wording, all deliberate:

  1. Derived mode comes from the effective selection, not the literal "local-only iff exactly {loopback}". {loopback, tailnet, lan} on a machine with no interfaces reports local-only; the request stays visible via listenInterfaces and the "listening on loopback only" warning. Preserves upstream's existing fallback behaviour and test.
  2. Tailnet endpoints are advertised only by the Tailscale provider, keyed on "a tailnet address resolved" rather than the tailnet kind, so an explicitly listed tailnet address is still advertised with the right label. Side effect: Serve counts as available when an explicit tailnet address is bound without the tailnet kind.
  3. The relaunch check uses structural selection equality, so the backend restarts on set inequality rather than on a spelling difference.
  4. The serialized wire form is named listenSelection; listenInterfaces names the object.

Also folded in from review: internal names renamed away from "host"; IPv4 family normalization moved into the shared resolver (toResolverInterfaces deleted); desktop reads the loopback-only verdict from the shared resolver instead of re-deriving it; tailnet addresses no longer advertised as "Local network".

Verification: 82 tests across contracts exposure, tailscale resolver, desktop exposure, desktop server exposure, desktop settings, and the web atom; typecheck clean on contracts, desktop, tailscale, server. Server files untouched. Follow-up filed for the unreachable loopback fallback branch in the server's listen-address resolver.

…re state

Desktop exposure was a two-valued mode, so the desktop could only ask for
loopback or everything, and it had to pick a bind host itself.

Exposure state and the set-exposure IPC now carry `listenInterfaces` (ADR
0003) plus the preset, the resolver's addresses and warnings, and whether
Tailscale Serve is available. The legacy `mode` stays as a derived field so
upstream consumers keep working. `formatListenHostSelection` gives a
selection its `--host` spelling for the bootstrap envelope, which the
server already parses, and `listenInterfacesEqual` compares two selections
as sets.
The desktop resolved exposure itself and sent the backend a bind host,
either `127.0.0.1` or the `0.0.0.0` wildcard, so it could not ask for the
tailnet without also opening the LAN.

Desktop settings now persist `listenInterfaces` (ADR 0003), migrating
one-way from the legacy key and dual-writing the derived `serverExposureMode`
so an upstream build still reads something sane after a downgrade. The
bootstrap envelope carries the selection in `--host` form and the server
resolves it, so the desktop never sends a resolved address or a wildcard.
Endpoints follow the selection: no LAN endpoint without `lan`, no tailnet
endpoint without `tailnet`, one endpoint per explicit address. Tailscale
Serve is offered only while `tailnet` is selected, and any change to the
selection as a set relaunches the backend. The new resolution logic lives
in the fork-only `desktopExposureSelection`; upstream files take call-site
edits only.

Interim: until the multi-bind ticket lands, a `lan` selection still binds
the first resolved address and warns about the rest.
The `lan` preset carries `tailnet`, so gating on the selected kind alone
spawned `tailscale status` on every LAN machine with no Tailscale at all.
The old mode-based guard did not, because the fallback had already read
the mode back as local-only. On Mac App Store builds that spawn raises the
"Other apps" TCC prompt.

Gate the spawn, the envelope's Serve flag, and `tailscaleServeAvailable` on
a tailnet address having actually resolved, not on the kind being selected.
…host

CONTEXT.md reserves "host" as a term to avoid for a listen interface, but
the desktop carried the selection as `listenHost` and formatted it with
`formatListenHostSelection`, which read as if the desktop still picked a
bind address.

Rename the serialized selection to `listenSelection` and the formatter to
`formatListenInterfaces`. The `--host` spelling now survives only where it
belongs, at the CLI and env parse boundary: the bootstrap envelope's own
`host` field, which the server parses.
…lver

`resolveListenAddresses` matched `family === "IPv4"` exactly, so the desktop
carried a `toResolverInterfaces` adapter to rewrite the numeric 4 that some
Node builds report. The adapter fixed the symptom for one caller and left
the same gap open for every other.

Accept both spellings in the resolver and drop the adapter. The server calls
the resolver with raw `os.networkInterfaces()` and now gets the same
handling for free.
…olver

`resolveListenAddresses` calls itself the single home of the fallback
policy, but the desktop took its own reading to decide `unavailable`, and
took it differently: an explicit `127.0.0.1` counted as asking for more
than loopback here and did not there.

Return the verdict as `loopbackOnly` and consume it. One policy, one place,
and the desktop no longer disagrees with the server about what a selection
resolved to.
Core endpoints claimed every non-loopback resolved address as "Local
network" with `lan` reachability, so a tailnet address named explicitly in
the selection reached clients mislabelled, competing with the correctly
labelled private-network endpoint from the Tailscale provider.

Core now never claims a tailnet address. Tailnet endpoints come only from
the Tailscale provider, and `tailnetResolved` keys off a resolved tailnet
address rather than the selected kind, so an explicitly named tailnet
address is still advertised instead of being dropped by both sides.
…trings

`listenInterfacesEqual` joined both selections to their `--host` spelling
and compared the strings, so equality depended on the wire format, and two
selections holding the same addresses in a different order read as
different.

Compare kinds and addresses as sets instead. The desktop's relaunch check
now uses that comparison rather than a string difference, so the backend
restarts on set inequality, which is what the exposure model actually means.
@Khang5687
Khang5687 merged commit 586399d into fork-main Sep 16, 2026
7 of 16 checks passed
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XL labels Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant