Skip to content

btcpayserver: document that the clightning backend controls the node's funds - #274

Merged
prusnak merged 3 commits into
bitcoinix:masterfrom
ostermayer:docs-btcpay-clightning-backend-access
Nov 18, 2026
Merged

prusnak merged 3 commits into
bitcoinix:masterfrom
ostermayer:docs-btcpay-clightning-backend-access

Conversation

@ostermayer

@ostermayer ostermayer commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #87.

With services.btcpayserver.lightningBackend = "clightning", BTCPay Server joins the
clightning group and talks to lightningd over its RPC socket lightning-rpc. The socket
allows every method. So BTCPay Server can pay invoices (pay, xpay), withdraw on-chain
funds (withdraw), open and close channels (fundchannel, close) and start plugins
(plugin), which run as the clightning user. A bug in BTCPay Server, a malicious BTCPay
plugin or a stolen admin session can drain the node.

With lnd, BTCPay Server gets its own macaroon (services.lnd.macaroons.btcpayserver).
It can read the node's state and create invoices and addresses, but it can't send funds
or open or close channels.

Neither the option nor the docs said this. This PR changes no behavior. It adds these docs.

  • The access of each backend in the lightningBackend option description, with a
    recommendation to use lnd when BTCPay Server should be limited.
  • A BTCPay Server section in docs/services.md with the same facts and the reason. It
    also says that with clnrest enabled, the clightning group can read clnrest's admin rune.
  • A note at the clightning backend in examples/configuration.nix.
  • A 0.2.0 release note that points to the new section, so existing users see it.

The second commit adds two notes that the red-team review found. The backend limits only
the Lightning node, so BTCPay Server can spend a hot wallet with either backend. And
bitcoinix turns on Core Lightning for BTCPay Server only while it's the backend. So before
a node with Core Lightning channels switches to lnd, it needs
services.clightning.enable = true and another lnd port, or its channels closed.

bitcoinix can't give BTCPay Server a restricted rune today. BTCPay Server 2.4.7 uses
BTCPayServer.Lightning 1.7.14. Its Core Lightning client accepts only
type=clightning;server=unix://... or tcp://... and sends raw JSON-RPC. It has no
clnrest or rune support.

It needs no versioning notice, since nothing changes at runtime.

Not in this PR

The fix for the access itself stays open in #87. I believe there are two ways to fix it.

  • A method allowlist in front of lightning-rpc for BTCPay Server. Receiving payments
    needs invoice, listinvoices, waitanyinvoice, getinfo and delinvoice. The
    Lightning node page and payouts need more, including xpay.
  • Rune support in BTCPayServer.Lightning upstream, so bitcoinix can connect BTCPay Server
    through clnrest with a restricted rune.

Testing

  • nix eval .#ciTestInfo passes.
  • nix build .#checks.x86_64-linux.module-config and .#checks.x86_64-linux.test-runner pass.
  • nix shell --inputs-from . nixpkgs#mdbook -c mdbook build succeeds. The new section and
    its link to Custom macaroons render.
  • No VM run, because nothing changes at runtime.
  • After the rebase onto master 0d12e6c, module-config, test-runner, ci-workflows and the mdBook build pass on the KVM host.

Models

Claude Opus 5.5 wrote the change. Codex GPT-5.6 Sol, Codex GPT-6 Astra (two passes plus rechecks), Kimi K3.1 Pro (two passes), DeepSeek V4.1 Flash 1017 and GLM 5.3 reviewed it. Claude Opus 5.5 rebased it onto #224.

@github-actions github-actions Bot added area: docs docs/, README, examples/, SECURITY.md, book.toml, assets area: modules modules/ and pkgs/lib.nix labels Nov 16, 2026
@prusnak

prusnak commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Ugh, that is nasty.

Maybe we should use clnrest to connect btcpayserver to cln instead so runes are allowed? Does using clnrest fix this issue?

FTR: i am ok with merging this PR as is. I am just raising a question for possible future PR.

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

No actionable findings. Checked the documented access against BTCPay's configured Core Lightning socket/group membership, clnrest admin-rune permissions, and the actual LND macaroon permission list. The distinction is accurate: the Core Lightning connection provides unrestricted RPC access, while the default LND macaroon lacks the permissions to spend or manage channels. The mdBook build passes. This review covers the documentation change, not a fix for the broader access tracked in #87.

Review performed with Codex (GPT-6 Astra).

@ostermayer

ostermayer commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator Author

It would help, but BTCPay Server can't use it yet. Its Lightning library connects to Core Lightning only through JSON-RPC, over the lightning-rpc socket or TCP. It has no clnrest client and can't send a rune. Its master branch is the same.

With rune support, a rune that allows only the invoice methods would fix this for stores that only receive payments. Stores that pay out over Lightning would still need pay.

I believe there are two ways to fix this issue.

  • Add clnrest and runes to BTCPayServer.Lightning upstream.
  • Put a small proxy in front of the socket that passes only the methods BTCPay needs.

#87 tracks it, and I added these details there. I'll work on the upstream rune support in BTCPayServer.Lightning.

…s funds

With `lightningBackend = "clightning"`, BTCPay Server joins the clightning
group and talks to lightningd over its RPC socket. The socket allows every
method, so BTCPay Server can pay invoices, withdraw on-chain funds, open and
close channels and start plugins. A bug in BTCPay Server, a malicious BTCPay
plugin or a stolen admin session can drain the node. With `lnd`, BTCPay
Server gets a macaroon that can't send funds. Neither the option nor the
docs said so.

Describe the access of each backend in the option description and in a new
BTCPay Server section in docs/services.md, and recommend `lnd` when
BTCPay Server should be limited.

Part of bitcoinix#87.

Assisted-by: Claude Code (Claude Opus 5.5)
The docs said that with `lnd` BTCPay Server can't send funds. That holds
for the Lightning node only. A hot wallet created in BTCPay Server keeps
its keys on the node, so BTCPay Server can spend it with either backend.

The docs also advised switching to `lnd` without saying that bitcoinix
turns on Core Lightning for BTCPay Server only while it's the backend.
On a node that relies on that, the switch stops Core Lightning while it
has channels, and nothing watches them. Say to set
`services.clightning.enable = true` first, or to close the channels, and
to give lnd another port, since both daemons default to 9735.

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

seberm commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

The content is accurate: I checked it against modules/btcpayserver.nix on master (the lnd macaroon permissions, Core Lightning enabled only while it's the backend, the port 9735 assertion in modules/lnd.nix).

Must:

  • Rebase onto master. docs/release-notes.md conflicts: move the entry from the new ## 0.1.7 heading into the existing ## 0.2.0 section and drop the ## 0.1.7 heading. Also change "0.1.7 release note" to 0.2.0 in the PR description.

Tested: read the diff and checked the docs against the module on master. No local build, CI covers it.

Assisted-by: Claude Code (Claude Opus 5.5)

@seberm seberm added this to the v0.2.0 milestone Nov 17, 2026
@ostermayer
ostermayer force-pushed the docs-btcpay-clightning-backend-access branch from 8f01f16 to 536049e Compare November 18, 2026 00:19
@github-actions github-actions Bot added status: rebase needed Merge conflicts need to be resolved and removed status: rebase needed Merge conflicts need to be resolved labels Nov 18, 2026
@prusnak
prusnak enabled auto-merge November 18, 2026 10:14
@github-actions github-actions Bot removed the status: rebase needed Merge conflicts need to be resolved label Nov 18, 2026
@prusnak
prusnak merged commit 4da99af into bitcoinix:master Nov 18, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: docs docs/, README, examples/, SECURITY.md, book.toml, assets area: modules modules/ and pkgs/lib.nix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants