Repository navigation
feat(core,web): let an operator pin a gateway's WAN IP, and keep public-IP opt-ins across a renumber - #3999
feat(core,web): let an operator pin a gateway's WAN IP, and keep public-IP opt-ins across a renumber#3999Dominion5254 wants to merge 10 commits into
Conversation
StartOS reads a gateway's WAN IP from outbound traffic — the router's UPnP external address, else an echoip request — which answers where egress comes from, not where ingress arrives. A router that sends all outbound traffic through a VPN while inbound connections still arrive on the real WAN address through port forwards therefore has every derived address pointing at the VPN exit: the public addresses offered per binding, the port forwards the user is told to add, and any address a service advertises to its peers. `NetworkInterfaceInfo` gains `wan_ip_override` beside `name` and `secure` — the fields the operator owns — so discovery keeps writing `ip_info.wan_ip` and clearing the override restores it. `NetworkInterfaceInfo::wan_ip()` resolves the two the way `secure()` resolves its pair, and every consumer reads it. `net gateway set-wan-ip` / `unset-wan-ip` set and clear it through the interface controller, which rejects an address discovery would itself discard and returns once the db holds the new value, so host addresses and port forwards are recomputed before the call answers. The gateway row's `⋮` menu gains "Edit WAN IP", whose dialog names the detected address and carries "Reset to detected".
A public IP is reachable only while its exact socket address sits in a binding's `enabled` set, and a WAN-exposed IPv6 GUA needs its address in `gua_wan` as well. Both are written by operator action alone, and nothing rewrote them when the address underneath changed. An ISP lease that rolled, a delegated prefix that moved, or an operator pinning the WAN IP by hand left the replacement address looking like one nobody had opted into: it defaulted to off, and the port forward computed from it vanished with it. The service lost its public address with no operator action and no notification. `migrate_renumbered_ips` moves an opt-in to the address that replaced it, and `update_addresses` calls it for every binding and every range against the address set it just recomputed. That is the one place the gateway map converges — the watcher's sync, the tunnel, and every host API route all pass through it — so a detected renumber and a manual override are the same event by construction rather than by a special case in the override path. An opt-in moves only where the exposure is the same one: same gateway, same port, same family, with exactly one public address offered there before and after. A gateway carrying several GUAs gives no way to say which one inherits the opt-in, so nothing moves and the operator opts in again. A new gateway, a new port, and an address still on offer elsewhere are all left alone.
`migrate_renumbered_ips` moves an opt-in from the address a gateway offered last time to the one it offers now, so it needs both in consecutive convergences. A device NetworkManager drops has its `ip_info` cleared, and `update_addresses` skipped a gateway without one: its rows left `available`, and when it came back on a new lease there was no previous slot to move from. A PPPoE reconnect, a router reboot, or a lease that rolled while the server was off therefore still stranded the opt-in, and boot clears every gateway the same way. `carry_forward` keeps a downed gateway's IPv4 and IPv6 rows from the previous set, so the migration sees old and new when it returns. Its addresses stay on offer until it is deleted, as its name and trust setting do; port forwards, which need the live `ip_info`, lapse while it is down and return with it. A gateway removed from the map still takes its rows with it. Also on the same branch: - `show_config` in the tunnel API read `ip_info.wan_ip` directly, the one consumer that bypassed the override. It now reads `wan_ip()`. - `set_wan_ip_override` refuses to pin an address on an outbound-only gateway, which carries no inbound traffic. Clearing is still allowed. The dialog already hid the action; the CLI now gets the same answer. - The override check also rejects 192.0.0.0/24, 198.18.0.0/15, multicast and 240.0.0.0/4, and the dialog's reserved list gains 192.0.0.0/24, so the two agree.
The override landed with an "Edit WAN IP" dialog in the gateway row's `⋮` menu and a motivating case we should not recommend: a router sending outbound traffic through a commercial VPN while inbound port forwards still arrive on the real WAN address. Pinning the real address there publishes it — in DNS, in the addresses services advertise to peers, and to anyone scanning a forwarded port — while those same services egress from the VPN exit, so a peer that sees both legs binds the two addresses together. The answer to that topology is per-service outbound, not an override that makes it work well enough to keep. What remains is the narrow case the override is actually for: detection naming an address the server is not reachable at, because inbound and outbound take different paths for reasons upstream of the server — multi-WAN routing, an ISP translating egress from a pool separate from the mapped inbound address, a cloud floating ingress address, a router with UPnP off or reporting a stale one. That is a fact about the network to correct rather than a setting to reach for, so it is `start-cli net gateway set-wan-ip` / `unset-wan-ip` and nothing else. The web UI keeps the read path — the gateway table, the DNS checks and domain validation all resolve the override over the detected value — so an address pinned from the CLI is never contradicted by the UI, and the table still marks one with a pencil. The dialog, six of its seven dictionary strings and the two `ApiService` methods are gone. The RPC methods are untouched: they were already `.no_display()` with `with_call_remote::<CliContext>()`, like `set-secure`. `gateways.md` and the 0.4.0.2 changelog drop the VPN framing for the detection-is-wrong cases, and gain a warning that pinning the correct address is what makes the server publicly reachable at it.
The field's `///` still described the case the feature is no longer documented for, and ts-rs copies it verbatim into `NetworkInterfaceInfo.ts` and its tunnel twin, so the framing removed from the docs and changelog survived in three generated places. Describe what detection actually gets wrong instead — UPnP first, outbound inference otherwise, and the asymmetric-routing cases where the two disagree. A test binding named `vpn_egress` becomes `detected_only`. Bindings regenerated with `make start-core-ts-bindings`.
dr-bonez
left a comment
There was a problem hiding this comment.
fix the mannered prose throughout the comments and docs
… facts Review on #3999 asked for the mannered prose to go throughout. Doc comments ran 7 to 17 lines, listed trigger cases, and argued their own rationale; tests narrated each step their names already state. Each comment is now one fact. The `wan_ip_override` field doc is one line, and both generated `NetworkInterfaceInfo.ts` bindings follow it. The CLI about/help strings match their neighbours ("Set a gateway's WAN IP"), the two error strings state the refusal alone, and the man pages carry the new text. The changelog entry and the `gateways.md` WAN IP section lose the mechanism and the jargon; the warning is one sentence. Two defects fixed on the way: `carry_forward` had been inserted between `mdns_gateways` and its doc comment, which it thereby took over, and `check_wan_ip_override` still pointed at a dialog removed in 6eaac3b. Bindings regenerated with `make start-core-ts-bindings`; man pages edited to match the new strings.
…he facts Review on #3999 asked for the mannered prose to go throughout, and this branch carried the same habits: a 23-line module doc, doc comments that argued their rationale and named their callers, tests narrating what their names state, and user docs saying the same thing three times. Each comment is now one fact. The changelog entry, release note, `published-ports.md` and `settings.md` state the behavior once. `ARCHITECTURE.md` also described the layer as keyed on the connection's destination, stale since 3f1fa0d, and omitted the per-request reread of stale addresses. Comment-only in every `.rs` file.
|
Field report for the renumber half of this PR, from a 0.4.0.1 server on a home A service exposes a raw UDP port and had its Public address on the router That matches what Two things worth knowing when this lands:
Happy to rebase this onto current master if that helps get it in. |
…ct to HTTPS while 443 is published (#4000) * fix(start-wrt): redirect plain HTTP at the WAN address to HTTPS while 443 is published StartOS asks its IPv4 gateway for no port-80 mapping: it publishes only 443 and expects the gateway to answer plain HTTP at the public address with a redirect to HTTPS, as StartTunnel does. StartWRT never implemented its half, so a LAN client opening http://sub.example.com for a domain pointing at the WAN address hairpinned to the router's own port 80 and got the router UI. Port control now binds a listener to <WAN IPv4>:80 beside the daemon's wildcard :80 (both SO_REUSEPORT; the kernel delivers a connection to the most specific socket) and hands each connection to start-core's shared handle_http_on_https, a 307 to the same host and path over HTTPS. The socket is never wired into the axum app, so it can serve nothing but the redirect, and the LAN gateway addresses and router.lan still reach the UI. No firewall rule is touched: who may reach WAN:80 remains the Remote Access policy; this changes only what answers there. The listener is bound only while WAN 443 leaves the router (an enabled WAN DNAT covering tcp/443, or a live hostname route on 443) and yields to a DNAT on tcp/80, so a router publishing nothing on 443 behaves exactly as before. Reconciled at port control startup, on the sweep, on hostname route changes, and when a manual published port is saved. * fix(start-wrt): admit WAN-side HTTP to the port-80 redirect through a DNAT The redirect listener on WAN:80 answered only connections the wan zone already admitted, so under Remote Access "Never" (or "When behind NAT" with a public address) a client on the Internet opening http://sub.example.com was refused. StartOS publishes only 443 and leaves port 80 to its gateway, and that half of the contract was unmet from outside. An ACCEPT on wan tcp/80 would be fail-open: UCI rules persist across a daemon restart and fw4 loads them before the daemon binds, so the UI's wildcard :80 socket would answer in that window or after a failed bind. Instead, port control writes a wan-zone DNAT (`startwrt_http_redirect`, no dest_ip, which fw4 renders as an nft `redirect to :8880`) while 443 is published, and the redirect binds 0.0.0.0:8880 beside its WAN:80 socket. fw4 accepts DNAT'd connections at input, so no ACCEPT rule opens 80, and with the daemon down the DNAT lands on a closed port. The section carries its own marker option rather than `_apf_label`, which the sweep would lease and collect and the UI would list as an automatic forward. `wan_dnat_covers` ignores it so the redirect does not gate itself off, `apply_forward_uci` still counts it so PCP/UPnP grants for external 80 conflict while it is active, and `sni_port_conflicts` reserves 8880 so no hostname route can out-rank the wildcard socket. The section's presence no longer depends on knowing the WAN address, which avoids a remove-and-re-add firewall reload at every boot; only the WAN:80 hairpin socket needs the address. Reconciliation runs under `write_serial`. Callers that already hold it use the serialized variant, and `published_ports::set` skips the redirect's own firewall reload since it reloads anyway. A settled section is never rewritten, so the sweep does not reload fw4 every minute. Under "Never", port 80 now answers a 307 instead of rejecting while 443 is published. It echoes the requested Host and can serve nothing else. * refactor(start-wrt,core): decide the port-80 redirect in the request path The redirect bound two sockets of its own — <WAN>:80 for LAN hairpins and 0.0.0.0:8880 behind a wan-zone tcp/80 DNAT for the Internet side — because a socket bound after the UI's wildcard :80 cannot be admitted by an ACCEPT rule without the UI answering in the gap between the two binds. Deciding per request removes the gap and with it the reason for both sockets: an outermost layer on the router answers a request whose destination is the WAN address with a 307 and passes everything else through, live from the first accepted connection. StartOS makes the same trade in net/domain_redirect.rs. Gone with them: port 8880 and its reservation, the hairpin rebind on every WAN renumber, the startwrt_http_redirect section and its marker, the family field on FirewallRedirect, the impostor-replacement logic, and wan_dnat_covers' exclusion of its own section. The Internet side is now a WAN ACCEPT rule on tcp/80, carried in the SNI admission set rather than reconciled separately, so sync_sni_rules is the one place the redirect is decided. It keeps the SNI label deliberately: a label older builds do not know is a rule older builds never purge, and such a rule outliving a downgrade would admit plain HTTP to a daemon with no layer behind it. Sharing the label means a rollback purges it on its first run, as it already does for a stale apf_sni_443. The gate the layer reads is that rule's presence, not "443 is published". The two disagree exactly at startup — a hostname route does not survive a restart but the rule it earned does — so the gate is seeded from UCI before the listener binds and tracks what the firewall actually admits. Until port control resolves the WAN address the layer redirects rather than falling through, since a double-NAT WAN is not separable from the LAN by address class. TcpMetadata.local_addr now comes from the accepted stream rather than the listener, which is the connection's destination on a wildcard socket and identical to the old value on a specifically bound one. served_name and arrival are its only readers and both want the destination. Also reserves port 80 against hostname routes while the redirect is up, which the DNAT did not: a UPnP grant could take external 80 and be silently dead WAN-side. * fix(start-wrt): serve the UI on port 80 by client subnet, not by destination alone The port-80 admission rule matches the wan zone, not a destination, and the layer redirected only a request whose destination was the WAN address. Four consequences, found auditing b700399 against the PR discussion: A WAN-side host that routes the LAN subnet through the router's WAN address arrives at the LAN address and was served the plaintext UI under "Never". The DNAT this replaced caught all wan-zone tcp/80, so that was a regression. The layer now serves the UI only to a client on a subnet the router is connected to off the WAN, at an address that is not the WAN's; every other IPv4 request gets the 307. The gate carries every WAN address rather than the first. After a restart the gate was seeded admitted with no WAN address, which redirected every plain-HTTP request, LAN included, until the first 60 s sweep and for as long as the WAN had no address. Addresses are now read before the listener binds, when port control starts, on every sweep and WAN hotplug, and once more (at most every 5 s) before a redirect is answered, so a bridge that comes up after the daemon is trusted on its first request. With the WAN down there is no WAN subnet to exclude and the LAN keeps the UI. The gate was set to the wanted state before the rule was reconciled, so unpublishing 443 shut it while fw4 still admitted WAN:80 — the UI answered there until the reload finished, or indefinitely if it failed. It now opens before the rule is written and shuts only after the reload that removes it. A hostname route on 80 writes the same section under the same label, and the redirect's rule was identified by port alone: the route's own rule read as the redirect's, so its renewal was refused as taken and a manual port-80 forward was refused rather than displacing it. The rule's name now tells the two apart, the redirect yields to a live route on 80, and the rule is rewritten when the port changes hands. The seed still opens the gate on any SNI rule on 80, since a lapsed route's rule admits the same traffic. The label stays shared, so a build without the redirect still purges the rule. Not migrated: the startwrt_http_redirect section written by 7207775. It reads as a user's port-80 forward and holds the redirect off, but no build on master ever wrote it; a bench router that ran that commit needs `uci delete firewall.startwrt_http_redirect`. * docs(start-wrt,core): cut the port-80 redirect comments and docs to the facts Review on #3999 asked for the mannered prose to go throughout, and this branch carried the same habits: a 23-line module doc, doc comments that argued their rationale and named their callers, tests narrating what their names state, and user docs saying the same thing three times. Each comment is now one fact. The changelog entry, release note, `published-ports.md` and `settings.md` state the behavior once. `ARCHITECTURE.md` also described the layer as keyed on the connection's destination, stale since 3f1fa0d, and omitted the per-request reread of stale addresses. Comment-only in every `.rs` file. * fix(start-wrt): answer a Host-less request on WAN:80 with 400, never the UI `redirect()` returned `None` when the request carried no usable `Host`, and `respond()` read that as "not the redirect's request" and fell through to the UI. A WAN-side client could reach the plaintext router UI while 443 is published with `printf 'GET / HTTP/1.0\r\n\r\n' | nc <WAN> 80`, under every Remote Access setting. Once the layer has decided a request redirects, it now always answers: a 307 with an authority, a `400 Host header required` without one, which is what the standalone redirect socket this layer replaced answered. * fix(start-wrt): admit WAN tcp/80 for the redirect at the WAN address alone The redirect's admission rule matched the wan zone with no destination, so the firewall also admitted a WAN-side packet for the router's LAN address to the daemon, and only the layer's client-subnet check kept it from the UI. The rule now carries `dest_ip` set to the WAN address, so such a packet is rejected at the firewall as it was before the redirect existed; the layer's check stays as the second line. Port control rewrites the rule when the WAN address changes (the sweep and the WAN hotplug already invalidate the cached address) and writes none while the address is unknown. The gate still opens whenever the redirect is wanted, so a LAN hairpin to the WAN address redirects with or without the rule. * fix(start-wrt): seed the port-80 gate before port control can raise it `port_control::run` was spawned before `http_redirect::seed` ran. `run` raises the gate before writing the admission rule; `seed` sets the gate to whether an SNI rule on 80 is already on disk. On the first boot of a router that already publishes 443, no such rule exists yet, so `seed`'s parse could read the old firewall and its `set_admitted(false)` land after `run`'s `set_admitted(true)`: rule live, gate shut, listener bound, and WAN:80 served the plaintext UI until the first sweep at 60 s. Seeding before the spawn leaves "rule absent, gate shut" as the worst boot state, which the firewall refuses. Found by helix-nine in review of #4000. * fix(start-wrt): a ubus failure leaves no client trusted on port 80 `wan_ipv4_addrs` returns an empty list on a ubus failure, which the gate could not tell from a WAN with no address. With no WAN address to subtract, the WAN interface's own subnet stayed in the trusted set, so a peer on that subnet dialling `<WAN>:80` got the UI instead of a 307 while the admission rule was still live from a cached lookup, until the next successful read. `read_wan_ipv4_addrs` returns `None` on a ubus failure and the gate then trusts no subnet; an empty list still means the WAN is down and keeps serving the LAN at its own address. Found by helix-nine in review of #4000. * docs(start-wrt,core): tighten the port-80 redirect's comments; fold its release note into highlights --------- Co-authored-by: Aiden McClelland <me@drbonez.dev>
… permission, and the answer plane (#4055) * feat(core): give DnsInjector a pre_update policy hook and change-only notify StartWRT's DNS injection needs per-record policy the injector cannot express today: its unsigned tier restricts an UPDATE to A/AAAA records pointing at the sender itself, and name ownership refuses a held name to a different device. None of that can live in `authorize`, which sees only the source IP. Replace the handler's hard-coded TSIG refusal with a `pre_update` hook that receives the UPDATE's records plus the TSIG verdict before the store mutates. StartTunnel installs the old rule verbatim (valid TSIG or Refused), so its behavior is unchanged — regression-tested across every src x signed combination. The one deliberate delta: a malformed unsigned packet now gets FormErr rather than Refused, since decoding happens before policy. Also suppress `on_change` when a mutation changes nothing. The client re-asserts every 180s, and on StartWRT that hook is the dataplane — an addn-hosts rewrite plus a dnsmasq signal per no-op, forever. StartTunnel merely saves a redundant PatchDb write. For the StartWRT consumer (start-core is an external crate to it), promote `derive_tsig_key` to pub and lift `forwarding_catalog` out of `tunnel/dns.rs` into `net/dns_update/` with the timeout as a parameter. * feat(start-wrt): DNS injection backend (RFC 2136 ingress, policy, answer plane) A device the user permits (a StartOS server publishing its private domains) pushes A/AAAA records to its gateway address; every LAN device then resolves them through dnsmasq. Also the LAN-side answer to the SNI hairpin: a split-horizon record pointing at the owning device's LAN address keeps LAN clients off the source-preserving demux path that cannot serve them. dnsmasq keeps owning port 53. A static nft NAT include (priority -101, ahead of the DNS-Override dstnat) diverts only UPDATE-opcode packets addressed to the router — `fib daddr type local` exempts ddns-scripts' transiting nsupdates — to per-profile listeners; a daemon restart therefore cannot take LAN name resolution down. Listeners are SO_BINDTODEVICE-bound per profile bridge, closing cross-segment source spoofing structurally, with a second port for inbound-WireGuard arrivals so no two sockets share (addr, port). Policy is tiered through the shared injector's pre_update hook: a WireGuard peer's TSIG (derived from its PSK) buys any-name A/AAAA/CNAME/TXT; a plain LAN device with the default-off per-device toggle may only publish A/AAAA records equal to its own source address — name-squatting at worst, strictly narrower than the DHCP-hostname injection dnsmasq performs for every device by default. Both tiers respect first-come name ownership (keyed MAC or WG pubkey) and refuse the reserved `lan.` zone. Answers leave through per-profile addn-hosts files in tmpfs, diffed before writing and signalled per instance via procd (never the pidfile — dnsmasq's ujail PID namespace makes it lie). Enabling injection for the first device gives every profile its own dnsmasq instance (ISP-mode profiles share one main instance otherwise), each now scoped to its own bridge — which also fixes the latent every-instance-serves-every-pool overlap. File visibility follows lan_access: a profile only sees names its firewall can reach. Records and ownership are memory-only; a sweep drops a record whose owner lost the address it points at, and clients re-assert within 180s, so flash is never written in the steady state. RPCs: devices.set-dns-injection (mirrors set-auto-forward, stored as `_allow_dns_inject` on the DHCP host section) and read-only dns.injected-list. Deliberately no manual record CRUD: the shared admin path bypasses authorization, TSIG, and ownership. * feat(start-wrt): DNS-injection permission toggle and record view in the UI A second per-device permission beside automatic port forwarding on the device page: "Allow DNS record publishing", default off, riding the same Save as the rest of the form so one click yields one toast. Enabling asks first — a confirm dialog naming the trust granted (names that resolve network-wide) — because unlike the port-forward toggle this one can affect what every other device on the network resolves; the control only flips on confirmation. Below the permissions, a read-only table of the names the device has published (`dns.injected-list`), with no actions by design: the device re-asserts or withdraws its own records, and revoking the permission removes them immediately. API contract gains `devices.set-dns-injection` and the new DNS Injection category, and the device row carries `allow_dns_injection`; both API service implementations and all five dictionaries updated. * feat(start-wrt): forgetting a device drops its published DNS records now Forget already closes the device's automatic forwards; wake the DNS-injection refresher too, so the sweep withdraws the device's records with the same immediacy instead of on its next interval. * style(start-wrt): rustfmt over the DNS-injection additions * docs(start-wrt): DNS record publishing in the book, changelog, and RFC Device page docs cover the new permission, its confirm dialog, and the read-only record table; the published-ports hostname-route section spells out the manual second step (a hostname route does not publish the name to the LAN — enable the domain as a private domain on the StartOS server); the FAQ gains the .local-over-inbound-VPN answer. Changelog entry under the unreleased 1.1.0 block. The RFC rides along updated to the implemented ingress: the earlier draft's port 5454 is actually inside SmartDNS's 5300-9394 namespace (5300 + tag 154), so the listeners sit at 9553/9554 — split by arrival interface in the nft include so bridge-bound and WireGuard-bound sockets never share (addr, port). * docs: private-domain DNS guidance in the StartOS and StartWRT books The StartWRT bench surfaced three things users will hit that neither book covered: names under .lan are refused by design (the router derives that zone from device hostnames), a lookup made before publishing is authorized escapes to public DNS and is cached as nonexistent — for up to a day when the domain's ending does not exist publicly, since the negative then comes from the root zone — and DoH browsers bypass the network's DNS entirely. The StartOS private-domains page gains domain-choice guidance (owned subdomain > .internal/home.arpa > invented endings, and why), the StartWRT publishing path alongside the existing point-your-router instructions, and a troubleshooting section with the per-OS cache-flush commands and the DoH explanation. The StartWRT devices page documents the reserved .lan zone and the enable-the-toggle-first ordering, deferring to the StartOS page for the rest. The changelog entry gains the Firefox DoH canary behavior added to the per-profile DNS instances. * fix(start-wrt): form footer no longer overlaps content that follows the form The form-card footer is absolutely positioned below the card and takes no layout space, so the device page's Published DNS records section rendered under the Cancel/Save buttons. The card now reserves the footer's height. * fix(start-wrt): published DNS records table matches the device form width * fix(start-wrt): DNS-injection refusals and reaps log at warn The daemon's default tracing filter is `warn,activity=info`, so the `info!` lines that were added to name a refused UPDATE or a reaped record never reached logread on a router. Bench-confirmed on hardware: a toggle-off that reaped a record produced no log line at all. * fix(start-wrt): published DNS records table follows the device poll The table was read once when the page opened, so it kept showing records after the permission was turned off and never picked up records that arrived or expired while the page was open. It now re-reads on every device poll, which also runs right after Save. * fix(start-wrt): unauthorized DNS UPDATEs log their refusal StartWRT installed `by_ip.contains_key` as the injector's `authorize` closure, so an UPDATE from a source without the DNS-injection permission was refused inside `DnsInjector::apply_update` before the `pre_update` policy ran. The policy's "source holds no known address assignment" branch — the one that logs at warn — was unreachable, and the most common refusal left no trace in `logread`. `authorize` is now pass-through and `policy` is the single gate: it already refuses an unknown source and names the reason. The wire reply is unchanged (`REFUSED`); the shared start-core gate is untouched for StartTunnel. Observed on the K1: a guest-profile laptop's `nsupdate` now produces the warn line. * fix(start-wrt): a reservation edit refreshes the DNS-injection directory The directory of addresses allowed to inject was rebuilt only on its 60 s tick and on the permission toggle. Moving a device's reserved address therefore left the old address in the directory until the next tick, and the device's first UPDATE from its new address was refused as an unknown source — which costs the StartOS client a five-minute back-off before it publishes again. `devices.update` now wakes the refresher, the same way `forget` and the permission toggle already do, so the reservation reaches the directory before the device can speak from it. Observed on the K1: an address move cost ~6 min of NXDOMAIN; the reap itself was already prompt. * docs(start-wrt,core): cut the DNS-injection comments and docs to the facts Review on #3999 asked for mannered prose to go, and this branch carried the same habit: a 48-line module doc that argued its own threat model, function docs of four to nine lines listing the cases that trigger a rule and comparing it to PCP, test docs narrating what the test name states, and book pages and a changelog entry that explained the mechanism to the user. Each comment is now one fact. The nft include's header keeps the field offset, the priority and the kmod dependency and drops the rest; the init-script comment says what it creates and when. The devices page, the FAQ entry, the published-ports paragraph and the StartOS private-domains paragraph lose the rationale; the changelog entry splits the DoH canary into its own bullet and states what a user gets. API_CONTRACT's two new methods lose the "deliberately no manual counterpart" reasoning. No code line changed: rustfmt, prettier, startwrt 590 + uciedit 18 + start-core dns_update 9, and both books are clean, and the nft rule lines and stage-files.sh code are byte-identical. * docs(start-wrt): DNS record publishing is for any RFC 2136 client The devices page named a StartOS server as the user of the toggle and never said a plain RFC 2136 client works. It does: the unsigned tier is stock DNS UPDATE over UDP, and nsupdate published from a laptop on the bench. * fix(start-wrt,core): unsigned DNS UPDATEs must arrive over TCP The unsigned tier trusted the UPDATE's source address, and a UDP source is free to forge on a LAN. The own-address rule kept a forged add harmless, but a delete carries no address to compare: any LAN host could spoof a permitted device and withdraw its records, or spoof an inbound WireGuard peer's tunnel address on the bridge and act as that peer. `pre_update` now receives an `UpdateAuth` carrying the transport beside the TSIG verdict, and StartWRT's policy refuses an unsigned UPDATE that did not arrive over TCP. A TCP handshake proves the source can receive at the address it claims, which on a switched LAN leaves only an attacker who can already take that address over. A TCP SYN carries no opcode, so the nft include now diverts every TCP connection to the router's port 53. The daemon answers UPDATEs itself (`DnsInjector::answer_update`) and relays every other message byte for byte to the profile's dnsmasq over one upstream connection per client, so TCP queries keep dnsmasq's answers, including the per-profile visibility the injector's own store does not apply. Clients are capped at 16 per listening socket with a 10 s idle limit. The divert's rate limit bounded the refusal log only for UDP, so refusals now log through a box-wide 20/s budget instead. The StartOS client sends an unsigned UPDATE over TCP; a signed one stays on UDP, so StartTunnel is unchanged. An `nsupdate` user now needs `-v`, which the book and changelog say. Tests: startwrt 592 + uciedit 18, start-core dns_update 11 (new: unsigned UDP refused including a spoofed WG peer address, the TCP listener answering an UPDATE and relaying a query untouched, the UPDATE response echoing id and zone, the client's TCP framing). Not yet on hardware. * fix(start-wrt,core): refuse DNS names that resolve publicly elsewhere Once the unsigned tier's source is proven over TCP, the rule that a record must point at its own source address guards nothing. A device that wants to hijack a name points it at itself, which is exactly the shape the rule allows, and the only other limit on the name was `lan.`. A device with the permission could publish `www.google.com` or a bank's login host to every profile that can reach it. The names worth hijacking are the ones the public DNS already answers. `policy` now looks every added name up through the router's main dnsmasq instance, which serves no injected records, and refuses one that resolves to any address other than the router's WAN address. A name with no public records is still allowed, as is one already routed to this router. A failed lookup refuses. Special-use zones (`local.`, `home.arpa.`, `internal.`, `test.`, `invalid.`, `localhost.`, `example.`) skip the lookup, so a StartOS server's `.local` name still publishes with the WAN down. Deletes never look anything up. The check applies to the signed tier too. To make room for the lookup, `pre_update` returns a future. The policy checks the directory, releases it for the lookups, then re-checks and claims under the lock, and it refuses an unknown source before it looks anything up. The own-address rule is gone: an unsigned update may point an A/AAAA record anywhere. The sweep therefore keys a LAN record's life to the address it was published from rather than the address it points at. The WAN addresses join the directory on each refresh. Consequences worth knowing: - The private side of a StartOS split-DNS domain is refused, since its public record points at the StartTunnel gateway. The StartOS book says so and points at the manual path. - A router behind CGNAT or another NAT has a WAN address that public DNS does not use, so a public name routed to it is refused. - A name registered after publication keeps its record until the owner next re-asserts; StartOS re-asserts with a delete and an add, so its records are re-checked every 180 s. Tests: startwrt 594 + uciedit 18, start-core dns_update 11. New: a publicly resolving name refused whether it points elsewhere or partly elsewhere, a failed lookup refused, a WAN-routed or unregistered name admitted, special-use zones and deletes never looked up, and the sweep following the publishing address rather than the target. Not yet on hardware. * fix(start-wrt): DNS-injection listeners survive the bridge being rebuilt The listeners were bound to their profile's bridge with SO_BINDTODEVICE, which pins the socket to an interface index. netifd rebuilds the bridge under a new index on `ifup lan` or on saving a profile, and the sockets kept their place in the listing while the kernel refused every packet to them. The listener sync only rebinds when a profile's configuration changes, so they stayed dead until the daemon restarted. Before the TCP divert this silently broke UDP publishing; with it, every TCP DNS query to the router was refused. Reproduced on the bench with `ifup lan` (index 13 -> 16), and a daemon restart cleared it. The listeners now bind each profile's gateway address with no device, and with IP_FREEBIND, so a bind made while the address is momentarily absent succeeds and the socket keeps serving the address across the rebuild. The device binding was the arrival-interface guarantee from the RFC; it guards nothing now that an unsigned update must complete a TCP handshake and a UDP update must carry a TSIG. SO_REUSEADDR stays on the TCP listener only, so no stale UDP socket can share the port. Tests: startwrt dns_inject 18 (new: binding an address the host does not hold). * fix(start-wrt): the public-name check sees answers naming private addresses The check asked the main dnsmasq instance, whose rebind protection strips any public answer naming a private address and returns an empty NOERROR. The check read that as "no public records" and admitted the name, so a public name resolving to an RFC 1918 address could still be shadowed. On the bench `192.168.0.5.nip.io` published while dnsmasq logged "possible DNS-rebind attack detected"; a name pointing at the WAN passed for the same wrong reason. The lookup now goes to the servers the main dnsmasq forwards to: the SmartDNS system group on 127.0.0.1:5300 when system DNS is set, else the nameservers in resolv.conf.auto, read when the lookup runs so a DNS mode change applies at once. With no upstream known, the lookup fails and the publish is refused, as any failed lookup is. Tests: startwrt 596 + uciedit 18 (new: upstream selection in both system DNS modes). * fix(start-wrt): publishing no longer depends on public DNS Publishing is a permission granted to a trusted device. A malicious publisher can direct clients to itself whatever its records may name, so the public-DNS gate guarded nothing that the grant does not already decide. Meanwhile it refused the private half of a StartOS split-DNS domain, refused names behind an upstream NAT, and refused every publish while upstream DNS was unreachable. The gate, its upstream lookup, and the WAN addresses the refresher collected for it are removed. With no await between them, the policy check and the ownership claim run under one directory lock. TCP source verification, TSIG, ownership, the record-type tiers, the `lan.` reservation and the source-keyed sweep are unchanged; start-core's async `pre_update` stays as it is. Two offline regressions drive a real UPDATE through `answer_update` for a public name: unsigned over TCP and TSIG-signed. Both returned REFUSED under the gate. Patch proposed by Helix in review of #4055. Tests: startwrt 640 + uciedit 18, start-core dns_update 11. * chore(start-wrt): bump to 1.3.0 for DNS record publishing DNS record publishing is a new feature, so the unreleased 1.2.2 becomes 1.3.0. Its changelog entry and the Firefox DoH canary entry move out of the released 1.2.0 section, where they landed before 1.2.0 was cut, into 1.3.0's Added. The 1.2.2 release notes become 1.3.0's and lead with the feature. * docs(rfcs): record the TCP divert and box-wide injection predicate Option B still said UPDATE ingress was UDP-only and needed no TCP rule, and the instance-creation sketch still took a profile. Both are recorded as amendments to match the implementation: TCP to the router's port 53 is diverted whole and relayed, and `has_dns_injection` is box-wide.
…-override # Conflicts: # projects/start-os/CHANGELOG.md # projects/start-os/web/ui/src/app/services/gateway.service.ts # shared-libs/crates/start-core/src/db/model/public.rs # shared-libs/crates/start-core/src/net/gateway.rs # shared-libs/crates/start-core/src/net/host/binding.rs # shared-libs/crates/start-core/src/net/host/mod.rs # shared-libs/ts-modules/shared/src/i18n/dictionaries/de.ts # shared-libs/ts-modules/shared/src/i18n/dictionaries/en.ts # shared-libs/ts-modules/shared/src/i18n/dictionaries/es.ts # shared-libs/ts-modules/shared/src/i18n/dictionaries/fr.ts # shared-libs/ts-modules/shared/src/i18n/dictionaries/pl.ts # shared-libs/ts-modules/start-core/lib/osBindings/NetworkInterfaceInfo.ts # shared-libs/ts-modules/start-core/lib/osBindings/index.ts # shared-libs/ts-modules/start-core/lib/osBindings/tunnel/NetworkInterfaceInfo.ts
Helix-Harness: pi Helix-Model: openai-codex/gpt-6.1-sol
|
Updated release metadata for #4459: pending fragments declare their audience and unreleased notes retain framing/notices only; Highlights compile from the fragments. Inherited pending SDK 3.1.2 metadata is migrated where present. Published notes and implementation files are unchanged. The current master compiler validated/rendered this PR’s migrated metadata overlaid on current master, and scoped pinned-Prettier checks passed. This metadata-only update does not resolve older inherited histories/manifests or pre-existing integration conflicts; the branch still needs its normal base refresh before release. |
|
Closing in favour of #4666, which carries only the renumber and link-drop fix. The manual WAN IP override is dropped. Its main case was a server whose outbound traffic leaves through a VPN on its router, so detection reports the VPN exit instead of the WAN. Putting the server behind StartTunnel covers that case: StartTunnel's IGD answers per peer and honours #4666 also changes one piece of this PR's logic. An opt-in now extends to the replacement address even while another gateway still offers the old one. Without that, a server dual-homed on one router lost the opt-in when one link went down. The new PR's body has the details. |
…cross a renumber (#4666) * fix(core): keep a public-IP opt-in across a gateway renumber or link drop A public IP's opt-in is stored as the literal `ip:port` in `enabled` (and a GUA's in `gua_wan`), and nothing moved it when the address changed. A rolled DHCP lease, a moved IPv6 prefix, or a PPPoE reconnect therefore brought the replacement up switched off, dropped its port forward, and said nothing. master's plain-domain grouping (#4616) carries the setting only for a plain port with a public domain on the same gateway; a bare public `ip:port` had no such cover. `migrate_renumbered_ips` runs in `derive_addresses` for single-port bindings and ranges. Where a gateway offered exactly one public address on a port and family before and after, an opt-in on the old address extends to the new one. The old address keeps its opt-in while another row still offers it, so a server dual-homed on one router keeps the address its other link holds. A gateway NetworkManager drops has its `ip_info` cleared, and its rows used to leave `available` with it, so a gateway that came back on a new lease had no previous address to carry from. `carry_forward` keeps a downed gateway's public IPv4 and GUA rows until it returns or is deleted. Port forwards still need the live gateway and lapse while it is down. Split from #3999, without its manual WAN IP override. * Proposed changes for #4666 Helix-Harness: pi Helix-Model: openai-codex/gpt-6.1-sol * fix(core): keep a GUA opt-in until the reconnected gateway reports a GUA The first ip_info after a link drop can carry DHCPv4 before SLAAC: poll_ip_info publishes on every address change. carry_forward now keeps a gateway's GUA rows until it reports a GUA, mirroring the public IPv4 rule, so the renumber migration still finds the old address when the new one arrives. * revert(core): drop the renumber migration ahead of gateway-keyed public opt-ins Helix-Harness: claude-code Helix-Model: claude-opus-5-5 * fix(core): key public IP opt-ins by gateway so they survive a renumber Store a public IPv4 opt-in as (gateway, port) and a GUA opt-in as (gateway, port, interface identifier) instead of the literal WAN ip:port. The opt-in resolves against whatever address the gateway currently reports, so a new DHCP lease, a moved IPv6 prefix or a link drop no longer switches the address and its port forward off. - DerivedAddressInfo.enabled and gua_wan hold PublicIpKey. - 0.4.3's migration (revision 1) rewrites stored socket-address opt-ins as the keys of the rows they select, dropping unmatched ones. - forget_gateway drops every opt-in keyed to the removed gateway. - start-core TS gains publicIpKey/samePublicIpKey; the legacy projection still accepts socket-address strings from servers without `effective`. - Regenerated TS bindings and MCP catalog; UI mock data uses the keys. Helix-Harness: claude-code Helix-Model: claude-opus-5-5 * feat(start-os): mark IPv6 addresses whose opt-in switches together A GUA opt-in keys on its interface identifier, so every GUA on the gateway and port with that identifier (another prefix, or the old prefix during a renumber) switches with it. The gateway table now marks such rows with a link icon whose tooltip says so. The UI derives GUA-ness from start-core's publicIpKey instead of its own parser. Helix-Harness: claude-code Helix-Model: claude-opus-5-5 * docs(start-os): explain that IPv6 settings follow the interface ID Helix-Harness: claude-code Helix-Model: claude-opus-5-5 * fix(core): keep legacy getHostInfo readers and every gateway's opt-in - getHostInfo serves `enabled` as socket addresses, the form SDKs before `effective` match, for bindings and port ranges alike. - The 0.4.3 upgrade keys an opt-in on every row it selects, so a WAN IP two gateways share stays on for both; one unreadable row no longer drops a binding's opt-ins. - Forgetting an interface drops its selections through the same Model<Host>::forget_gateway the tunnel removal uses. - The link icon, docs and changelog name only the Local/Public choice and the toggle while Public as shared. Co-authored-by: helix-white <helix-white@users.noreply.github.com> Helix-Harness: claude-code Helix-Model: claude-opus-5-5 * fix(core): keep a range's public IP on with its plain public domain Drop the gateway-keyed public opt-ins: a public IP opt-in stays the literal ip:port, and an operator who needs a stable public address uses a public domain with DDNS. On a plain port, an enabled public domain already carries its gateway's public IPv4 and GUA across a renumber for single-port bindings. update_addresses never re-resolved those groups for port ranges, so a range's public IP stayed off after a link drop or new lease. Resolve them for ranges too. Helix-Harness: claude-code Helix-Model: claude-opus-5-5 * docs(core): record that a public IP opt-in lapses on a renumber Helix-Harness: claude-code Helix-Model: claude-opus-5-5 * fix(core): keep a renumbered range's plain domain on through the upgrade Released versions never resolved plain-domain groups for ranges, so a range renumbered before the upgrade holds an enabled plain domain beside an off WAN IP. Resolving its group from that state would switch the domain off. 0.4.3 (migration revision 1) switches on the group of each enabled plain public domain on a range first. Co-authored-by: helix-white <helix-white@users.noreply.github.com> Helix-Harness: claude-code Helix-Model: claude-opus-5-5 --------- Co-authored-by: helix-a <267227783+helix-a@users.noreply.github.com> Co-authored-by: helix-red <355572797+helix-red@users.noreply.github.com> Co-authored-by: helix-white <helix-white@users.noreply.github.com>
Why
StartOS derives a gateway's WAN IP by asking the router over UPnP and, failing
that, by reading back the address an outbound request appeared to come from.
Those answer different questions: the router is authoritative about where
inbound traffic arrives, while an echo service can only report where outbound
traffic left. Where the two differ and UPnP cannot settle it — multi-WAN
routing, an ISP translating egress from a pool separate from the mapped inbound
address, a cloud floating ingress address, a router with UPnP off or reporting
a stale one — detection names an address the server is not reachable at, and
every address derived from it points somewhere wrong: offered public addresses,
the port-forward rules the UI asks for, the TLS served name, and any address a
service advertises to peers. There was no field an operator could correct;
discovery rewrote it on every poll.
Public-IP exposure is also keyed on the literal address.
enabledandgua_wanare written by operator action and nothing moved them when theaddress changed, so a rolled lease or a moved prefix left the replacement off
by default, dropped its port forward, and said nothing. A manual override would
have been the same event, so that had to be fixed first.
What
wan_ip_overrideonNetworkInterfaceInfo, besidenameandsecure.wan_ip()resolves it over the detected value; every consumer reads it.Discovery keeps writing
ip_info.wan_ip, so clearing restores it.net gateway set-wan-ip/unset-wan-ip— command line only. Unroutableaddresses and outbound-only gateways are refused.
listmarks a pinnedaddress
(manual). The web UI reads the override, so the gateway table, theDNS checks and domain validation all test the pinned address, but it offers
no way to set one: this corrects a fact about your network that StartOS got
wrong, not a setting to reach for.
migrate_renumbered_ipsmoves an opt-in to the address that replaced it,from
update_addresses, so a detected renumber and a manual override are thesame event. It moves only within the same gateway, port and family, and only
when exactly one public address is offered there before and after.
carry_forwardkeeps a downed gateway's IP rows so the migration alsosurvives a link drop, a router reboot, and boot. A downed gateway keeps
offering its last public addresses until deleted; its port forwards lapse while it
is down.
Compatibility
No db migration: the field has a serde default and an older binary ignores it.
Bindings regenerated, backend and CLI strings in five locales, changelog under
0.4.0.2,
gateways.mdgains a WAN IP section.Testing
Unit tests cover override precedence, the legacy row, validation, every
migration shape, and the full
update_addressespath for a detected renumber,an override set and cleared, a second gateway, a range, a link drop, and a
deleted gateway, with port forwards checked in each.
cargo test,cargo fmt,the UI build, i18n and prettier are clean.
http_reader::main_testfails onmaster too; it fetches a live URL.
Not yet exercised on a box. To do before merge:
set-wan-ipthenunset-wan-ip; addresses and port forwards follow, andthe UI's gateway table and domain validation track the pinned address
Start here
net/host/binding.rsmigrate_renumbered_ips,net/host/mod.rscarry_forward,net/gateway.rsset_wan_ip_override.