Skip to content

lndconnect: ask clightning for clnrest's cert dir - #270

Merged
prusnak merged 2 commits into
bitcoinix:masterfrom
ostermayer:lnconnect-clnrest-cert-dir
Nov 18, 2026
Merged

prusnak merged 2 commits into
bitcoinix:masterfrom
ostermayer:lnconnect-clnrest-cert-dir

Conversation

@ostermayer

Copy link
Copy Markdown
Collaborator

Follow-up to #258.

lnconnect-clnrest always passed server.pem from clightning's network dir to lndconnect. clnrest reads its cert dir from clnrest-certs, which can also come from an include file or the per-network config. With that option set, lnconnect-clnrest failed, or it put a stale cert from the network dir into the URL. #258 solved the same problem for RTL at runtime.

What this does

  • lnconnect-clnrest now asks clightning for the effective clnrest-certs with lightning-cli listconfigs clnrest-certs, like RTL. It runs the query as its caller: root or a member of the clightning group.
  • The jq query and the path resolution (unset means the network dir, a relative dir starts there) move into one script, the internal read-only option services.clightning.plugins.clnrest.serverCertPathFromConfigs. It reads the listconfigs output on stdin and prints the path of server.pem. RTL and lnconnect-clnrest both use it, and each runs lightning-cli its own way. RTL's script does the same thing as before.
  • The query only runs when the URL includes the cert from this path. clnrest.lnconnect.onion, --nocert and the caller's own --tlscertpath skip it. So lnconnect-clnrest-wg doesn't depend on clightning at all.
  • When clightning doesn't answer, lnconnect-clnrest prints a warning and uses server.pem from the network dir, as before. That happens when clightning is stopped, or when the caller can't read a config file that lightning-cli reads, for example an include file that only the clightning user can read. The warning says to run the command while clightning runs, or to pass --tlscertpath, when clnrest-certs is set. RTL doesn't fall back. It pins the cert, so it still fails and Restart=on-failure tries again.
  • nix-bitcoin.mkLndconnect gets an optional getCertPathCmd argument. Existing calls work as before.

There's no versioning notice. Nothing that worked before fails now: without an answer from clightning, lnconnect-clnrest does what it did before, with a warning.

Testing

  • netnsRegtest now sets clnrest-certs=rest-certs, a relative dir. There, lnconnect-clnrest-cert compares the URL's cert with clnrest's TLS handshake, which fails without this change. rtl-credentials and rtl-backend-certs use the cert and CA from that dir.
  • regtest still uses the default dir for the same tests.
  • wireguard-lndconnect stops clightning and checks that lnconnect-clnrest-wg --url prints the same URL as before. lnconnect-clnrest --url then prints the warning and a URL with a cert. That URL is the same as the one with --tlscertpath=<network dir>/server.pem, and that call prints no warning.
  • I ran the new script against listconfigs output with no value, a relative dir, an absolute dir with a space, invalid JSON and empty input. I also ran shellcheck on the generated lnconnect-clnrest.

On the KVM host, netnsRegtest, wireguard-lndconnect, ciTestInfo, module-config and test-runner pass on the final head. regtest passed on the previous head, which only differed in the lnconnect-clnrest fallback, its test and the docs.

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.

@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 labels Nov 15, 2026

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

No actionable findings. Checked the shared certificate-path parser, relative/absolute/default path handling, RTL integration, caller-supplied certificate override, no-certificate paths, and warning/fallback behavior. The fallback preserves the old behavior when Core Lightning is unavailable, while RTL still fails if it cannot resolve its certificate. Local module-config, test-runner, and mdBook builds pass. I inspected the relative-cert-dir and offline-command VM coverage and successful CI results; I did not rerun those VMs locally.

Review performed with Codex (GPT-6 Astra).

@github-actions github-actions Bot added the status: rebase needed Merge conflicts need to be resolved label Nov 16, 2026
lnconnect-clnrest always passed `server.pem` from clightning's network dir
to lndconnect. clnrest reads its cert dir from `clnrest-certs`, which can
also come from an included or per-network config file. With that option
set, lnconnect-clnrest failed or put the wrong cert into the URL.

Ask clightning for the effective `clnrest-certs`, like RTL does since
clnrest.nix that both use. lnconnect-clnrest only asks when the URL
includes the cert and the caller doesn't pass `--tlscertpath`. When
clightning doesn't answer, for example because it's stopped, it prints a
warning and uses the network dir, as before. RTL still fails then,
because it pins the cert.

`netnsRegtest` now sets a relative `clnrest-certs` dir, which
`lnconnect-clnrest-cert` and the RTL tests check.

Follow-up to bitcoinix#258.

Assisted-by: Claude Code (Claude Opus 5.5)
@ostermayer
ostermayer force-pushed the lnconnect-clnrest-cert-dir branch from 4b0259b to 7a4e6c8 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 previously approved these changes Nov 18, 2026

@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 added this to the v0.2.0 milestone Nov 18, 2026
@prusnak
prusnak enabled auto-merge November 18, 2026 10:46
@github-actions github-actions Bot removed the status: rebase needed Merge conflicts need to be resolved label Nov 18, 2026
@prusnak
prusnak merged commit e389078 into bitcoinix:master Nov 18, 2026
25 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants