Skip to content

fix(db): make postgres SSL opt-in via SQL_SSL=true#181

Merged
TaprootFreak merged 2 commits intodevelopfrom
fix/sql-ssl-optional
May 8, 2026
Merged

fix(db): make postgres SSL opt-in via SQL_SSL=true#181
TaprootFreak merged 2 commits intodevelopfrom
fix/sql-ssl-optional

Conversation

@TaprootFreak
Copy link
Copy Markdown
Contributor

@TaprootFreak TaprootFreak commented May 7, 2026

Summary

Make the postgres SSL config controllable via env-var instead of being hardcoded.

The hardcoded ssl: { rejectUnauthorized: false } in src/config/config.ts always negotiates TLS to the postgres host. That breaks the dfxdev/dfxprd setup where the API talks to a local api-postgres container that doesn't speak SSL:

Error: The server does not support SSL connections

Fix

ssl: process.env.SQL_SSL === 'false' ? false : { rejectUnauthorized: false },

SSL-on stays the default (matches the previous behaviour). SQL_SSL=false opts out for hosts where the postgres peer doesn't speak TLS.

  • Azure-hosted psql-lds-api-{prd,dev} (Flexible Server, require_secure_transport=on) → no change needed, default still SSL.
  • Local container-postgres (dfxdev/dfxprd LDS stack) → set SQL_SSL=false in the vault item / .env.

Includes

  • Rebased on top of #180 (lds-api stage-2 Dockerfile fix). Merging in either order is fine; the two commits are independent.

Test plan

  • Verified locally on dfxdev: with SQL_SSL=false the lds-api container connects to api-postgres and goes healthy
  • CI LDS API DEV CI/CD builds and pushes lightningdotspacecom/lds-api:beta

Stage 2 was running 'npm ci --omit=dev' from scratch, which triggers
node-gyp on native deps (solana/eth signers) and fails the same way
stage 1 did before — the runtime image base also lacks python/g++.

Fix: do 'npm prune --omit=dev' in the builder (drop dev-only deps from
the existing node_modules tree, keeping the already-compiled native
binaries) and COPY node_modules across to the final stage.

This avoids ever re-running node-gyp at runtime-image-build time and
keeps the runtime base small (no python/toolchain there).
The hardcoded { rejectUnauthorized: false } SSL config forces a TLS
handshake against the postgres host even when the server doesn't speak
SSL — which breaks the dfxdev/dfxprd setup where lds-api talks to a
local api-postgres container without SSL.

  Error: The server does not support SSL connections

Make it opt-in: SSL only when SQL_SSL=true (the Azure-hosted PostgreSQL
Flexible Server expects it; the new container-postgres does not).
@TaprootFreak TaprootFreak force-pushed the fix/sql-ssl-optional branch from 24bb2cf to 260e332 Compare May 8, 2026 06:58
@TaprootFreak TaprootFreak requested a review from davidleomay May 8, 2026 07:18
@TaprootFreak TaprootFreak marked this pull request as ready for review May 8, 2026 07:30
@TaprootFreak TaprootFreak merged commit 39a472b into develop May 8, 2026
1 check passed
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.

2 participants