Skip to content

Add ThunderHub as an LND dashboard - #326

Closed
viberaven wants to merge 6 commits into
bitcoinix:masterfrom
viberaven:feat/thunderhub
Closed

viberaven wants to merge 6 commits into
bitcoinix:masterfrom
viberaven:feat/thunderhub

Conversation

@viberaven

@viberaven viberaven commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #136

Enable services.thunderhub.enable = true; to manage the local LND node through ThunderHub. bitcoinix packages version 0.19.1 from its nixpkgs pin with local dashboard fonts. The package omits the Boltz swap interface, including recovery of saved swaps. The dashboard listens on 127.0.0.1:3001 by default and supports SSH forwarding, Tor onion services, and network namespace isolation.

ThunderHub verifies LND's TLS certificate and uses a dedicated macaroon scoped to individual RPCs. A dashboard login can send funds and manage channels. LND denies macaroon administration, payment-history deletion, and low-level signer RPCs. The YAML account preserves two-factor enrollment across restarts. nodeinfo reports the dashboard address and the backups service includes its settings.

The VM tests exercise login, balance queries, invoice creation on regtest, denied macaroon administration, rejection of an untrusted LND certificate, and two-factor login after restart. The operator guide and example configuration include setup and access instructions.

Local verification

  • Before the package patches, the default, netns, and netnsRegtest NixOS VM scenarios passed on x86_64 Linux, along with a dashboard VM using a custom port, user, group and data directory.
  • Passed nix flake check --all-systems, all x86_64 flake check builds, shellcheck, the docs build and release-note validation.
  • Built the patched ThunderHub package on x86_64 Linux and passed all 167 upstream tests. The focused ThunderHub VM fetched both bundled fonts, checked the browser policy and confirmed the swap claim mutation is absent. Evaluated the patched aarch64 Linux derivation.

Use the ThunderHub package in pinned nixpkgs, a dedicated URI-scoped macaroon and LND's TLS certificate. Keep two-factor enrollment and preferences across restarts, and integrate the dashboard with Tor, netns isolation, backups and nodeinfo.

Assisted-by: OpenAI Codex (GPT-6.2 Astra)
@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 size: L 100–499 changed lines (additions + deletions) labels Nov 24, 2026
@prusnak prusnak added this to the v0.2.1 milestone Nov 24, 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 the gate on this with GPT-6 Astra, Kimi K3.1 Pro twice, DeepSeek V4.1 Flash and Gemini 4 Carbon. The macaroon, the credential handling and the socket proxy hold up, and RTL's proxy comes out of the refactor unchanged. ThunderHub also keeps the {YML_ENV_n} placeholders when it saves a second factor, because it reads the raw YAML file again before it writes it. Two small bugs and one doc point are inline.

Comment thread modules/thunderhub.nix Outdated
macaroon: "{YML_ENV_2}"
certificatePath: "{YML_ENV_3}"
'';
rpcHost = nbLib.address (removePrefix "[" (removeSuffix "]" lnd.rpcAddress));

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.

With services.lnd.rpcAddress = "::", this connects to [::1], but lnd's certificate doesn't cover ::1. lnd.nix adds rpcAddress as it's given, so the certificate has localhost, 127.0.0.1 and ::. ThunderHub checks the certificate, so the login fails with UnableToConnectToThisNode. rpcServer in lnd-macaroons.nix keeps the address unmapped for this reason, and the same code here fixes it. 0.0.0.0 works because 127.0.0.1 is always in the certificate.

Comment thread modules/thunderhub.nix Outdated
];
systemd.services.thunderhub-proxy = mkIf useProxy {
serviceConfig = {
InaccessiblePaths = [ "/run/lnd" ];

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.

/run/lnd only exists while lnd runs. lnd keeps it across restarts but removes it on stop (RuntimeDirectoryPreserve = "restart"). Without a - prefix, the proxy fails to start with 226/NAMESPACE when someone connects while lnd is stopped, for example during boot before lnd is up. Then it backs off up to a minute, so the dashboard can stay unreachable for that long after lnd and ThunderHub are back. The proxy runs as a dynamic user, and /run/lnd is mode 711 with each macaroon readable only by its owner. So -/run/lnd or dropping the line both work.

Comment thread docs/services.md Outdated

ThunderHub verifies LND's TLS certificate and uses its own revocable macaroon.
**A dashboard login can spend funds**, including sending on-chain payments and
opening or closing channels. LND denies macaroon administration and signer RPCs,

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.

The macaroon still allows lnrpc.Lightning/SignMessage, so a login can sign messages with the node key. LNURL-auth uses DeriveSharedKey from the signer service, which is denied, so the sentence is right. But "signer RPCs" reads as if the dashboard can't sign anything. Saying that it can still sign messages with the node key would make that clear.

Use the address in LND's certificate for the dashboard connection. Share
the formatted RPC endpoint with LND, lncli and macaroon creation so bare
and bracketed IPv6 addresses work from the listener through login.

Allow socket activation while LND's runtime directory is absent. Test
activation during a backend stop and cover the RPC address formats.

Clarify that the dashboard can sign messages with the node key.

Assisted-by: OpenAI Codex (GPT-6.2 Astra)
@viberaven

Copy link
Copy Markdown
Contributor Author

@ostermayer, I addressed all three review comments in 3cd77cd5.

  • LND, lncli, macaroon creation, and ThunderHub now share the same RPC endpoint. With rpcAddress = "::", LND listens on [::]:10009 and ThunderHub verifies the :: address in LND’s TLS certificate. This also fixes LND’s own startup failure on the malformed :::10009 listener.
  • The socket proxy now uses InaccessiblePaths=-/run/lnd. It still hides the directory when it exists at proxy startup, and an incoming connection can start the proxy while LND is stopped.
  • The guide now says explicitly that a dashboard login can sign messages with the node key through lnrpc.Lightning/SignMessage. The macaroon excludes signrpc.Signer/DeriveSharedKey, which LNURL-auth requires.

I verified dashboard login in x86_64 NixOS VMs with ::, [::1], and 0.0.0.0. The restart test now connects to the dashboard port while /run/lnd is absent and checks that systemd starts the proxy successfully.

@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 the gate again on 3cd77cd with K3.1 twice, DeepSeek, Gemini and Astra twice. The three fixes hold. With the default address, lnd.conf and the lncli wrapper don't change, so the upgrade doesn't restart lnd. The macaroons in /run/lnd are 0400 for their own users, so the proxy can't read them when it starts without the mask. Two reviewers thought ThunderHub's IP filter would block connections to 0.0.0.0 and ::. I checked that in a VM, and it doesn't. The kernel sends both to loopback before the filter sees the packets.

Comment thread modules/lnd.nix Resolved
Use lnd.rpcEndpoint for charge-lnd's --grpc argument and the LNURL
server's lnd.host setting. It brackets IPv6 addresses and preserves the
wildcard address covered by LND's TLS certificate.

Exercise both clients against the IPv6 wildcard in the existing LNURL
regtest scenario.

Assisted-by: OpenAI 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-fix items. One should-fix.

Should: The dashboard makes the operator's browser contact Google. The pinned 0.19.1 index.html loads https://fonts.googleapis.com/css2?family=Noto+Sans…. The CSP the server sends allows https: in style-src and font-src, so the browser fetches the stylesheet and font files on every page load. With the SSH tunnel from the guide, Google sees the operator's clearnet IP each time they open the dashboard. tor.enforce only restricts the service, not the browser, and the docs ("By default the service can only reach local addresses") suggest nothing leaves the machine.

Optional: the CSP also allows connect-src wss://api.boltz.exchange. The browser contacts Boltz directly while swaps are tracked, which may be worth a line in the docs.

Tested: ran the pinned 0.19.1 and checked the served page and CSP header. Matched the macaroon permissions against the lightning library's method map for every call ThunderHub makes. Only the intentionally denied BakeMacaroon, ListMacaroonIDs, DeletePayment (probe cleanup, errors ignored) and DeriveSharedKey are missing. The rtl, rtl-proxy, socket, lnd, charge-lnd and unbeholden-lnurl units are identical to the base commit with default settings.

Assisted-by: Claude Code (Claude Opus 5.5)

Drop the Google Fonts stylesheet and preconnects. ThunderHub already bundles Noto Sans and JetBrains Mono through Fontsource. Restrict font and stylesheet sources and exercise both local WOFF2 assets in the VM.

Assisted-by: OpenAI Codex (GPT-6.2 Astra)
Drop the swap page, browser WebSocket provider and GraphQL module, including recovery for saved swaps. Restrict browser connections to the dashboard origin and test that the claim mutation is absent.

Assisted-by: OpenAI Codex (GPT-6.2 Astra)
@github-actions github-actions Bot added size: XL 500–999 changed lines (additions + deletions) and removed size: L 100–499 changed lines (additions + deletions) labels Nov 24, 2026
@viberaven

Copy link
Copy Markdown
Contributor Author

@sebsgent, I addressed both browser connections in separate commits.

  • Removed the Google Fonts stylesheet and both preconnects. ThunderHub now serves its bundled Noto Sans and JetBrains Mono fonts from the node. The content security policy permits local stylesheets and local or embedded fonts. 5766fddd
  • Removed the Boltz swap page, sidebar widget, WebSocket tracker and GraphQL operations, including recovery for saved swaps. The browser’s connect-src now allows only 'self'. 2fb738e7

The x86_64-linux ThunderHub VM fetched both fonts, checked the served policy and confirmed that the claim mutation is absent. All 167 upstream tests passed, and I verified that the installed package contains no boltz.exchange URL.

@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 the gate on 5766fdd and 2fb738e with GPT-6 Astra, Kimi K3.1 Pro twice, DeepSeek V4.1 Flash and Gemini 4 Carbon, and on the earlier commits before. Both patches apply to 0.19.1, nothing on the server still refers to the removed Boltz code, and the browser now loads fonts and connects only to the node. Links like the mempool.space and Amboss ones still open in the browser when you click them, which is fine for a dashboard. With a9a41f6 all my earlier points are fixed too.

@sebsgent

Copy link
Copy Markdown
Contributor

Re-checked the permissions on 2fb738e. No must or should items.

  • Macaroon: Every granted RPC is used by ThunderHub. I checked this with the lightning library's urisForMethod on every function ThunderHub imports. Macaroon administration, DeletePayment, the signer and walletrpc key derivation stay denied, and ThunderHub's fallbacks work without them. The macaroon is 0400, owned by thunderhub and read with nofollow.
  • Secrets and state: The password reaches ThunderHub only through LoadCredential. The data directory is 0700 and accounts.yaml is 0600. The JWT secret is random on every start, and SSO and the database are off.
  • Proxy: It runs as a separate dynamic user that shares only the thunderhub group, so it can reach the socket (0770 in a 0710 directory) but not ThunderHub's environment, the macaroons, the secrets or the data directory. RTL's proxy is unchanged.

Optional: add a test that another local user can't connect to /run/thunderhub/thunderhub.sock.

Assisted-by: Claude Code (Claude Opus 5.5)

@seberm seberm 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 25, 2026

Copy link
Copy Markdown
Contributor

Let's close this PR for now.

It seems it needs couple of security updates:

and compatibility with recent LND versions:

Will reopen once upstream has cut a new release with the fixes.

@prusnak prusnak closed this Nov 25, 2026
@prusnak prusnak modified the milestones: v0.2.1, v1.0.0 Nov 25, 2026
@seberm seberm mentioned this pull request Nov 25, 2026
@prusnak

prusnak commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Moves RTL and LND changes into #334

prusnak added a commit that referenced this pull request Nov 25, 2026
#334)

This PR extracts two independent changes from #326. Each can be reviewed
as a separate commit.

1. **RTL socket proxy**. Move RTL’s systemd socket and proxy service
into a reusable NixOS module. Systemd still reserves the HTTP port while
RTL is stopped and forwards connections to RTL’s Unix socket. The
`rtlIPv6` VM permissions check now uses the configured listener, and
only scenarios that enable RTL read its address. The shared module
validates the port and preserves the secrets and resolver masks when a
dashboard has no data directory. [Commit
`46cb2f56`](46cb2f5)
2. **LND gRPC endpoint**. Use one endpoint for the LND listener,
`lncli`, macaroon creation, charge-lnd and Unbeholden LNURL. Bare and
bracketed IPv6 inputs produce the same endpoint syntax. Certificates use
the bare IP, and clients keep the configured address when verifying TLS,
including wildcard addresses. Empty hosts, whitespace and malformed
brackets fail evaluation. [Commit
`b0367d66`](b0367d6)

The LND module test covers loopback and wildcard addresses on a custom
port. The `unbeholden-lnurl-lnd` regtest VM runs both gRPC clients
against `[::]`.

### Local verification

The `rtlIPv6` VM passed on x86_64 Linux. The RTL commit and the PR head
produce the same test derivation. The `unbeholden-lnurl-lnd` VM passed
on the PR head. `nix flake check --all-systems`, the CI test-driver
evaluation (`nix eval --raw .#ciTestInfo`), shellcheck, release-note
validation, and the empty LND RPC host diagnostic also passed.

Applying the complete pre-rebase diff (`2fbd6ef5..71196a9`) directly to
`master` at `a760f5d3` produced the same Git tree (`0b34b85e`) as the
two commits above.
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 size: XL 500–999 changed lines (additions + deletions) type: feature New capability or service

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add Thunderhub

5 participants