Skip to content

feat: web shares through relays, blind to TLS - #1742

Draft
penso wants to merge 17 commits into
mainfrom
feat/relay-web-shares
Draft

penso wants to merge 17 commits into
mainfrom
feat/relay-web-shares

Conversation

@penso

@penso penso commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Web shares through relays: a computer publishes its own HTTPS server, starting with the Sheprd web UI as a PWA, at a public name under sheprd-relay.dev, and the relay stays a blind pipe. Plan: docs/web-share-plan.md.

This PR has the plan and Phase 1, the relay:

  • Names (web_share): host label = first 80 bits of SHA-256("sheprd-relay/web/v1\0" ‖ route), base32; shares at SHARE.HOST.ZONE. A bounded ClientHello reader extracts the SNI. Bit-flip and truncation loops show it never panics.
  • Edge (web_share::edge, --web-listen): reads only the ClientHello's server name, splices a browser to its host's listener with the TLS bytes untouched, sends other names to --web-fallback (Caddy) with a PROXY v2 header, and answers unknown shares with unrecognized_name.
  • DNS (web_share::dns, --web-dns, --web-address): an authoritative server for the zone only. A/AAAA for share names, SOA/NS, and CAA letsencrypt.org; validationmethods=dns-01 at the apex, and TXT at _acme-challenge.HOST from that host's listener. NXDOMAIN inside the zone, REFUSED outside it. Over the rate limit, UDP gets a TC=1 reply (the address may be forged) and TCP has the hard limit.
  • Hub: listeners opt in (web / acme_txt, QUIC 0x22 / 0x23). Browsers are counted apart from the owner's devices (64 per route) and have their own rate. Their sessions end when web shares go off, never on a dial-key change. New status 10 unsupported. /v1/info gains web.zone.
  • QUIC client: Listener::set_web, set_acme, Pending::arrival → Arrival::Web(Visitor). Pending::incoming is unchanged for existing callers.
  • Deploy: opt-in compose.web.yml + Caddyfile.web (the relay takes TCP 443 and port 53, Caddy moves behind it). README covers NS delegation and checks. PROTOCOL.md "Web shares", vectors/web_share.json.

Phase 2, the computer (sheprd-remote-control, behind [remote] web_share = true):

  • The first relay's /v1/info is read with the connection (client::reach_with_info); nothing about web shares is sent to a relay that names no zone, and status says no_zone.
  • instant-acme (ring) gets *.HOST.ZONE from Let's Encrypt by DNS-01, the value set through the daemon's own listener (set_acme). The label, account (per CA directory), chain, and key are kept 0600 under web-share/, renewed with a third of life left, retried 15 min → 6 h. --acme-directory and --acme-root point it at staging or a private CA.
  • Each browser's TLS ends in the daemon, which checks the share's own name and hands it the router phones use (relayed, keyed by the browser's address). Nearby pairing and the local CA's files are 404 through the share. The share origin is admitted only while serving, never remembered, offered, or raced.
  • Settings > Remote control gets a Web share switch with the address and Copy, config set remote.web_share true does the same, and remote status prints Web share: URL (JSON status.web).

Trust note: rate limits key browsers by the address their relay reports, and the share origin is only as trusted as its relay's zone, as the plan's threat section says.

Without --web-zone, relays behave exactly as before; without [remote] web_share, the daemon does too.

Not in this PR: pairing a browser from the share's origin, a Let's Encrypt staging run on a delegated zone, client_ws listener support, the dashboard kill switch, and the PSL entry for *.sheprd-relay.dev.

Screenshots

Real usage in a Sheprd macOS VM: sheprd-relay --web-zone fra1.sheprd-relay.dev on TCP 443, with macOS's resolver for the zone pointed at the relay's own DNS (/etc/resolver), and examples/web_share.rs as the computer. It listens over QUIC, turns web shares on, and ends TLS itself. Its wildcard comes from a throwaway local CA standing in for the Let's Encrypt certificate Phase 2 gets by DNS-01.

Safari opens the share with no certificate warning. The page is served by the computer over TLS 1.3, and the relay only carried the bytes:

Safari loading https://demo.mas2mqac535nzpqs.fra1.sheprd-relay.dev served through the relay

The same name resolved by macOS through the relay's DNS, the zone's CAA record, the computer's wildcard certificate as curl sees it, and the relay counting spliced visits:

Terminal: dscacheutil, dig CAA, curl -v, and relay_web_visits_total

Settings > Remote control, from this branch's debug build in a Sheprd VM: the Web share switch under the relays, on, with its status line (remote control is off there, so it says it starts with it; once running it shows the address with Copy address, or why it waits):

Settings > Remote control: the Web share switch

QA

  • cargo test -p sheprd-relay --all-features: 281 passed
  • cargo test -p sheprd-remote-control: 1,927 passed, including a browser through a loopback relay to the daemon's router with TLS ended in the daemon
  • Opt-in web_share::tests::pebble with Pebble v2.10.3: a real ACME DNS-01 order answered by the relay's DNS through the daemon's listener, then the web app loaded trusting only Pebble's root (4.4 s)
  • cargo test -p sheprd-gpui --lib for the new status line and Settings row; just check-i18n, including a real TLS handshake browser → edge → relay → QUIC listener holding its own certificate
  • cargo clippy -p sheprd-relay --all-targets --all-features: clean
  • cargo check of --no-default-features --features client, websocket-server, and testing, plus every crate that depends on sheprd-relay
  • swift test in crates/sheprd-relay/swift: 25 passed (new status 10)
  • python3 scripts/test_relay_deploy.py: 25 passed. docker compose -f compose.yml -f compose.web.yml config merges as intended
  • just check-file-size, git diff --check
  • Local binary smoke test: dig against --web-dns returned A/AAAA, CAA, SOA, NXDOMAIN, and REFUSED as specified; /v1/info shows web.zone
  • In a macOS VM: Safari and curl reach a share through the relay's DNS and web port, with TLS ended on the computer (screenshots above)
  • Caddyfile.web validated by Caddy (the Docker daemon was down here)
  • On a droplet: delegate fra1.sheprd-relay.dev, then dig +norec @IP a.aaaaaaaaaaaaaaaa.fra1.sheprd-relay.dev and check the relay's own HTTPS still works through the fallback
  • CI's full relay matrix (crates/sheprd-relay/ci.sh)

A computer publishes the Sheprd web UI, and later any local port, at a public HTTPS name under sheprd-relay.dev. The relay routes by SNI and stays a blind pipe; the computer holds a per-host wildcard issued through ACME DNS-01 against the relay's own DNS.
@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; no blocking findings remain.RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; no blocking findings remain.

Summary

This PR adds opt-in HTTPS web shares through relays. The computer holds the certificate; the relay routes encrypted browser traffic and answers DNS.

Since the previous review:

  • Opted-in relays route browser TLS and answer DNS for web shares.
  • The daemon serves the web app through a relay using its own wildcard certificate.
  • Settings and remote status show whether web sharing is on and where it is served.
  • An opt-in relay deployment puts the relay on browser HTTPS and DNS traffic.

The previous findings are addressed in the current code. No new actionable issues were found. This review checked code and test coverage; it did not run tests.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    Browser[Browser] -->|Encrypted TLS bytes| Relay[Relay]
    Relay -->|QUIC stream| Computer[Computer ends TLS]
    Computer --> App[Web app]
    Computer -->|DNS-01 challenge value| Relay
    Relay --> DNS[Authoritative DNS]
Loading

Reviews (6) · Last reviewed commit: "fix(remote): keep the web share's owner,..." · Reviewed by Greptile

Comment thread docs/web-share-plan.md Resolved
Comment thread docs/web-share-plan.md Resolved
The relay learns web shares at the protocol and hub level: a host label derived from the route, share names under a zone, a bounded ClientHello reader that finds the server name, listener messages to turn web shares on and set a DNS-01 value (QUIC 0x22/0x23, WebSocket web/acme_txt), and browsers' dials, announced as INCOMING_WEB or incoming_web with the visitor's address. Browsers are counted apart from the owner's devices and their sessions end when web shares go off, never with a change of dial keys. Status 10, unsupported, answers a relay without a zone. No transport for browsers yet.
With --web-zone, the relay opens a TCP port (--web-listen) that reads each ClientHello's server name and splices a browser reaching SHARE.HOST.ZONE to that host's listener, forwarding its TLS bytes untouched; other names go to --web-fallback with a PROXY protocol v2 header, or get an unrecognized_name alert. It also answers DNS for the zone (--web-dns, --web-address): share names resolve to the relay, the zone serves SOA, NS, and a CAA record that allows only Let's Encrypt by DNS-01, and _acme-challenge.HOST serves the value that host's listener set. /v1/info names the zone, and relay_web_visits_total counts outcomes.
compose.web.yml puts the relay on TCP 443 and DNS on 53 and moves Caddy behind it with a PROXY protocol listener (Caddyfile.web); the deploy README covers the NS delegation and checks. --web-fallback takes HOST:PORT so a container name works. PROTOCOL.md documents web shares. The zone's DNS no longer drops UDP past an address's rate, since a forged source could silence a resolver or a CA: it answers the question alone with TC set, no larger than the query, so real clients retry over TCP, where the limit holds.
Listener::set_web and set_acme send the new messages, and Pending::arrival reads either a device's dial or a browser for a web share (Visitor, with its address), whose stream starts with its TLS ClientHello. Pending::incoming keeps its meaning for existing callers. A test runs a real TLS handshake from a browser through the relay's web port to a computer holding its own certificate.
@penso penso changed the title docs: plan web shares through relays at sheprd-relay.dev feat(relay): web shares through relays, blind to TLS Nov 29, 2026
set_web(false) removed the host label's mapping whatever route held it; it now removes only its own. Caddyfile.web takes PROXY headers on :443 only, not on port 80. The plan's flow now matches the relay: clients check /v1/info for a web zone before sending web messages, since older relays close the listener; the listener learns a browser's address from incoming_web or a 0x11 stream, not a PROXY header; DNS answers empty NOERROR, never a refusal, for names in the zone without the type asked.
@penso

penso commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator Author

@greptileai review

Comment thread crates/sheprd-relay/src/hub.rs Resolved
Comment thread crates/sheprd-relay/src/splice/peer.rs Resolved
A listener leaving or being replaced now ends its browsers' sessions; a WebSocket listener's accepted sockets did not close with its control socket, and a replacing listener starts with web shares off. Devices' sessions stay, as their keys let them in. The zone's DNS gives TCP its own allowance, so a UDP flood forged in a resolver's name, which now only gets truncated answers, cannot also close the TCP retry. The bytes read before a browser's session are sent in chunks of at most max-frame, so a WebSocket listener enforcing it accepts them.
examples/web_share.rs listens on a relay over QUIC, turns web shares on, and serves a page at SHARE.HOST.ZONE with a wildcard from a throwaway local CA standing in for the Let's Encrypt certificate DNS-01 would give. It is the reference for other apps' authors and what the PR's screenshots ran.
@penso

penso commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator Author

@greptileai review

The daemon gets each web share's wildcard from Let's Encrypt by DNS-01 through its relay; instant-acme runs on the workspace's ring provider, without its aws-lc-rs default.
With [remote] web_share = true (--web-share), the daemon serves its web app at https://SHARE.HOST.ZONE/ through the first relay that names a web zone. It turns web shares on there, gets a wildcard for *.HOST.ZONE from Let's Encrypt by DNS-01 with the value set through its listener, keeps it with the share label and the ACME account in its private state, renews it with a third of its life left, and ends each browser's TLS itself before handing it the router phones use. Only the share's own name is served; the share's origin joins the computer's origins; sheprd remote status prints its address or why it waits. --acme-directory and --acme-root point it at another ACME CA. An opt-in test gets a real certificate from Pebble against the relay's DNS and loads the web app through the relay.
The share's origin was added to the computer's origins, which are remembered, offered for pairing, and raced by phones; it is now admitted only while the share serves and never kept. Nearby pairing and the local CA's files answer 404 through the share, which has no use for them. A relay sending a browser to a session that did not turn web shares on is not followed.
Settings > Remote control gets a Web share switch under the relays, writing [remote] web_share, with a line that gives the web app's public address and a Copy address button once it serves, or why it waits. The same is config set remote.web_share true, and remote status prints it; docs/cli.md says so.
Status is kept by value in Health::Running, and the new field made that variant much larger than the others.
@penso penso changed the title feat(relay): web shares through relays, blind to TLS feat: web shares through relays, blind to TLS Nov 29, 2026
@penso

penso commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator Author

@greptileai review

… with it

When shared relays change and another becomes first, its listener and the old first one reconnect, so the share starts there without waiting for a reconnect. A listener that stops serving the share now clears it back to waiting, unless a newer one took over, so status no longer offers a ready address during an outage. The certificate and its key are kept in one file, replaced in one rename, so a crash during renewal cannot leave a mismatched pair.
@penso

penso commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator Author

@greptileai review

…r one lock

A listener that ended could pass the generation check, pause, and clear the certificate a newer listener had just installed. The generation, the served certificate, and the status now share one lock, and the certificate task names its generation, so an older listener's end or late steps never touch a newer one's share. A relay withdrawn while it was restarted for the web share no longer stays in the relay status.
@penso

penso commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator Author

@greptileai review

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant