Skip to content

feat(config): load LND TLS cert from file with env fallback#200

Open
Danswar wants to merge 1 commit into
developfrom
feat/lightning-cert-from-file
Open

feat(config): load LND TLS cert from file with env fallback#200
Danswar wants to merge 1 commit into
developfrom
feat/lightning-cert-from-file

Conversation

@Danswar

@Danswar Danswar commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Problem

On dfxdev we keep hitting recurring Failed to fetch Lightning balance: self-signed certificate errors. The root cause is that the LND TLS certificate is supplied to the app only through the LIGHTNING_API_CERTIFICATE env var, which is a hand-copied snapshot of the cert. Whenever LND regenerates its certificate, that env-var copy goes stale and no longer matches the live cert, so the HTTPS connection to LND fails.

Change

This adds support for a new optional env var LIGHTNING_API_CERTIFICATE_PATH:

  • If LIGHTNING_API_CERTIFICATE_PATH is set and the file is readable, the app reads the certificate straight from that file on disk (fs.readFileSync). Pointing this at the live LND cert means it can never drift again.
  • Otherwise the app falls back to the existing LIGHTNING_API_CERTIFICATE env-var behavior, completely unchanged.
  • If the path is set but the file is missing/unreadable, it silently falls back to the env var (config.ts has no logger).

The certificate is read in src/config/config.ts (the blockchain.lightning.certificate field) via a small readCert() helper. The lightning client TLS logic that consumes this cert is untouched.

Backward compatibility

Fully backward compatible. With no new env var set, behavior is identical to before. Nothing is removed.

Deploy order

Safe to ship code first: with LIGHTNING_API_CERTIFICATE_PATH unset there is zero behavior change. The matching infra change (mounting the live LND cert file into the container and setting the new env var) is a separate PR in the server/infra repo, which can land afterward to actually switch dfxdev over to the file.

Add support for an optional LIGHTNING_API_CERTIFICATE_PATH env var. When
set and readable, the LND TLS certificate is read from that file on disk
(the live cert), avoiding the recurring 'self-signed certificate' errors
that occur when the hand-copied LIGHTNING_API_CERTIFICATE env var drifts
after LND regenerates its cert.

Fully backward compatible: if the path is unset or unreadable, falls back
to the existing LIGHTNING_API_CERTIFICATE env-var behavior unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant