Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node-Postgres Pool.ssl.mode: disabled is being ignored. #3089

Open
BrokenFlame opened this issue Nov 2, 2023 · 1 comment
Open

Node-Postgres Pool.ssl.mode: disabled is being ignored. #3089

BrokenFlame opened this issue Nov 2, 2023 · 1 comment

Comments

@BrokenFlame
Copy link

I'm setting the Node-Postgres Pool parameter ssl.mode to disabled via an environment variable. However I'm get the error:

"name":"Error","message":"The server does not support SSL connections","stack":"Error: The server does not support SSL connections\n

My code is simple enough, and the object stringifying the Pool object confirms the setting:

... "ssl\":{\"rejectUnauthorized\":\"false\",\"ca\":null,\"mode\":\"disable\"} ...

The code is pretty simple and works fine when a Certificate Authority Pem is provided, and I need to connect over SSL. It just doesn't seem to work, when I don't want to use SSL to connect to the server.

import { Pool } from 'pg';
import fs from "fs";
import dotenv from "dotenv";

const dbPoolConfig = {
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  host: process.env.DB_HOST,
  port: process.env.DB_PORT,
  database: process.env.DB_NAME,
  connectionTimeoutMillis: 10 * 1000,
  idleTimeoutMillis: 60 * 60 * 1000,
  max: 2,
  statement_timeout: 10 * 1000,
  query_timeout: 10 * 1000,
  ssl: {
    rejectUnauthorized: process.env.DB_REJECT_UNAUTHORIZED,
    ca: process.env.DB_CA_PATH ? fs.readFileSync(process.env.DB_CA_PATH, 'ascii').toString() : null,
    mode: process.env.DB_SSL_MODE ? process.env.DB_SSL_MODE : 'allow',
  },
};

export const dbPool: Pool | null = ['preprod', 'uat', 'development', 'production'].includes(process.env.ENV)
  ? new Pool(dbPoolConfig)
  : null;

// TODO: remove conditional export
export default dbPool;

I'm not sure if this is a bug or, if I'm doing something wrong. Maybe I should be setting the CA to "undefined"?

@charmander
Copy link
Collaborator

If you don’t want to use SSL, you need to set the entire ssl property to a falsy value. ssl.mode is not an option that exists; you might be thinking of the sslmode connection string parameter.

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

No branches or pull requests

2 participants