Repository navigation
rtl: give RTL its own lnd macaroon and clightning rune - #291
Conversation
|
The |
|
e06e403 to
882f2e7
Compare
viberaven
left a comment
There was a problem hiding this comment.
Requesting changes on rune rotation and the scope of RTL’s lnd macaroon. I verified the rotation failure in a Core Lightning regtest VM and tested the narrower macaroon in a separate lnd regtest VM. The local module-config and test-runner flake checks passed.
`netnsRegtest` failed once on #291 because lnd panicked. `lnd-wallet-init` stopped lnd right after a new wallet came up, and lnd crashed on that early stop with `unable to subscribe to chans: subscription server shutting down`. `lnd-restart-on-clean-exit` then found the failed exit in lnd's journal. lnd answers RPCs and notifies systemd before its server has started all subsystems, so neither `lncli getinfo` nor `systemctl start` closes that window. This PR: - adds `wait_for_lnd_server` to `test/suite/helpers.py`. When the regtest fixture has mined blocks (`num_blocks`), it waits until `lncli state` reports `SERVER_ACTIVE`. lnd starts its server only once its chain has synced. Without these blocks, as on the test mainnet, lnd never starts its server and can't panic this way, so the helper keeps the `getinfo` wait there. The fixture's data doesn't change when a run selects a subset of the tests. - uses it in the tests that run before `lnd-restart-on-clean-exit` and stop, restart or terminate lnd. These are `config-replace`, `lnd-wallet-init` and `rtl-stops-with-backend`. - also waits before `restart-bitcoind` and `config-replace` stop bitcoind, because lnd requires bitcoind and stops with it. Both start lnd before that wait, because lnd can be down there. `restart-bitcoind` reads whether lnd is enabled from a new `test.data.restart-bitcoind.lnd`, so this also works when a run leaves out test `lnd`. - tells test authors about the helper in `test/README.md`. ## Testing - `netnsRegtest` and `default` pass on a KVM host. In the `netnsRegtest` log, the `SERVER_ACTIVE` wait comes right before each stop of bitcoind in `restart-bitcoind` and `config-replace`. - These focused runs on `regtestBase` with lnd also pass. - `lnd-wallet-init` alone. All three of its waits use `lncli state`. - `config-replace` alone, with lnd down when the test starts. - `restart-bitcoind` and `lnd-restart-on-clean-exit`, without test `lnd`. Both stops of bitcoind wait for `SERVER_ACTIVE`. Right after boot, the first wait took about 2.5 s, so the stop used to land in that window. - The panic is a race, so I can't trigger it on demand. `lnd-macaroon-revocation` runs after `lnd-restart-on-clean-exit` and has its own failure check, so I left its stops of lnd for a separate change. `lnd-create-macaroons` also restarts lnd right after a start once it deletes stale root keys. Only a module change can close that window, and that wait needs a timeout, because a node that's still syncing never starts its server. `backups` stops bitcoind too, but it runs only on the test mainnet. Written with Claude Opus 5.5, reviewed with Claude Fable 5.2.
882f2e7 to
8528361
Compare
|
Thanks for the review. All in 8528361.
|
viberaven
left a comment
There was a problem hiding this comment.
The five earlier findings are addressed on the packaged backends. The local module-config, test-runner, and release-note checks passed. In a two-backend regtest VM with createAdminRune = false, rtl-credentials and rtl-permissions also passed, including the blacklisted-ID rotation cases and the denial of DeleteAllPayments.
I’m requesting changes because enabling RTL now prevents a previously working custom lnd build from starting. The inline comments include the base-versus-head result, a separate cold-start test race, and a correction to the decommissioning instructions.
|
Nothing to add beyond viberaven's open threads. The change only narrows RTL's access, and the new rune/macaroon steps fail closed and keep the rune out of command lines. Tested: compared the 40 lnd RPCs and 32 clightning methods with RTL 0.15.17's Assisted-by: Claude Code (Claude Opus 5.5) |
8528361 to
8f82639
Compare
|
Thanks for the review. All in 8f82639.
|
viberaven
left a comment
There was a problem hiding this comment.
I verified the three findings from the last review. The custom lnd build now starts with RTL, clnrest-admin-rune passes on a fresh two-backend VM, and the decommissioning instructions cover the case where disabling RTL removes Core Lightning. With the pinned packages and createAdminRune = false, both rtl-credentials and rtl-permissions passed.
I’m requesting two changes to the new permission filtering. It relaxes validation for unrelated custom macaroons, and the built-in permission test fails on the reduced lnd build even though the issued credential is correct.
8f82639 to
07069f9
Compare
|
Thanks for the review. All in 07069f9.
|
viberaven
left a comment
There was a problem hiding this comment.
Both findings from my previous review are resolved in 07069f9a. I verified that a misspelled required RPC makes lnd startup fail and leaves the client without a macaroon. The generated startup script skips listpermissions when no optional grants are configured.
rtl-permissions passed with exactly 40 RPC grants on the pinned lnd and exactly 35 in lndWithoutWalletrpc. The reduced build logged each of the five omitted WalletKit RPCs, and RTL’s dashboard requests succeeded. The Core Lightning credential and cold-start rune checks also passed.
seberm
left a comment
There was a problem hiding this comment.
No must/should items. The allowlists match RTL 0.15.17's backend source exactly: the 32 clightning methods, and the lnd REST paths and verbs (websocket and backup job included), which map to the 40 RPCs. optionalPermissions is opt-in: macaroons without it keep their root key IDs and make no listpermissions call, and permissions is still validated exactly. The new rune and macaroon steps fail closed and keep the rune out of command lines.
Tested: module-config passes on 07069f9 merged with current master; CI is green on 07069f9.
Assisted-by: Claude Code (Claude Opus 5.5)
RTL got lnd's admin macaroon and clnrest's admin rune, which has no restrictions. So whoever controls the RTL process had full control of both backends, and could bake new lnd macaroons and create new runes. lnd: RTL gets `services.lnd.macaroons.rtl`, with a `uri` permission for each lnd RPC that the REST routes in RTL's `backend/controllers/lnd` call. Entity permissions would allow more, like `offchain:write` for `DeleteAllPayments`. `rtl-copy-macaroon` copies `/run/lnd/rtl.macaroon` to the file name that RTL reads. It reads as the rtl user and doesn't follow a symlink, as the lnd user can write `/run/lnd`. lnd registers the RPCs of `invoicesrpc` and `walletrpc` only when its package has their build tags, and it refuses to bake a permission for an RPC that it doesn't register. So RTL's permissions for these RPCs go to the new option `services.lnd.macaroons.<name>.optionalPermissions`. Only when a macaroon has optional permissions, lnd-create-macaroons asks lnd for its RPCs. It leaves out each optional permission whose RPC lnd lacks, and logs a warning. A required permission that lnd refuses still fails lnd's start. The root key ID covers both lists. Without optional permissions, a macaroon keeps its ID, and lnd-create-macaroons doesn't change. clightning: RTL gets a rune with one restriction that allows only the methods in RTL's `backend/controllers/cln` and the method that clnrest checks for RTL's websocket, and a comment restriction that marks it as RTL's. RTL's start creates the rune once at `rtl-rune` in clightning's network dir, which RTL can't write, and keeps it while clightning has it stored with these restrictions and not blacklisted. It blacklists all other stored runes with the marker, so only one RTL rune stays valid. Runes without the marker, like the admin rune, are never blacklisted. Then, if it didn't keep the rune, it creates a new one. clightning gives a new rune the next unique ID, also when this ID is blacklisted. So the start checks each new rune, and creates up to 10 until one isn't blacklisted, or fails. RTL's copies keep their paths, so its next start overwrites the admin credentials that it had. When RTL uses only one backend, its start removes the old copy for the other backend. A 0.2.0 notice tells RTL users that apps which read these copies need their own credentials. Fixes bitcoinix#261. Assisted-by: Claude Code (Claude Opus 5.5)
07069f9 to
eb790ad
Compare
Fixes #261.
RTL used lnd's admin macaroon and clnrest's admin rune. Whoever controls the RTL process, for example through a bug in RTL or Node before login, had full control of both backends. The admin macaroon can bake new macaroons and the admin rune can create new runes, so that access could outlast a fix in RTL. RTL still has to send funds and open and close channels, so a takeover can still move funds. This PR takes away the rest.
This PR:
services.lnd.macaroons.rtlwith auripermission for each lnd RPC that RTL calls. These are the 40 RPCs of the lnd REST routes in RTL'sbackend/controllers/lnd. Entity permissions would allow more, likeoffchain:writeforDeleteAllPayments. So an RTL update that calls another RPC has to add it to the list.rtl-copy-macaroonreads/run/lnd/rtl.macaroonas the rtl user and doesn't follow a symlink, because the lnd user can write/run/lnd.services.lnd.macaroons.<name>.optionalPermissionsforuripermissions that a macaroon gets only when lnd has their RPC. lnd has the RPCs ofinvoicesrpcandwalletrpconly when its package has their build tags, and it refuses to bake a permission for an RPC that it doesn't register. So RTL's 7 permissions for these RPCs are optional, and the other 33 stay required. Only for optional permissions doeslnd-create-macaroonsask lnd for its RPCs, withlncli listpermissions. It leaves out each optional permission whose RPC lnd lacks, and logs a warning.permissionsstays exact, so lnd's start still fails for a misspelled URI. The root key ID covers both lists. Without optional permissions, a macaroon keeps its ID, andlnd-create-macaroonsis the same as on master.listclnrest-notifications, which clnrest checks for RTL's websocket. A second restriction is the commentbitcoinix-rtl#, which marks RTL's runes. RTL's start creates the rune once and keeps it atrtl-runein clightning's network dir, where RTL can't write. It keeps the rune while clightning has it stored with these restrictions and not blacklisted. It blacklists every other rune with the marker, so after a method change, a failed start or a lostrtl-rune, only one RTL rune stays valid. A rune without the marker, like the admin rune, is never blacklisted. Then, if it didn't keep the rune, it makes a new one. clightning gives a new rune the next unique ID, also when that ID is blacklisted. So the start checks each new rune the same way, and creates up to 10 until one passes, or fails.docs/services.md. The section says how to revoke RTL's rune. clnrest checks the rune of a websocket client only when it connects, so you blacklist the rune and then restart clightning, which also starts RTL again. When only RTL enables clightning, you revoke the rune before the deploy that disables RTL.The only new option is
optionalPermissions. An app that reads RTL's copies of the admin credentials needs its own credentials now, and the notice says so.The rune handling follows #288, with two differences. RTL had the admin rune in its data dir until now, so a file that RTL can write must not decide which rune gets revoked. That's why the rune lives in clightning's network dir. The script also finds RTL's rune in the output of
showruneswith jq, so the rune never shows up in a command line, and runes that clightning doesn't store, like ones derived withcreaterune rune=..., are never blacklisted.Testing
rtl-permissions. RTL's macaroon has exactly the 40uripermissions (lncli printmacaroon), or those of them that the scenario's lnd has, can callgetinfoand can't bake a macaroon. lnd's journal warns about exactly the left-out ones. lnd'scheckpermissionsconfirms each of the other RPCs, and answers "permission denied" forBakeMacaroon,StopDaemon,DeleteAllPaymentsandSignOutputRaw. clnrest accepts RTL's rune forgetinfoand refusescreaterunewith 401.checkruneaccepts each of the 32 methods, from a separate list in the test, and refusescreaterune,blacklistrune,showrunesandstop. The test also logs in to RTL's API and checks that the dashboard requests of each backend return 200.rtl-credentialscovers the new sources. A symlink at/run/lnd/rtl.macaroonisn't followed. After each start exactly one valid rune has the marker. A start makes a new rune for a symlink, an empty file,null, garbage, the admin rune, a rune derived from it, another app's rune, an earlier RTL rune and a rune revoked by hand. It blacklists earlier RTL runes, also one that a lost file left behind, and never the others. When RTL's rune and the next two unique IDs are blacklisted, a restart of RTL gets the ID after them, and clnrest accepts it. When RTL's rune and the next 10 free IDs are blacklisted, the start fails, keeps both files and still revokes an earlier RTL rune, and the next start gets the ID after them. WithcreateAdminRune = false, the test uses a rune without restrictions in place of the admin rune.module-configgetstestRtlUnusedCredentialsandtestVersioningRtlCredentials,clnrest-admin-runenow checks that RTL keeps its own rune when clightning restarts with a new admin rune, andlnd-macaroon-revocationalso checks macaroons that allowGetInfothrough auripermission, like RTL's.lndWithoutWalletrpc, not in the CI matrix. It builds the pinned lnd withoutwalletrpcand runs RTL on lnd. It passes, with the 35 other permissions in RTL's macaroon and a warning for each WalletKit RPC. On the previous head,rtl-permissionsfails there, as it expects all 40.clnrest-admin-runenow starts RTL before it reads RTL's rune. Run alone on a fresh regtest VM, it failed on an earlier head, because RTL hadn't copied its rune yet. It also resets RTL's start limit with clightning's, as RTL on clightning only hit the limit there.GetInfoand a misspelledListChannelsfails lnd's start withinvalid permission actionon master and on this head, and no macaroon is installed. On the previous head, lnd started with aGetInfo-only macaroon. For this macaroon and for BTCPay Server, charge-lnd and Unbeholden LNURL on lnd,lnd-create-macaroonshas the same store path and the same root key IDs as on master.module-configchecks the root key IDs with and without optional permissions and rejects optional permissions that aren'turipermissions.lnd-macaroon-filterschecks the new filter oflistpermissionsoutput against unexpected output.bakemacaroonworks,checkpermissionsis valid for the admin RPCs,checkruneaccepts the four admin methods and clnrest answers 201 forcreaterune. On an earlier head of this PR,checkpermissionsis valid forDeleteAllPayments, and after the restart with blacklisted IDs RTL started with a blacklisted rune.default,regtest,netnsRegtest,netnsandlndWithoutWalletrpcpass on a KVM host. So do regtest scenarios with clightning, lnd and RTL andcreateAdminRune = false, with RTL on lnd only and with RTL on clightning only.module-config,test-runner,lnd-macaroon-filters, shellcheck and the release notes check pass.Known limits. The admin macaroon and the admin rune stay valid, so a copy taken before the upgrade still works. When you disable RTL or its clightning node, its rune stays valid, and
docs/services.mdsays how to revoke it. After clightning starts on a new or older database, a new RTL rune can get the unique ID of an older rune, and the next rotation then revokes both. RTL's start logs a line in that case, and the docs explain it. With a custom lnd package that lacks some of RTL's RPCs, RTL's features that use them fail, and lnd's journal says which permissions RTL didn't get. When the next 10 unique IDs are blacklisted, RTL's start fails, and systemd starts it again every 10 seconds. Each failed try stores 10 more runes, so the docs say to blacklist only the IDs of runes that you have. With RTL on lnd, the first deploy restarts lnd to create RTL's macaroon.Written with Claude Opus 5.5, reviewed with Claude Fable 5.2, GPT-6 Astra, Kimi K3.1 Pro, DeepSeek V4.1 Flash, GLM 5.3 and Qwen4-Max.