brianc / node-postgres Public
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
Allow users to pass certs when PG environment variable PGSSLMODE=require/verify-ca/verify-full #2517
base: master
Are you sure you want to change the base?
Allow users to pass certs when PG environment variable PGSSLMODE=require/verify-ca/verify-full #2517
Conversation
Gotcha, thought erroring would be better since if certs aren't passed in with the SSLMODEs then they won't be able to connect and getting a somewhat vague
is confusing since theres actually no certs to update. As far as I can tell, certs won't be populated anywhere when Do you think logging a warning is appropriate? It certainly would've helped me out. |
29e0be5
to
e0af654
Compare
Updated so that it'll return an object with the cert properties. Please let me know if this is reasonable, mostly the part about returning undefined if the environment variable is not present for the certs. |
I just tried passing a cert via env var
|
889bb42
to
6b736e5
Compare
If PGSSLMODE is specified and is either require, verify-ca or verify-full, then the PGSSLROOTCERT, PGSSLCERT, and PGSSLKEY environment variables will be checked for certificate paths and used to connect. This also includes a fix to CI to stop getting the following error: ``` yarn install v1.22.17 [1/4] Resolving packages... [2/4] Fetching packages... error Command failed. Exit code: 128 Command: git Arguments: ls-remote --tags --heads git://github.com/BonsaiDen/Fomatto.git Directory: /home/runner/work/node-postgres/node-postgres Output: fatal: remote error: The unauthenticated git protocol on port 9418 is no longer supported. Please see https://github.blog/2021-09-01-improving-git-protocol-security-github/ for more information. info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. ```
6b736e5
to
7b1c4b1
Compare
Previously if
readSSLConfigFromEnvironment
was used to generate the SSL config, the ssl object would not be created to create certs.I ran into this issue when trying to execute yarn tests to a secure cluster (SSLMODE=require), certs would never be read even when I specified
PGSSLCERT, PGSSLKEY, PGSSLROOTCERT
.This fix allows the user to pass in certs through PG env variables.
I'm not great with JS so apologies in advance
Why this is necessary.
To highlight this issue in a simple case
Running the script I attached below through
PGSSLMODE=require PGSSLCERT=/home/ubuntu/certs/client.testuser.crt PGSSLROOTCERT=/home/ubuntu/certs/ca.crt PGSSLKEY=/home/ubuntu/certs/client.testuser.key PGHOST=localhost PGPORT=26257 PGUSER=root node test.js
results in the following error:This is because the ssl field in
ConnectionParameters
is simply set to true and the certs fields are not populated