Skip to content

Add native unbeholden-lnurl service for LND and Core Lightning - #288

Merged
prusnak merged 15 commits into
bitcoinix:masterfrom
unbeholdendev:unbeholden-lnurl
Nov 20, 2026
Merged

prusnak merged 15 commits into
bitcoinix:masterfrom
unbeholdendev:unbeholden-lnurl

Conversation

@unbeholdendev

Copy link
Copy Markdown
Contributor

Summary

Adds services.unbeholden-lnurl, a native package (v0.4.0) and module for Unbeholden LNURL: Lightning Addresses, withdrawal vouchers, ntfy notifications and Nostr zaps from the local node.

backend = "lnd"  macaroon with only the permissions the enabled features need
backend = "cln"  rune with only the needed methods, reused while they match,
                 blacklisted when they change

The module also generates persistent secrets and wires up backups, Tor, netns isolation (id 34) and sudo unbeholden-lnurl-vouchers. No versioning notice: the service is new and off by default.

Evidence

The unbeholden-lnurl VM test requests an address and an invoice and checks the verify URL. On CLN, it also checks that a restart reuses the rune and that changed restrictions revoke it.

On a KVM host, the head passes nix flake check --all-systems, shellcheck, mdbook build and the six unbeholden-lnurl-{lnd,cln}{,-netns,-tor} scenarios. CI runs -lnd and -cln-netns.

Merge Danger

Door: two-way

Blast Radius: small

Outside the new module, the only change that affects other scenarios is in test/suite/restarts.py: clnrest-admin-rune now resets clightning's systemd start limit, which earlier tests use up on fast scenarios.

Models

Codex GPT-6.1 Sol wrote the first version. Claude Opus 5.5 wrote the follow-up commits.

Package v0.3.0 and add typed settings, scoped node credentials, persistent secrets and state, Tor and namespace isolation, backups, documentation and integration tests.

Assisted-by: Codex (gpt-6.1-sol)
restart-bitcoind, config-replace and clnrest-admin-rune start clightning
six times within seconds on fast scenarios, which hits systemd's default
start limit.

Assisted-by: Claude Code (claude-opus-5-5)
- Keep the CLN rune in the data dir and reuse it while its restrictions stay
  the same. Blacklist it when they change, so that disabling a feature
  revokes its methods. Previously every start created another valid rune.
- Add `unbeholden-lnurl-vouchers` to print unclaimed vouchers.
- Use plain option declarations and a freeform `settings` type.
- Drop the redundant StateDirectory and Tor client setup.
- Move the release note to 0.2.0, add the package to the version manifest
  and run two LNURL scenarios in CI.

Assisted-by: Claude Code (claude-opus-5-5)
- Update the package to v0.4.0, which adds `-diagnose`.
- Default `settings.withdraw_secret_file` to null and generate no voucher
  secret when `settings.withdraw_secret` is set. The app rejects configs
  that set both.
- Link the example config on the `main` branch.
- Group the netns address assignment with the other services.

Assisted-by: Claude Code (claude-opus-5-5)
Assisted-by: Claude Code (claude-opus-5-5)
Assisted-by: Claude Code (claude-opus-5-5)
@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 area: packages pkgs/ and flake pins type: feature New capability or service labels Nov 18, 2026
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 18, 2026
Comment thread pkgs/unbeholden-lnurl/default.nix Resolved
Comment thread pkgs/unbeholden-lnurl/default.nix Resolved

@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.

Reviewed 73c2e2e. I found three actionable issues, detailed inline: a privileged symlink write in CLN credential setup, missing recovery after backend stop/start, and wildcard listener addresses being rewritten to loopback.

Validation: built checks.x86_64-linux.module-config, checks.x86_64-linux.test-runner, and unbeholden-lnurl (including its Go tests). All passed. I also ran a disposable KVM test based on unbeholden-lnurl-cln and reproduced all three findings against the unchanged PR code. This was a targeted reproduction test, not a rerun of the full six-scenario matrix.

Review assisted by Codex (gpt-6-astra).

Comment thread modules/unbeholden-lnurl.nix Resolved
Comment thread modules/unbeholden-lnurl.nix Resolved
Comment thread modules/unbeholden-lnurl.nix Resolved
- Access the data dir and clnrest's certs dir only as their owners, so a
  planted symlink can't redirect a root write. Check the saved rune with
  `showrunes` instead of a restrictions file, and revoke only a rune that
  clightning stored.
- Pass the rune to `showrunes` as `rune=`, since a rune with `=` was
  parsed as a key=value pair and the old rune was never revoked.
- Start the service from the backend's ExecStartPost, so it comes back
  after a backend stop and start.
- Keep wildcard listen addresses instead of rewriting them to loopback.
- Fetch the package by tag and drop `meta.platforms`.

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

Copy link
Copy Markdown
Contributor Author

Addressed in 3819076:

  • @prusnak: the package now fetches by tag, and I dropped platforms.
  • Symlink writes: the setup script now reads and writes the data dir only as the service user. It reads clnrest's ca.pem as the clightning user. I dropped the .restrictions file. The script now checks the saved rune with showrunes and revokes it only if clightning stored it. The CLN test plants a symlink to a root-owned 0600 file and checks that the file is unchanged. The test also found a bug in the old code: lightning-cli parsed a rune containing = as a key=value pair, so the old rune was never revoked. The script now passes it as rune=.
  • Backend restart: the backend now starts unbeholden-lnurl from its ExecStartPost, the same way RTL does. restart-bitcoind now covers unbeholden-lnurl.
  • Wildcard bind: listen now keeps the configured address and puts IPv6 in brackets (0.0.0.0:8081, [::]:8081). I checked the generated config but didn't add a test.

All six unbeholden-lnurl scenarios pass, along with flake check and shellcheck.

@github-actions github-actions Bot removed the status: rebase needed Merge conflicts need to be resolved label Nov 18, 2026
@seberm

seberm commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Hello @unbeholdendev , please recheck this review:


The earlier findings are fixed in 17191d6.

Must fix

  • LND macaroon: grant the exact RPCs, not whole entities. With vouchers, offchain:write also lets this public-facing service call AbandonChannel, UpdateChannelPolicy, HtlcInterceptor and UpdateChanStatus. v0.4.0 calls only these six, and lnd-macaroons accepts them as { entity = "uri"; action = "/lnrpc.Lightning/AddInvoice"; }:

    • receiving: /lnrpc.Lightning/AddInvoice
    • receiving or notifications/Nostr: /lnrpc.Lightning/LookupInvoice, /lnrpc.Lightning/ListInvoices, /lnrpc.Lightning/SubscribeInvoices
    • vouchers: /routerrpc.Router/SendPaymentV2, /lnrpc.Lightning/GetInfo

    Update testLnurlLndReceivePermissions to match.

Should fix

  • docs/services.md: say that vouchers let the service pay any invoice from the node's Lightning balance (LND SendPaymentV2, CLN pay), and that only the service itself enforces the voucher amounts.
  • docs/services.md: zap receipts go to relays that the payer chooses. Without tor.proxy, anyone who pays a zap learns the node's IP address, even when the address is published only as an onion.

Tested: CI green on 17191d6. Locally, unbeholden-lnurl-{cln,lnd}-tor pass. With the URI macaroon and addresses, vouchers and Nostr enabled, unbeholden-lnurl-lnd passes and updatechanpolicy is denied with that macaroon.

Assisted-by: Claude Code (Claude Opus 5.5)

@seberm

seberm commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Closes #256

@prusnak prusnak added this to the v0.2.0 milestone Nov 18, 2026

@ostermayer ostermayer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I ran our reviews on 17191d66. seberm's URI list covers the macaroon, so here's the rest. I'd fix the first one before merge.

  • The service user can still make the root setup script blacklist any rune. lightning-cli copies a value wrapped in " into the request as is (is_literal in cli/lightning-cli.c). So cln-rune can add a top-level filter to the showrunes call that hides stored, our_rune and blacklisted. The jq step then answers revoke <id> for a forged rune with any id, for example 0, which is usually clnrest's admin rune that RTL and lnconnect use. Check the file against the rune alphabet first, then call showrunes with no argument and match .rune through jq --arg. That also keeps the rune off the command line, where any local user can read it in /proc while the script runs.
  • An old rune stays valid when the file changes or goes away. The file is the only record, so when it's missing or wrong the script makes a new rune and never blacklists the old one. Nothing blacklists it when the service is disabled or moves to lnd either. If the rune id lived where the service can't write, the script could revoke it in those cases, like lnd-macaroons.nix does with root keys.
  • After a restore, vouchers claimed since the backup can be claimed again, because the claims only live in state.json and the secret comes back too. That's worth a line next to the channel database warning in docs/services.md.
  • Behind the onion service every caller comes from Tor's address, so they all share one rate limit bucket and one client can starve the rest.
  • lnd runs with GODEBUG=multipathtcp=0 since #187. This is a new public Go listener, so it should get the same.

- LND: grant only the six RPCs the service calls, as `uri` permissions,
  instead of whole entities such as `offchain:write`.
- CLN: clightning records the ID of the service's rune in its own data
  dir. The setup compares the service's rune file with that rune and
  never passes the file to lightning-cli, so a forged file can't pick a
  rune to revoke. A changed or missing file revokes the recorded rune.
  clightning also revokes it when the service is disabled or uses LND.
- Run with GODEBUG=multipathtcp=0, like lnd.
- Docs: what vouchers can pay, re-claims after a restore, the shared
  rate limit behind the onion service, and zap receipts leaking the IP
  without the Tor proxy.

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

Copy link
Copy Markdown
Contributor Author

Addressed in b7ae669:

  • @seberm: the LND macaroon now grants only the six RPCs, as uri permissions. The docs now explain what vouchers can pay and that zap receipts reveal the node's IP without tor.proxy.
  • @ostermayer: clightning now records the rune ID in its own data dir, so the service can't change it. The setup no longer passes the rune file to lightning-cli. When the rune file changes or goes missing, the setup revokes the recorded rune. clightning also revokes it when the service is disabled or switched to LND. GODEBUG=multipathtcp=0 is set. The docs now cover voucher re-claims after a restore and the shared rate limit behind the onion service.

Comment thread modules/unbeholden-lnurl.nix Resolved
Match the service name used elsewhere in bitcoinix, so the backend
value is also its systemd unit and netns service name.

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

Copy link
Copy Markdown
Collaborator

Checked b7ae669 and 892fcc1. All five points are fixed. The rune ID now lives in clightning's data dir and has to be numeric, the rune file only reaches jq through the environment, a changed or missing file revokes the recorded rune, clightning revokes it when the service goes away, and GODEBUG and the docs are in.

One edge case is left, and it's not blocking. After clightning starts on a new or restored database, the recorded ID can belong to another rune, and the next start revokes that one. #291 has the same case for RTL and documents it in docs/services.md.

On a new or restored clightning database, the recorded ID can belong to
another rune, and the next start revoked that rune. Record the rune
itself and revoke only the ID that clightning lists for it.

Assisted-by: Claude Code (Claude Opus 5.5)
@seberm seberm linked an issue Nov 19, 2026 that may be closed by this pull request
@github-actions github-actions Bot added the status: rebase needed Merge conflicts need to be resolved label Nov 19, 2026
Move the release note into docs/release-notes/0.2.0/.

Assisted-by: Claude Code (Claude Opus 5.5)
@github-actions github-actions Bot removed the status: rebase needed Merge conflicts need to be resolved label Nov 19, 2026
@seberm

seberm commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

LGTM. All earlier findings are fixed on f00ac69; no remaining must/should items.

Tested: CI green on f00ac69. Locally on f00ac69 merged with master: unbeholden-lnurl-{cln,lnd-netns,cln-tor,lnd-tor} pass.

Assisted-by: Claude Code (Claude Opus 5.5)

@seberm
seberm requested a review from viberaven November 19, 2026 20:13

@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.

My three original findings are fixed on 80ea000. CLN setup writes service-owned files as the service user and the symlink regression checks the target. Backend startup brings LNURL back, and the bitcoind stop/start test includes LNURL. The listener now preserves wildcard addresses and brackets IPv6.

One credential exposure from the follow-up discussion remains. Both setupCln and revokeRecordedRune pass the full recorded CLN rune to jq via --arg recorded. During a normal restart that rune remains valid. On a host with the usual process visibility, another local user can read it from jq's command line while jq waits for showrunes. With vouchers enabled the rune authorizes payments. Please pass the recorded value through a protected file descriptor or a process-scoped environment variable in both places and update the jq filters accordingly.

I reviewed the current diff and checked GitHub CI. The LND and CLN-netns scenarios passed. I did not rerun the VMs locally.

Assisted-by: Codex (gpt-6.2-astra)

@prusnak prusnak added the status: changes needed Cannot proceed until suggested changes are implemented label Nov 20, 2026
Any local user can read a process's arguments while it runs. Pass the
recorded rune to jq through the environment, which only its user and
root can read.

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

Copy link
Copy Markdown
Contributor Author

Addressed in e01d185:

@viberaven: setupCln and revokeRecordedRune now pass the recorded rune to jq as an environment variable for that one command, and the filters read $ENV.recorded. The rune no longer appears in any command line.

unbeholden-lnurl-{cln,cln-netns,cln-tor}, flake check and shellcheck pass.

@viberaven

Copy link
Copy Markdown
Contributor

Re-reviewed e01d185. This resolves my last change request. Both setupCln and revokeRecordedRune pass the recorded CLN rune through jq’s environment and read it with $ENV.recorded. I verified with a dummy rune that its value stays out of both command lines.

I also checked that setup keeps a matching rune, rotates it when its permissions change, and that cleanup selects only the matching active rune. The unbeholden-lnurl-cln VM passed locally, including the restart tests. The CLN network-namespace scenario passed in CI.

No remaining findings from my review.

Assisted-by: Codex (gpt-6.2-astra)

@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

@prusnak

prusnak commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Please resolve merge conflicts - GitHub UI shows there are none, but there are some ...

@prusnak
prusnak merged commit 8a678bb into bitcoinix:master Nov 20, 2026
31 of 44 checks passed
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 area: packages pkgs/ and flake pins status: changes needed Cannot proceed until suggested changes are implemented type: feature New capability or service

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add unbeholden-lnurl (self-hosted Lightning Address for LND)

5 participants