question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow passing SSL configuration into options for @key/postgres

See original GitHub issue

I recently found that I was unable to use the keyv postgres backend because the production database I was connecting to forces SSL connections. This is a request to add the ability to pass SSL configuration options into the Keyv object. Or more generally to allow passing external pool for Keyv to make use of.

These are a sample of the errors I was getting:

Error from keyv.Keyv: error: no pg_hba.conf entry for host "3.89.49.50", user "postgres", database "postgres", SSL off

And the more cryptic message (this occurs after the above error):

TypeError: query is not a function
  File "/app/node_modules/@keyv/postgres/src/index.js", line 29, col 19, in <anonymous>
    .then(query => query(sqlString, values));
  File "/app/node_modules/@keyv/postgres/src/index.js", in runMicrotasks
  File "node:internal/process/task_queues", line 96, col 5, in processTicksAndRejections

Here’s a sample from my project of the SSL options:

import * as fs from 'fs';
import { Pool, PoolConfig } from 'pg';

function setupPgPool(): Pool {
  const poolConfig: PoolConfig = {
    connectionString:
      process.env.DATABASE_URL ||
      'postgres://postgres:postgres@localhost:5432/regen_registry',
  };

  if (process.env.NODE_ENV === 'production') {
    poolConfig.ssl = {
      ca: fs.readFileSync(`${__dirname}/../config/rds-combined-ca-bundle.pem`),
    };
  }

  const pool = new Pool(poolConfig);
  return pool;
}

const pgPool = setupPgPool();

export { pgPool };

Here’s an upstream issue with some additional info in case it is helpful. I would be glad to work on this once an approach is decided.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jaredwraycommented, Oct 31, 2022

@wgwz - this should be going out in the next two weeks. Closing down this ticket.

1reaction
jaredwraycommented, Oct 18, 2022

The first approach where we pass the config into @keyv/postgres storage adapter would be the preferred.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PostgreSQL SSL Certificate Configuration - Alibaba Cloud
This article mainly discusses how to prevent Intermediate attackers and how to configure cert using certificates without password login.
Read more >
Setting up SSL authentication for PostgreSQL - CYBERTEC
This blogposts helps you to set up SSL authetication for PostgreSQL and enables you to handle secure client server connections in the best ......
Read more >
Documentation: 15: 34.19. SSL Support - PostgreSQL
PostgreSQL has native support for using SSL connections to encrypt client/server communications using TLS protocols for increased security.
Read more >
How to Enable SSL authentication for an EDB Postgres ...
This guide describes the steps needed to enable SSL authentication for an EDB Postgres ... Verifying - Enter pass phrase for server.key:.
Read more >
Using psql to connect to PostgreSQL in SSL mode
psql below 9.2 does not accept this URL-like syntax for options. The use of SSL can be driven by the sslmode=value option on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found