Skip to content

rtl: keep RTL's port held by systemd while RTL is down - #293

Merged
prusnak merged 2 commits into
bitcoinix:masterfrom
ostermayer:rtl-ui-socket
Nov 21, 2026
Merged

prusnak merged 2 commits into
bitcoinix:masterfrom
ostermayer:rtl-ui-socket

Conversation

@ostermayer

@ostermayer ostermayer commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #262.

RTL's web interface is plain HTTP with one password. Without netns-isolation, any local user can bind RTL's address and port while RTL is stopped, and since #250 RTL stops each time lnd or clightning stops. The user can then serve a fake login page and collect the password that the operator types through the SSH tunnel.

RTL 0.15.17 can listen on a unix socket without a patch. It takes a port that isn't a number as a path, and listens there when host isn't set. So without netns-isolation, this PR:

  • moves RTL to /run/rtl/rtl.sock. /run/rtl is RTL's runtime dir with mode 0700, which systemd creates for each start and removes at each stop. No other user can create the path, and a stale socket never blocks a start.
  • adds a socket unit rtl-proxy-<hash>.socket that listens on services.rtl.address and port from boot on and doesn't stop with RTL. It has RTL's IP filter, so tor.enforce still applies, and FreeBind, so it can start before an address like a WireGuard IP exists. Like RTL's own listener, it turns IPV6_V6ONLY off (BindIPv6Only=both), so :: also holds IPv4 and a v4-mapped address binds when net.ipv6.bindv6only is set. The filter has to be on the socket unit, because systemd doesn't apply a service's IP filter to sockets that it passes in.
  • adds rtl-proxy.service, which runs systemd-socket-proxyd as RTL's user, because only that user can reach the socket. It has defaultHardening, no network of its own, only AF_UNIX, and no access to RTL's data dir, the secrets dir or the local resolvers. Like RTL, it starts only after the secrets are set up. While the data dir or the secrets dir is missing, it fails to start and retries, so it never runs without their masks.
  • keeps the port held across switches. A switch doesn't restart a changed socket unit, so the unit name carries a hash of the address and port, and a new address gives a new unit. A switch that changes only the proxy leaves the socket alone, since the proxy has no rtl-proxy.socket and no Sockets=. stopIfChanged = false makes the switch restart the proxy after its daemon-reload. Otherwise the switch stops it before the reload and starts it after, and a connection before the reload starts the old unit, which then keeps running. The proxy restarts with a back-off and no start limit, because systemd closes a socket whose service hits the limit.
  • unsets PORT and HOST for RTL, also when they come from an EnvironmentFile. RTL prefers them to its config file, so they would move it off its unix socket.
  • checks services.rtl.address when the system is built. systemd skips a ListenStream= that it can't parse, like one with a host name or a zone ID, and without a listener it refuses the unit. Neither the switch nor the boot fails then, and nothing holds the port. A path or a name that starts with @ gives a unix socket, which holds no port either. So a system.checks entry runs Python's ipaddress module from pkgs.buildPackages.python3 on the address, and the build fails unless it's a numeric IP address without a zone ID. The error names the address. The address reaches Python through the environment, not through the code. The check reads no system state, so the build host's kernel doesn't matter. The option stays a string, with no parser in Nix.
  • rejects port = 0 with an assertion, since systemd can't listen on it. RTL used to take 0 as 3000.
  • adds a 0.2.0 notice, release and upgrade note drafts in docs/release-notes/0.2.0/ and docs/upgrading/0.2.0/, and a paragraph in docs/services.md.

While RTL is stopped, a connection reaches the proxy, which can't reach RTL and closes it. A user who tries to bind the port gets Address already in use. The SSH tunnel, the onion service and nodeinfo keep working with no config change.

With netns-isolation nothing changes. RTL's address exists only in its namespace, which only root can enter. Joining the socket unit to that namespace would need hand-written boot ordering around sockets.target and netns-rtl, which is more risk for no gain.

Testing

  • test_rtl logs in through RTL's address and port and makes an authenticated API call, and does the same at the onion service's target. Then it stops RTL and checks that nobody can't bind the port and that a connection gets no answer. Without netns-isolation it also checks that 20 failed connections and six proxy kills leave the socket listening and held by systemd, and that the UI works after RTL's restart. Each kill must succeed and hit a new proxy. The test config gives the proxy a fixed 100 ms restart delay, so the six restarts would hit systemd's default start limit if the proxy had one. Its 2FA checks now use RTL's address and port too, not 127.0.0.1:3000.
  • The bind check fails on master, where nobody binds 127.0.0.1:3000 in the default scenario.
  • The new rtlIPv6 scenario runs test_rtl with RTL on ::1 and lnd. run-tests.sh buildable runs it, and the CI matrix doesn't. So the node's kernel must let systemd listen on an IPv6 address, and nobody must fail to bind it.
  • default, netns, regtest, netnsRegtest and rtlIPv6 pass on a KVM host. One earlier regtest run failed because an outgoing connection took Fulcrum's port 50002, which is in the ephemeral range, and the rerun passed. module-config passes with new cases for IPv6, BindIPv6Only, the unit name, UnsetEnvironment, port 0 with and without netns-isolation, the notice and that it doesn't name a host name, the build check, the socket's IP filter with and without tor.enforce, and the proxy's sandbox. The last two fail when the socket gets another IP list or none, or when the proxy loses PrivateNetwork, its user, the AF_UNIX-only list or a mask, or gets a - on a mask. The address check must fail with its message, which names the address, for localhost, fe80::1%lo, /run/rtl/frontend.sock, @rtl-ui and 1.2.3, and pass for 127.0.0.1, ::1, ::ffff:127.0.0.1, 0.0.0.0 and ::. module-config fails when the check takes a zone ID, ignores Python's exit status, runs with netns-isolation or is gone, and when the socket unit loses BindIPv6Only. test-runner, the release notes check and test/shellcheck.sh pass too. The tor-enforce test now skips units without a network of their own, like rtl-proxy.
  • Ad hoc in a VM, not in this PR. A switch that changes only the proxy keeps the socket, and a nobody loop that tries to bind the port during the switch never gets it. With a unit that takes 5 seconds to stop and a connection every 0.1 seconds during the switch, the proxy runs the new unit after the switch, and without stopIfChanged = false it runs the old one. A port change moves the socket with no failed units, and so does the switch back. address = "::" serves IPv4 and IPv6. With tor.enforce, the socket drops a client from 127.0.0.2. RTL comes back after kill -9. From inside the proxy's namespaces, RTL's data dir and /proc/<rtl pid>/root aren't reachable. With secretsSetupMethod = "manual" and no secrets dir at boot, a connection makes the proxy fail with 226/NAMESPACE and retry, while the socket keeps the port. Once the dir exists, the proxy starts and sees it empty, and the UI works. With - masks, the proxy started and later saw all secret files. In the normal setup, a connection before setup-secrets waits for the secrets, and the proxy starts once. With PORT=3001 from an EnvironmentFile and HOST from environment, RTL keeps its unix socket, and without UnsetEnvironment it listens on 0.0.0.0:3001. With systemd's default start limit on the proxy, the crash loop closes the socket and the test fails. A burst of 1000 connections from nobody while the proxy fails or waits to restart leaves the socket active, since systemd holds the queued start until the restart. Without the build check and with address = "localhost" or "fe80::1%lo", at boot and after a switch from master's rtl.nix, the socket unit is bad-setting, the switch exits 0, no unit fails, nothing listens on port 3000, and nobody can listen there. With ::1 and ::ffff:127.0.0.1, the socket unit is loaded and active, systemd listens on the address, and nobody can't bind it. With the v4-mapped address, nobody can't bind 127.0.0.1:3000 either. With net.ipv6.bindv6only = 1 and without BindIPv6Only=both, :: held only IPv6, and nobody could listen on 0.0.0.0:3000, and ::ffff:127.0.0.1 failed to bind with Invalid argument. With it, nobody can't bind ::, 0.0.0.0, 127.0.0.1 or ::1 on port 3000, and the v4-mapped socket listens and serves http://127.0.0.1:3000.
  • Ad hoc nixos-rebuild build on the KVM host, not in this PR. The system build fails with the check's message for localhost, /run/rtl/frontend.sock, @rtl-ui, fe80::1%lo and 1.2.3, and port 0 fails at evaluation with the assertion. It builds for 127.0.0.1, ::1, ::ffff:127.0.0.1, 0.0.0.0, :: and port 8443, and with netns-isolation, where the system has no check. The check's build command passes for ::1 and ::ffff:127.0.0.1 and fails for localhost in a sandbox with no /proc and no /sys. Under strace, it opens nothing under /proc/net or /sys.

Known limits. The first switch to this version, a switch back, and a switch that changes the address or port free the port for a moment, so the notice suggests nixos-rebuild boot and a reboot. RTL sees no client addresses through the proxy, so five failed logins lock out every client for 30 minutes. With the default localhost setup that was already the case, since every client came from 127.0.0.1. The proxy shares RTL's user, so a compromised proxy could kill RTL, but it can't read RTL's files or memory. [::1]:3000 stays free as before, and the docs and the notice say to use the address and port that systemd holds in the tunnel. The PR doesn't parse address in Nix, so a bad address passes evaluation and fails only when the system is built. The node's kernel still decides if systemd can listen on an IPv6 address. On a node booted with ipv6.disable=1, systemd refuses the socket unit for one, and nothing holds the port. The upgrade note's systemctl list-units check shows that. The planned nbLib types can check the address at evaluation and replace the build check and the port 0 assertion.

Written with Claude Opus 5.5, reviewed with Claude Fable 5.2, GPT-6 Astra, GPT-5.6 Sol, Kimi K3.1 Pro (twice), DeepSeek V4.1 Flash, GLM 5.3 and Qwen4-Max.

@ostermayer ostermayer added the type: security Hardening or vulnerability (public-safe only) label Nov 18, 2026
@github-actions github-actions Bot added area: ci .github/, test/, dev/ area: docs docs/, README, examples/, SECURITY.md, book.toml, assets area: modules modules/ and pkgs/lib.nix type: feature New capability or service labels Nov 18, 2026
@seberm

seberm commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Should

  • Drop nbLib.allowLocalIPAddresses from rtl-proxy and the rtl-proxy entry in the tor-enforce list in test/tests.nix. With PrivateNetwork = true and RestrictAddressFamilies = "AF_UNIX" the allow list does nothing, and systemd doesn't apply a service's IP list to sockets passed in by socket activation. defaultHardening's IPAddressDeny = "any" alone is stricter. InaccessiblePaths is already set explicitly. I checked this in a VM with the same socket and proxy setup: with only IPAddressDeny=any on the proxy, requests through the socket still work.
  • Drop stopIfChanged = false and its comment. switch-to-configuration-ng only stops a service's sockets when it lists them in Sockets= or when <name>.socket exists, and rtl-proxy has neither. Checked in the same VM: a switch that changes only the proxy stops and starts rtl-proxy.service, while the socket stays active and holds the port the whole time. A nobody loop trying to bind the port during the switch never got it.
  • Lock the socket's IP filter in test/configuration.nix: assert that the rtl-proxy-* socket's IPAddressAllow/IPAddressDeny equal RTL's with tor.enforce on. It keeps tor.enforce working and is currently only tested by hand.
  • Lock the proxy sandbox: assert User, PrivateNetwork, RestrictAddressFamilies and that InaccessiblePaths contains dataDir and the secrets dir (eval test), or check from inside the proxy that RTL's data dir isn't reachable (VM test).

Assisted-by: Claude Code (Claude Opus 5.5)

@github-actions github-actions Bot added the status: rebase needed Merge conflicts need to be resolved label Nov 19, 2026
@prusnak prusnak added this to the v0.2.0 milestone Nov 20, 2026
@ostermayer ostermayer removed the status: rebase needed Merge conflicts need to be resolved label Nov 20, 2026
@ostermayer

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. All in 30a1c8d.

  • Dropped nbLib.allowLocalIPAddresses from rtl-proxy and its entry in the tor-enforce list. You're right that the allow list did nothing there. The proxy still masks the resolver sockets, so the tor-enforce test still picked it up through /run/nscd and failed with "unexpected". It now skips units with PrivateNetwork, and the new sandbox test checks the proxy's masks instead.
  • Kept stopIfChanged = false, with a new comment. You're right that a switch never stops the socket, and the old comment was wrong. But without the setting, a switch stops the proxy before its daemon-reload and starts it after. The socket keeps listening, so a connection before the reload starts the old unit again, and the later start leaves it running. I saw this in a VM with a unit that takes 5 seconds to stop and a curl every 0.1 seconds during the switch. The proxy kept the old unit's environment after the switch. With the setting, the switch restarts the proxy after the reload and it runs the new unit. In both cases the socket stayed active, and a nobody bind loop during the switch never got the port.
  • Also ordered rtl-proxy after nix-bitcoin-secrets.target, like RTL. InaccessiblePaths skips a secrets dir that doesn't exist yet, so a connection at boot could otherwise start the proxy without that mask.
  • Added testRtlProxySocketIPFilter. It checks that the socket's IPAddressAllow and IPAddressDeny equal RTL's, with tor.enforce on and off.
  • Added testRtlProxySandbox. It checks User, PrivateNetwork and RestrictAddressFamilies, and that InaccessiblePaths has the data dir, the secrets dir and the resolver masks, the masks without a -. The two tests fail when the socket gets another IP list or none, or when the proxy loses PrivateNetwork, User, the secrets dir or the AF_UNIX only list, or gets a - on a resolver mask.
  • Rebased on master (90b7533). The release and upgrade notes are now drafts in docs/release-notes/0.2.0/ and docs/upgrading/0.2.0/.
  • default, netns, regtest and netnsRegtest pass on a KVM host, and so do module-config, test-runner and the release notes check.

@viberaven viberaven left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The systemd-owned listener addresses the original port-ownership issue for the default configuration. I’m requesting changes because the proxy can start without its secrets mask, an environment file can move RTL off its Unix socket, and the migration notice can direct operators to an address systemd does not hold.

I built module-config and test-runner locally on 30a1c8d8, evaluated the configuration cases in the inline comments, and checked the generated listener syntax with systemd-analyze verify. The VM results I used are from the passing GitHub Actions run. CI results

Reviewed with Codex (gpt-6.2-astra).

Comment thread modules/rtl.nix Resolved
Comment thread modules/rtl.nix Resolved
Comment thread modules/rtl.nix Resolved
Comment thread modules/rtl.nix Resolved
Comment thread test/suite/services.py Resolved
@prusnak

prusnak commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Like in the other PR - I suggest to drop IP address validation from the PR. Let's just pass them as string.

We can add PR in the future that replaces all such usage with types in nbLib - I already have such PR in the making.

@ostermayer

Copy link
Copy Markdown
Collaborator Author

Thanks for the reviews. All in 6671559.

  • Dropped the IP address check, its assertion and its eval cases. The address is a plain string again, and the module only puts brackets around an address with a : for ListenStream=. So ::ffff:127.0.0.1 now gives [::ffff:127.0.0.1]:3000, which systemd-analyze 262 accepts. The upgrade note still says the address must be an IP address, since systemd doesn't take localhost.
  • Made the data dir and secrets dir masks in rtl-proxy fail closed, and testRtlProxySandbox now requires both without a -. I checked it in a VM with secretsSetupMethod = "manual" and no secrets dir at boot. A connection started the proxy, which failed with 226/NAMESPACE and kept restarting with the back-off. The socket stayed active and nobody couldn't bind the port. Once setup-secrets created the dir, the next restart worked and the proxy saw /secrets empty. The UI worked after the rest of the node came up. With the old - masks, the proxy in the same VM saw all 11 secret files. In the normal setup, a connection before setup-secrets waited for the secrets target, and the proxy started once with no failed start.
  • Set UnsetEnvironment = [ "PORT" "HOST" ] on rtl.service and dropped the PORT and HOST assertion. systemd.exec(5) says it's applied last and also undoes Environment= and EnvironmentFile=. In a VM with PORT=3001 from an EnvironmentFile and HOST from environment, RTL had neither in its environment, listened on its unix socket, and the UI worked. Without UnsetEnvironment, RTL listened on 0.0.0.0:3001. testRtlProxySocket checks the setting, with and without netns-isolation.
  • The notice now names the address and port that systemd holds, with loopback for a wildcard address. So :: gives [::1]:3000, and testRtlProxySocket checks that. The upgrade note and docs/services.md say that 127.0.0.1:3000 is the default and to use the address and port you set otherwise.
  • Left port 0 for the nbLib types PR. You're right that it gives 127.0.0.1:0, which systemd rejects.
  • The crash loop now uses succeed for each kill and waits for a new nonzero MainPID before the next one. The test config gives rtl-proxy a fixed 100 ms restart delay. The default VM log now shows six kills and restart counters 1 to 6 in about 2.5 seconds. With systemd's default start limit on the proxy, the loop fails, because systemd closes the socket with service-start-limit-hit.
  • Rebased on master (cbc2310). test.data.rtl now reads config.tests.rtl or false, since scenarios with tests = mkForce { ... } have no tests.rtl. It's the same bug as test: let scenarios that replace the test set evaluate again #306.
  • default, netns, regtest and netnsRegtest pass on a KVM host, and so do module-config, test-runner, the release notes check and test/shellcheck.sh.

@ostermayer
ostermayer requested a review from viberaven November 20, 2026 18:49

@viberaven viberaven left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified five fixes from the previous review on 66715593. The proxy now requires both directory masks, rtl.service clears PORT and HOST from its final environment, the tunnel notice uses the correct destination for custom numeric binds, and systemd accepts the generated IPv4-mapped IPv6 listener. The default VM log also shows six distinct proxy PIDs killed and restart counters 1 through 6. Local module-config and test-runner checks passed. Default VM log

The port-zero finding is still open. RTL 0.15.17 previously treated a JSON port of 0 as its default of 3000. This revision passes evaluation and generates ListenStream=127.0.0.1:0, which systemd-analyze verify rejects. A nonzero-port assertion scoped to the proxy, or preserving the old fallback, would address this independently of the planned IP address types. Original port-zero thread

I found two migration cases in the revised code and notes, detailed inline. Both can be addressed while keeping services.rtl.address a string.

Reviewed with Codex (gpt-6.2-astra).

@sebsgent sebsgent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No must/should items from me beyond viberaven's open threads; the localhost and scoped-IPv6 cases matter beyond the notice wording, since systemd then holds no port and the attack this PR closes stays open for those configs.

Checked: the proxy's user has no extra groups, so with RTL's data dir and the secrets dir masked it can't reach the lnd macaroon or the CLN rune; the socket's IP filter matches RTL's in both tor.enforce cases; nodeinfo and the onion target are unaffected; the PrivateNetwork skip in the tor-enforce test doesn't drop any unit currently on master. Merges cleanly with master; relied on CI for the VM scenarios.

Assisted-by: Claude Code (Claude Opus 5.5)

@ostermayer

Copy link
Copy Markdown
Collaborator Author

Thanks for the reviews. All in 1bf81ae.

  • Added an assertion that rejects services.rtl.port = 0 when the socket unit holds the port. Its message says that RTL used to take 0 as 3000. testRtlProxySocket checks 0, 1, and 0 with netns-isolation, where RTL listens itself and still takes 0 as 3000. The nbLib types PR can replace the assertion.

  • sebsgent was right that a host name or a zone ID leaves the attack open. systemd skips the ListenStream= that it can't parse and refuses the socket unit, but neither the switch nor the boot fails. I checked it in VMs that booted with localhost and with fe80::1%lo, and again after a switch from master. The socket unit was bad-setting, no unit failed, and nobody could listen on 127.0.0.1:3000 and [::1]:3000. So the system build now runs systemd-analyze --user verify on the socket unit and fails with systemd's error. That needs no address parser in Nix. With address = "localhost", nixos-rebuild build now stops here.

    error: Cannot build '/nix/store/f9v0dicrrwj0cnijixl64v3ypjswdk41-check-rtl-proxy-79cbb35a.drv'.
           Reason: builder failed with exit code 1.
           Output paths:
             /nix/store/6sk60kfda2iw6991gjmpxnxg762c5r3f-check-rtl-proxy-79cbb35a
           Last 3 log lines:
           > /build/rtl-proxy-79cbb35a.socket:9: Failed to parse address value in 'localhost:3000', ignoring: Invalid argument
           > rtl-proxy-79cbb35a.socket: Unit has no Listen setting (ListenStream=, ListenDatagram=, ListenFIFO=, ...). Refusing.
           > Unit rtl-proxy-79cbb35a.socket has a bad unit file setting.
    

    The check fails on any line that systemd would skip, and it runs only without netns-isolation. The socket unit escapes % in the address, since %i in a zone ID like %ib0 would expand to nothing and leave a valid address. The check also fails for port 0 if the assertion is gone. module-config builds it for localhost, fe80::1%lo, fe80::1%ib0, port 0 and an IPAddressDeny that systemd skips, where it must fail with systemd's message, and for three addresses that systemd takes.

  • The notice, the upgrade note and the release note now say that the address must be a numeric IP address without a zone ID, and that a host name or a zone ID fails the build. The notice names no address. It says to use the socket unit's address and port once systemctl list-units --all 'rtl-proxy-*.socket' shows the unit active, 127.0.0.1:3000 by default, and 127.0.0.1 or [::1] for a wildcard. docs/services.md and the upgrade note give the same mapping for a wildcard.

  • Restored the zone ID restriction in the upgrade note, and added it to the notice and the release note. The module doesn't render scoped addresses.

  • Rebased on master (8a678bb). test: let scenarios that replace the test set evaluate again #306 fixed test.data.i2pd, and test.data.rtl keeps its or false, since it's new in this PR.

  • default, netns, regtest and netnsRegtest pass on a KVM host, and so do module-config, test-runner, the release notes check and test/shellcheck.sh. module-config fails without the assertion or its netns-isolation scope, and when the build check loses the % escape or --recursive-errors=no, ignores systemd's exit status, runs with netns-isolation or is gone.

@ostermayer
ostermayer requested a review from viberaven November 21, 2026 05:32

@viberaven viberaven left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All three findings from my last review are addressed. Port zero is rejected when the proxy owns the listener. Hostnames and scoped IPv6 addresses now fail the system build, and the migration notice explains how to change them before connecting. I built the x86_64-linux module-config and test-runner checks locally. The default VM and CI gate also passed on GitHub. CI run

I’m requesting changes on the new build check. It accepts Unix-domain listeners where the module promises a TCP listener, and the same valid IPv6 unit can pass or fail depending on the build machine. Both findings are detailed inline.

Reviewed with Codex (gpt-6.2-astra).

Comment thread modules/rtl.nix Resolved
Comment thread modules/rtl.nix Resolved
RTL's web interface is plain HTTP with one password. Without
netns-isolation, any local user could bind RTL's address and port while
RTL was stopped, for example while lnd or clightning was stopped,
serve a fake login page and collect the password.

RTL now listens on a unix socket in its runtime dir, which only RTL's
user can reach. A socket unit holds services.rtl.address and port from
boot on, and rtl-proxy runs systemd-socket-proxyd to forward each
connection to RTL. While RTL is stopped, a connection reaches the proxy
and fails. The socket unit has RTL's IP filter, since a service's own
filter doesn't apply to the connections that systemd passes in. Like
RTL's own listener, it turns IPV6_V6ONLY off, so that :: also holds
IPv4 when net.ipv6.bindv6only is set.

A switch doesn't restart a changed socket unit, so the socket unit's
name carries a hash of the address and port. A change then stops the old
unit and starts a new one. A switch that changes only the proxy, like a
systemd update, keeps the socket. The proxy has stopIfChanged = false,
so the switch restarts it after the daemon-reload. Otherwise the switch
would stop it before the reload and start it after. A connection before
the reload would then start the old unit, which would keep running. The
proxy restarts after a crash without a start limit, so systemd never
closes the socket for it. The proxy can't see RTL's data dir or the
secrets dir, and fails to start while one of them is missing. RTL's unit
unsets PORT and HOST, which RTL would prefer to its config file.

systemd skips a ListenStream= that it can't parse, like one with a
host name or a zone ID. Without a listener it refuses the socket unit,
but neither the switch nor the boot fails, and nothing holds the port.
A path or a name that starts with @ gives a unix socket, which holds no
port either. So the system build fails unless the address is a numeric
IP address without a zone ID. Python's ipaddress module checks it, and
reads no system state. systemd-analyze verify on the socket unit isn't
enough. It takes a unix socket, and it refuses an IPv6 address when the
build host's kernel has no IPv6. An assertion rejects port 0, which
systemd can't listen on. A 0.2.0 notice and upgrade notes cover the
first switch, which frees the port once, and the address.

With netns-isolation, RTL's address exists only in RTL's namespace,
which only root can enter, so RTL keeps listening on it directly.

Assisted-by: Claude Code (Claude Opus 5.5)
@ostermayer

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. All in 6e06292.

  • The build check now runs Python's ipaddress module on the raw services.rtl.address, and fails unless it's a numeric IP address without a zone ID. So a path or an @name fails the system build, and the error names the address. The option stays a string, with no parser in Nix, and prusnak's nbLib types PR can replace the check. With /run/rtl/frontend.sock, nixos-rebuild build now stops here.

    error: Cannot build '/nix/store/7qz051qkfqm94swjdd2vljjf9q4p0b13-check-rtl-address.drv'.
           Reason: builder failed with exit code 1.
           Output paths:
             /nix/store/qq5zwksqkk77pjl4514y4jv5ilpy07x1-check-rtl-address
           Last 1 log lines:
           > Error: services.rtl.address must be a numeric IP address without a zone ID, like 127.0.0.1 or ::1, not '/run/rtl/frontend.sock'
    

    With localhost it's the same error, with not 'localhost'.

  • systemd-analyze is gone, and so are its | cat, SYSTEMD_UNIT_PATH, --recursive-errors=no, the stub service and the %% escape. The address reaches Python through the environment, not through the code, and Python's parser reads no system state. In a sandbox with no /proc and no /sys, the check passes for ::1 and ::ffff:127.0.0.1 and fails for localhost. Under strace it opens nothing under /proc/net or /sys. For 30 edge cases like leading zeros, 127.1, embedded IPv4, upper case and whitespace, it agrees with the ListenStream= parser of systemd 262. The module-config tests of the generated socket unit still check its listener and its IP filter.

  • The new rtlIPv6 scenario runs test_rtl with RTL on ::1 and lnd. It checks the UI, that systemd holds the port, and that nobody can't bind it, on the node's kernel. run-tests.sh buildable runs it, and the CI matrix doesn't. test_rtl's 2FA check now uses RTL's address and port, not 127.0.0.1:3000. In ad hoc VMs with ::1 and ::ffff:127.0.0.1, the socket unit was loaded and active, and nobody couldn't bind the address. With the v4-mapped address, nobody couldn't bind 127.0.0.1:3000 either.

  • The socket unit now has BindIPv6Only=both, like RTL's own listener before. Node turns IPV6_V6ONLY off. Without it, a node with net.ipv6.bindv6only = 1 held only IPv6 on ::, so nobody could listen on 0.0.0.0:3000, and ::ffff:127.0.0.1 failed to bind. testRtlProxySocket checks the setting, and ad hoc VMs with the sysctl set show both cases fixed.

  • The notice, the upgrade note and docs/services.md now say that a host name, a zone ID or a socket path fails the system build. The PR body no longer lists the builder's kernel as a limit.

  • default, netns, regtest, netnsRegtest and rtlIPv6 pass on a KVM host, and so do module-config, test-runner, the release notes check and test/shellcheck.sh. module-config builds the check for localhost, fe80::1%lo, /run/rtl/frontend.sock, @rtl-ui and 1.2.3, where it must fail with its message and the address, and for 127.0.0.1, ::1, ::ffff:127.0.0.1, 0.0.0.0 and ::. It fails when the check takes a zone ID, ignores Python's exit status, runs with netns-isolation or is gone, and when the socket unit loses BindIPv6Only.

@ostermayer
ostermayer requested a review from viberaven November 21, 2026 16:28

@viberaven viberaven left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both findings from my previous review are fixed in 6e06292f. I ran the module’s address check with /proc and /sys hidden. It accepted ::1 and ::ffff:127.0.0.1, and rejected both a filesystem socket path and an abstract Unix socket name. IPv6 validation is now independent of the builder’s network support.

The local module-config and test-runner checks passed. I also ran the full rtlIPv6 KVM scenario. It passed, including an authenticated UI request over IPv6, the port-ownership check with RTL stopped, and recovery after six proxy restarts. The GitHub CI gate is green. CI run

Reviewed with Codex (gpt-6.2-astra).

@prusnak
prusnak enabled auto-merge November 21, 2026 17:16
prusnak
prusnak previously approved these changes Nov 21, 2026

@prusnak prusnak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@github-actions github-actions Bot added the status: rebase needed Merge conflicts need to be resolved label Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci .github/, test/, dev/ area: docs docs/, README, examples/, SECURITY.md, book.toml, assets area: modules modules/ and pkgs/lib.nix type: feature New capability or service type: security Hardening or vulnerability (public-safe only)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtl: the web UI is plain HTTP, so a local user who takes its port while RTL is down can collect the password

5 participants