Repository navigation
lndconnect: mount lnd's REST socket dir nosymfollow for tor - #346
Conversation
28adcb2 to
ae2d62c
Compare
|
Reviewed commit ae2d62c. One P2 finding to fix before merging. [P2] Decode escaped unit names in the dependency assertion — test/suite/networking.py:44–45
assert lnd_rest_mount in shlex.split(
succeed(f"systemctl show -P {prop} tor")
), propValidation:
No other actionable findings. I did not independently test a live configuration switch or rerun the full scenario matrix. Assisted-by: Codex (GPT-6 Astra) |
ae2d62c to
2d13e92
Compare
|
Thanks, fixed in 2d13e92 with your Assisted-by: Claude Code (Claude Opus 5.5) |
ostermayer
left a comment
There was a problem hiding this comment.
@sebsgent I ran our gate on 2d13e92 with Kimi K3.1 Pro twice, DeepSeek V4.1 Flash, Gemini 4 Carbon and GPT-6 Astra twice, and checked each finding against the code. The mount does what it should. Tor's view has ro,nosymfollow, a symlink fails with ELOOP, and a hard link or a rename from another dir into the self-bind fails with EXDEV, so lnd can't point tor at another socket. Three small points are left.
- lnd's socket keeps the mount busy. When lnd starts after the mount, for example on any lnd restart, its namespace gets a copy of the self-bind, and the bound
rest.sockholds a reference to that copy. While lnd runs,umount /run/lnd-restfails withtarget is busy. I reproduced this with a self-bind and a listener in a slave mount namespace. A switch that turns offlndconnect.onionstops lnd, tor and the mount at the same time, so the mount's stop can fail and the switch exits with an error.after = [ "run-lnd\\x2drest.mount" ]on lnd makes lnd stop first. The restart test doesn't catch this, because it stops lnd before the mount. - If
/run/lnd-restis missing when the mount starts, systemd creates it asroot:root 0755, and the self-bind still succeeds. Tor then starts, but lnd can't create its socket. Before this PR, tor'sBindReadOnlyPathsfailed on the missing dir. For example, runsystemctl stop lnd 'run-lnd\x2drest.mount', remove the dir and runsystemctl start tor.unitConfig.AssertPathIsDirectory = lndRestSocketDiron the mount makes the start fail before systemd creates the dir, and tor fails with it. - The boot check at
test/suite/networking.py:51fails when tor restarted before the test, for example withrun_test("lndconnect-onion-lnd-restart")and thenrun_test("lndconnect-onion-lnd")in a debug VM. It also fails when the test runs beforemulti-user.targetis active, because the target's timestamp is still 0. Line 50 passes when the mount never started, because the mount's timestamp is 0 too. TheRequiresandAfterchecks already cover the order, so line 51 can go, and0 <on line 50 catches a mount that never started.
2d13e92 to
486415b
Compare
|
@ostermayer Thanks, all three are in, amended into the single commit.
Assisted-by: Claude Code (Claude Opus 5.5) |
ostermayer
left a comment
There was a problem hiding this comment.
@sebsgent I reran our gate on 486415b with DeepSeek V4.1 Flash 1017 (max), Gemini 4 Carbon (high), Gemini 4 Neon (high), Claude Opus 5.5 (high) and GPT-6 Astra (max), and checked each finding against the code. The three changes do what they should, and AssertPathIsDirectory fails the mount before systemd creates the dir, so tor fails with it. A few points are left, and the first one matters most.
after = [ lndRestMount ]orders lnd's stop only when lnd stops in the same transaction. A stop or restart of the mount alone doesn't stop lnd, so the unmount fails withtarget is busyand tor stays down. That happens withsystemctl stop 'run-lnd\x2drest.mount', on a later switch that changes the mount unit (switch-to-configuration restarts a changed mount), and on a switch that turns the onion service off while lnd hasrestartIfChanged = falseorstopIfChanged = false, because lnd then isn't in the stop phase. All five models found this.partOf = [ lndRestMount ]on lnd fixes it, because the mount's stop or restart then includes lnd, and lnd still doesn't require the mount. The restart test could then stop the mount alone attest/suite/networking.py:82and check that lnd stopped too.systemctl is-active lnd torattest/lndconnect-onion-switch.nix:99succeeds when either unit is active. Two separate checks would catch a stopped lnd.- The VM boots with the onion service, so
/run/lnd-restis still there from boot when the last subtest switches it back on.rmdir /run/lnd-restbeforeswitch_to_system("machine")would test that the switch creates the dir before the mount's assertion runs. journalctl -u tor -u lnd -u <mount>attest/suite/networking.py:52misses most cycle messages. systemd logs a cycle under the unit where it found it, oftenlocal-fs.targetorsysinit.target, and lines from before journald started have no unit field.journalctl -b -t systemdcatches both.- The order through onion-addresses exists only when lnd's onion service is public (
modules/onion-services.nix:89-94). The switch test doesn't setpublic, so theonion-addressesstop attest/lndconnect-onion-switch.nix:84and the comments there and atmodules/lndconnect.nix:314describe an order that isn't there. The main suite sets it attest/tests.nix:307. - Line 71 of
test/suite/networking.pystops lnd beforewait_for_lnd_server(). Whenconfig-replacehas just restarted lnd, that stop can land between RPC start and server start, which is the panic thatwait_for_lnd_server's docstring warns about. Starting lnd and waiting before the restart avoids it.
486415b to
9dd4f4c
Compare
|
@ostermayer Thanks, all six points are addressed in 9dd4f4c (squashed):
Could you rerun your gate on the new head? If anything else needs changing, could you push it as Assisted-by: Claude Code (Claude Opus 5.5, claude-opus-5-5) |
9dd4f4c to
67325a5
Compare
ostermayer
left a comment
There was a problem hiding this comment.
@sebsgent I reran our gate on 67325a5 with DeepSeek V4.1 Flash 1017 (max), Gemini 4 Carbon (high), Gemini 4 Neon (high), Claude Opus 5.5 (high) and GPT-6 Astra (max), and checked each finding against the code. All six points are fixed. partOf stops lnd before the mount also when only the mount stops or restarts, and tor follows the mount through Requires. Two optional test points are left.
- The mount-restart subtest at
test/lndconnect-onion-switch.nix:80checks only that lnd restarted. Comparing tor'sInvocationIDbefore and after would test the "and tor" part. - The main suite makes lnd's onion service public at
test/tests.nix:307, solndconnect-onion-switchis the only test where lnd's ownafteris its only order to the mount. Its first subtest restarts lnd at line 76 before it checks anything, so it doesn't test the boot order. A timestamp check like the one attest/suite/networking.py:83, before the restart, would.
67325a5 to
fa9351e
Compare
|
@ostermayer Thanks, both are in, amended into the single commit and rebased onto master.
Assisted-by: Claude Code (Claude Opus 5.5, claude-opus-5-5) |
Tor must only reach lnd's REST socket in /run/lnd-rest. lnd owns this dir and can create symlinks in it, and tor's connect() would follow them inside tor's root dir. Mount the dir on itself with `nosymfollow`. lnd and tor still share the same dir and socket. Tor's bind mount of the dir copies the flag, so tor requires the mount and starts after it. If the mount fails, tor doesn't start. The mount has no default dependencies, so that it can start after tmpfiles creates the dir at boot. If the dir is missing, systemd would create it as root:root 0755, and tor would start while lnd can't create its socket. Assert the dir instead, so that the mount and tor fail to start. When lnd starts after the mount, its mount namespace gets a copy of it, which lnd's socket keeps busy, so the mount can't stop while lnd runs. Make lnd part of the mount and order it after the mount, so that lnd stops or restarts with the mount and stops first. This also holds when only the mount stops or restarts, e.g. on a switch that changes the mount unit, or when a switch that turns off the onion service doesn't stop lnd itself. lnd doesn't need the mount, so it doesn't require it. Test that the mount has `nosymfollow` in the host's and tor's view, that tor can't connect through a symlink in the dir while lnd's socket still works, that tor starts after the mount, that stopping only the mount stops lnd and tor, that the mount and tor don't start without the dir, and that tor remounts the dir when it starts. A new VM test in CI, `lndconnect-onion-switch`, restarts only the mount, switches the onion service off while lnd runs and is slow to stop, and on again after removing the dir. Assisted-by: Claude Code (Claude Opus 5.5, claude-opus-5-5)
fa9351e to
892ee61
Compare
Follow-up to #343, suggested by @ostermayer.
Tor must only reach lnd's REST socket in
/run/lnd-rest. lnd owns this dir and can create symlinks in it, so this mounts the dir on itself withnosymfollow. Tor's read-only bind mount of the dir copies the flag, so tor'sconnect()fails on a symlink there. lnd and tor still share the same dir and socket.run-lnd\x2drest.mount(bind,nosymfollow). It has no default dependencies, so it can start aftersystemd-tmpfiles-setup.service, which creates the dir at boot.RequiresMountsFor=/run/lnd-rest, so it starts after the mount. If the mount fails, tor doesn't start.root:root 0755, and tor would start while lnd can't create its socket.PartOfand ordered after the mount, so it stops or restarts with the mount and stops first. When lnd starts after the mount, its socket keeps lnd's copy of the mount busy, so the mount can't stop while lnd runs. This also covers a stop or restart of the mount alone, e.g. a switch that changes the mount unit, and a switch that turns off the onion service while lnd hasrestartIfChangedorstopIfChangedoff. lnd doesn't require the mount.Tests (
lndconnect-onion-lnd,lndconnect-onion-lnd-restart):nosymfollowin the host's view and in tor's mount namespace (there alsoro).PartOfand ordered after it, and systemd logged no ordering cycle in this boot.New VM test
lndconnect-onion-switch, added to the CI matrix: lnd starts after the mount (checked at boot), then a restart of only the mount restarts lnd and tor (checked by tor's invocation ID). A switch turns the onion service off while lnd is slow to stop, and, after removing/run/lnd-rest, on again. Neither leaves failed units. WithoutPartOf, the restart of the mount fails withtarget is busy.Assisted-by: Claude Code (Claude Opus 5.5, claude-opus-5-5)