Search code examples
node.jspostgresqlssl

Self-signed certificate not accepted by postgresql even with `rejectUnauthorized: false`


Here is my code:

import pg from 'pg';
const { Pool } = pg;

let connectionString = process.env.DB_CONNECTION_STRING

export const pool = new Pool({
    connectionString: connectionString, 
    ssl: { rejectUnauthorized: false },
})

console.log('connectionString:', connectionString);

And I used self-signed certificate for PostgreSQL within a docker.

It used to work in my previous instance, but no longer work here. I searched across the internet and everybody says "making rejectUnauthorized to be false and you should be good". I wonder why it does not work for me.

It used to not having a certificate so the connection is rejected. And I have added the self-signed certificate and restarted the service to make it work. Both cert and key, but not ca.cert. I assume the problem is still in the node.js side.


Solution

  • I realised that I have a ?ssl=true at the end of my connectString. Removing it makes the command works.

    I guess it somehow overwritten the SSL config provided here.