GeezerVison is showing github.com — self signed certificate error · Issue #2009 · brianc/node-postgres
self signed certificate error #2009DescriptionHi. Sorry ahead of time, I don't have a lot of detail here. We updated our packages today and afterwards started seeing a connection error from Sequelize ORM: "self signed certificate". We do in fact use a self signed certificate but this has never been a problem for us in the past. We downgraded from [email protected] to [email protected] and then we were able to connect again. Reacted by Ian Remmel, Cameron Perry, Clay Murray, Dimos Botsaris, Brandon Zacharie, Tao Peng, Ján Káčer, Luke Hedin, Roman Leventov, Diego Rodríguez Baquero and 13 more Activityianwremmel commented on Nov 19, 2019 If I’m reading bf029c8 correctly, I think there may have been a bunch of options (including rejectUnauthorized) being inadvertently set to falsy values. They are now not set at all unless you pass them in. The last release was a breaking change, but it’s probably easiest to fix by passing rejectUnauthorized: false to pg. Reacted by Vaibhav Dwivedi and Paul Ojo ianwremmel commented on Nov 19, 2019 Sorry, I think I actually meant checkServerIdentity. charmander commented on Nov 20, 2019
I think there may have been a bunch of options (including rejectUnauthorized) being inadvertently set to falsy values
tls.connect treats rejectUnauthorized: undefined as rejectUnauthorized: false? … It does. Oh no. :(
Well, it’s a good thing that was fixed. We should probably add a test for it. It might also be worth a security announcement (@brianc). powerc9000 commented on Nov 20, 2019 eldimious commented on Nov 20, 2019 znarf commented on Nov 20, 2019 BrandonZacharie commented on Nov 20, 2019 Kinetic-Pulse commented on Nov 20, 2019 ptpt commented on Nov 20, 2019 jsanta commented on Nov 20, 2019 If it may help someone else, we just added the rejectUnauthorized: false, to our sequelize connection configuration:
sequelize: {
uri:
'postgres://postgres_user:postgres_user_password@postgres_server:5432/postgres_database',
options: {
database: 'postgres_database',
dialect: 'postgres',
host: 'postgres_server',
port: 5432,
username: 'your_postgres_user',
password: 'your_postgres_user_password',
pool: {
max: 3,
min: 1,
idle: 10000,
},
dialectOptions: {
ssl: {
require: true,
// Ref.: https://github.com/brianc/node-postgres/issues/2009
rejectUnauthorized: false,
},
keepAlive: true,
},
ssl: true,
define: {
timestamps: false,
},
},
},
lets say the error is still there, but we are not being notified, and the backend is not crashing anymore. Just adjust the configuration according to your own needs.
Best regards from Chile. Reacted by Sergey Chernetsky, Kane Wang, Oscar Yañez, Matt Ramotar, Vilhelm Tamm, Hans, vothikimhieu18600091, Alex Chugaev, aparecida-gui, Louis Lepper and 5 more Reacted by Segers Ian, Alexander Kovalyov, Vance Lucas, フアン・カマーチョ, Dominik and Paul Ojo Reacted by Dimos Botsaris, Ján Káčer, Iván Roldán Lusich, Alejandro Corredor, dulyts, Himanshu Mishra, Christopher Taylor, alpha1336, saurabh, Aliaksei Kislou and 19 more Reacted by Sajeel Ahmad Reacted by Jayampathi Adhikari, Iván Roldán Lusich, Alejandro Corredor, Himanshu Mishra, Nadir A. Soza Solis, Christopher Taylor, Sebastián Gutiérrez, CaioValentim, Mathieu, alpha1336 and 11 more brianc commented on Nov 20, 2019 Gah, I apologize for this! There aren't enough tests around self-signed cert connecting with node-postgres in travis so it was missed. Totally accidental on my part! I'm going to roll out a backwards-compatible (to the 7.x line) semver patch on top of this one to make sure it behaves exactly as it should.
@charmander what do you mean about security announcement? This makes things more secure now right? By forcing unauthorized cert rejection, where as before it was ignoring it? We should probably make the defaults be the same as the node.js defaults in v8.0. Do you mean announcing the current behavior is insecure in that it allows unauthorized certs unless you specifically set rejectUnauthorized to something to true? I agree that's worth calling out. We should also re-introduce this breaking change in 8.0 (w/ a deprecation notice in the 7.x line) so we can get folks to migrate to better ssl configurations. Reacted by eric-elsholz, François Hodierne, Dimos Botsaris, Euan Caskie, Dirk Heniges and Paul Ojo brianc commented on Nov 20, 2019 Okay - released [email protected] which reverts [email protected] 🤕 sorry about that!
I'd like to get self-signed and "proper" ssl connections tested in travis. Anyone have a docker file handy that sets both of those things up? Then we can be covered on this behavior going forward. Reacted by Vipul Joshi and Paul Ojo Reacted by François Hodierne, Ian Reynolds, Dimos Botsaris, Vipul Joshi and Paul Ojo charmander commented on Nov 20, 2019
@charmander what do you mean about security announcement? This makes things more secure now right? By forcing unauthorized cert rejection, where as before it was ignoring it?
@brianc Yep, it does! I meant an announcement that pg 0.8.7 through 7.12.0 don’t check certificates.
(edit)
Do you mean announcing the current behavior is insecure in that it allows unauthorized certs unless you specifically set rejectUnauthorized to something to true? I agree that's worth calling out. We should also re-introduce this breaking change in 8.0 (w/ a deprecation notice in the 7.x line) so we can get folks to migrate to better ssl configurations.
Yes, exactly that. sehrope commented on Nov 20, 2019 +1 to having the default in a new major being to validate so that it's an explicit action to disable things.
FYI, the default for libpq (ex: via psql) is not to validate either so the default behavior of this module till now is not totally crazy either. May be worth calling that out in any security announcement: https://www.postgresql.org/docs/current/libpq-ssl.html (Still a +1 to making a security note calling out the behavior) Reacted by Charmander and Paul Ojo sehrope commented on Nov 20, 2019 @brianc RE: a test setup, the defaults for a Debian / Ubuntu postgresql server install configures it to use a self signed "snake oil" cert. Setting it up in Docker container should be similar.
The PGJDBC driver has a whole bunch of SSL related configs and tests for running things on Travis. Includes overwriting the certs, setting up specific users, installing the sslinfo extension for verifying things. May be worth a peek: https://github.com/pgjdbc/pgjdbc charmander commented on Jul 12, 2021 simon1tan commented on Aug 21, 2021 RodrigoBeiraoCardoso commented on Sep 3, 2021 jsanta commented on Sep 3, 2021 RodrigoBeiraoCardoso commented on Sep 3, 2021 Tosinkoa commented on Sep 19, 2022 charmander commented on Sep 22, 2022 Tosinkoa commented on Sep 30, 2022 pantelis-karamolegkos commented on Feb 21, 2024 I have the following node script
const { Pool } = require('pg');
const { parse } = require('pg-connection-string');
const config = parse(process.env.DATABASE_URL);
config.ssl = { rejectUnauthorized: true };
const pool = new Pool(config);
pool.connect((err, client, done) => {
if (err) {
console.error('Error acquiring client', err.stack);
return;
}
const testQuery = 'SELECT * FROM information_schema.tables';
client.query(testQuery, (err, result) => {
done();
if (err) {
console.error('Error executing query', err.stack);
return;
}
console.log('Query result:', result.rows);
pool.end();
});
});
Before running the script I am exporting the NODE_EXTRA_CA_CERTS=../aws-global-bundle.pem where the .pem file is this one.
My question is how can I enforce the verify-full option as described in the official postgresql documentation and what is the practical difference with setting the rejectUnauthorized to true ?
I have tried the following
config.ssl = {
rejectUnauthorized: true,
sslmode: 'verify-full',
ca: fs.readFileSync('./global-bundle.pem').toString(),
};
However it is as if the sslmode: 'verify-full', is not actually being taken into account because when I use sslmode: 'foobar', it does not complain at all (and connects as expected. charmander commented on Feb 22, 2024 @pantelis-karamolegkos sslmode is a connection string parameter (and has a corresponding environment variable named PGSSLMODE). It’s translated to the ssl: … property of the pg configuration object when you use a connection string. There is no ssl.sslmode. rejectUnauthorized: true/verify-full is the default behavior of Node’s tls module that pg passes the ssl object to directly, so all you need is
config.ssl = {
ca: fs.readFileSync('./global-bundle.pem'),
};Repository owner locked as resolved and limited conversation to collaborators on Feb 27, 2026
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|