Expand description
Mesh status + Funnel helpers (P5 of the unified-tool-gateway epic, #478).
Extracted from apps/core/src/mesh into its own primitive crate (in-process
default preserved — every entry point is a plain function call, never IPC).
Core owns what runs — the optional Tailscale/Headscale daemon (a Sidecar
managed by the SidecarManager, apps/core/src/sidecar/tailscale.rs). This
crate is the read/shape side: it shapes tailscale status --json into the
canonical GET /api/mesh/status contract (Appendix A Contract 6 of
docs/unified-tool-gateway-spec.md), resolves the fail-closed shared-mesh-token
bearer for GET /api/mesh/peers, and exposes the ensure_funnel/funnel_url
primitives P6 consumes for public webhook ingress.
The one kernel coupling — the tailscale/tailscaled process shell-outs —
inverts through the narrow MeshHost trait (host shim implemented Core-side
in apps/core/src/mesh_host.rs, installed once at boot via set_global_host,
mirroring the CryptoHost/RecipesHost precedent). So this crate has ZERO
dependency on apps/core.
The mesh is opt-in. The enabled signal is RYU_MESH_ENABLED (env) OR the
mesh-enabled pref (seeded by Core at boot into set_pref_enabled — the
desktop’s Gateway → Integrations toggle writes the pref through
POST /api/mesh/config). The env wins when set (operator override → pref,
matching the mesh-login-server/ingress-URL precedence). When off,
query_status returns the all-default object (HTTP 200, never 500) WITHOUT
touching the host, so a build with no host installed still behaves correctly
for the default (mesh-disabled) install.
Structs§
- Mesh
Handle - Handle held by Core’s
ServerStatefor the mesh plane. Cheap to clone. Today it is a stateless façade over the env-drivenquery_status/is_enabledfree functions (the daemon itself is a Sidecar managed by theSidecarManager), but giving the server a typed handle keeps the call site stable for when P6 wires Funnel-backed ingress through here. - Mesh
Peer - A peer node on the tailnet, as surfaced in Contract 6. Carries both the P7
fields (
name,host_or_dns) and the P5 fields (magic_dns_name,tailscale_ips,os). - Mesh
Peer Entry - One peer entry in the
GET /api/mesh/peersresponse. - Mesh
Peers Response - The
GET /api/mesh/peersresponse (Contract 6 companion, P7).enabled:false⇒ emptypeers,bearer_source:"none". - Mesh
Status - The canonical
GET /api/mesh/statussuperset (Contract 6). snake_case keys;reachableandupare both present and equal.enabled:false⇒ all-default.
Constants§
- BEARER_
NONE_ NOTE - Provisioning guidance returned when no usable bearer exists on this node. Names the EXACT secret a peer must share for the fail-closed check to pass.
- BEARER_
SOURCE_ NONE - BEARER_
SOURCE_ SHARED - How the offered bearer was derived, surfaced so the desktop (and a human) know whether the token is a real candidate or absent.
Traits§
- Mesh
Host - The kernel-side couplings this crate needs but cannot own: the three
tailscale/tailscaledprocess shell-outs (the “what runs” half of the mesh, aSidecarin Core). Core implements this inapps/core/src/mesh_host.rsand installs it once at boot viaset_global_host.
Functions§
- build_
peers_ response - Build the peers response from a live
MeshStatusand this node’s token. - ensure_
funnel - Ensure a Tailscale Funnel is serving
portto the public internet, returning the public HTTPS URL. Consumed by P6’sTailscaleFunnelSource. - funnel_
url - The public Funnel URL for
portif one is active, elseNone. Cheap read (no mutation) used by P6’s status surface. - is_
enabled - Whether the mesh is enabled for this node. Opt-in via
RYU_MESH_ENABLED(truthy = anything but empty/0/false/no) OR themesh-enabledpref (seeded into [MESH_PREF_ENABLED]). The env wins when SET — including an explicitRYU_MESH_ENABLED=0, which overrides the pref — so an operator can always force the mesh off; only when the env is unset does the pref decide. Kept in lockstep with the gateway’stools::mesh_enabled()so the loopback-trust neutralization (B-9) and Core fail-closed gate agree on the same signal. - is_
insecure_ auth_ token_ placeholder - Whether an auth token is a well-known insecure placeholder. This is the
canonical home for the node-admittance placeholder check:
resolve_mesh_bearerrefuses to hand out such a token as a peer bearer (a peer provisioned with a placeholder refuses to start under mesh, so offering it would be a lie), and Core’senforce_remote_authstartup gate consults the same predicate so both agree on the same signal. Pure + const — no dependency on apps/core. - parse_
enabled - Whether a string parses as a truthy mesh-enabled value — the SAME truthiness
is_enabledapplies toRYU_MESH_ENABLED, exposed so Core can parse itsmesh-enabledpref with the identical semantics instead of a second copy. - parse_
status_ json - Parse the JSON emitted by
tailscale status --jsoninto aMeshStatus. - query_
status - Query the live mesh status. When the mesh is disabled this returns the all-default object without shelling out (HTTP 200, never 500) and WITHOUT consulting the host. When enabled but the daemon is absent/erroring (or no host is installed), it returns an enabled-but-unreachable object so the desktop can render an amber “configured but down” state.
- resolve_
mesh_ bearer - Resolve the candidate bearer to hand the desktop from this node’s node token
(
RYU_TOKEN, passed in). ReturnsNone— meaning “no usable bearer” — when the token is absent, empty/whitespace, or a known insecure placeholder (a peer with a placeholder token refuses to start under mesh, so offering it would be a lie). - set_
global_ host - Install the process-global
MeshHost. Idempotent (a second call is a no-op). Called once from Core’smainat boot. - set_
pref_ enabled - Seed the pref half of the mesh-enabled signal (env wins when set). Mirrors
the entitlement / claude-config / untrusted pref seeders in Core’s
main. Also called by the runtimePOST /api/mesh/confighandler so an enable/disable takes effect without a restart.