feat(config): load LND TLS cert from file with env fallback#200
Conversation
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.
The rest of the repo imports { readFileSync } from 'fs' (app.controller,
monitoring.controller); align readCert with that instead of import * as fs.
|
Suggestion: remove the fallback Same comment as on the DFX API counterpart (DFXswiss/api#3861) — the silent fallback to |
|
Done — removed the fallback. Since the lds-api code runs on dfxprd too (not in the original dfxdev-only scope), I migrated dfxprd in the infra PR as well so prod keeps a cert source once the env var is gone — DFXServer/server#366. |
davidleomay
left a comment
There was a problem hiding this comment.
Approved. Deploy after server PR (DFXServer/server#366).
ade542d to
838a806
Compare
|
Small refinement after CI: |
Address review: if LIGHTNING_API_CERTIFICATE_PATH is set, read it or throw. The LIGHTNING_API_CERTIFICATE env var was the stale copy this change fixes, so keeping it as a silent fallback only masks a broken mount. Remove it.
838a806 to
f06a9ef
Compare
Problem
On dfxdev we keep hitting recurring
Failed to fetch Lightning balance: self-signed certificateerrors. The root cause is that the LND TLS certificate is supplied to the app only through theLIGHTNING_API_CERTIFICATEenv 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:LIGHTNING_API_CERTIFICATE_PATHis 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.LIGHTNING_API_CERTIFICATEenv-var behavior, completely unchanged.The certificate is read in
src/config/config.ts(theblockchain.lightning.certificatefield) via a smallreadCert()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_PATHunset 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.