-
Notifications
You must be signed in to change notification settings - Fork 332
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
feat(pg): support SSL certs #7175
Conversation
Signed-off-by: Matt Krick <[email protected]>
Signed-off-by: Matt Krick <[email protected]>
Signed-off-by: Matt Krick <[email protected]>
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Just in case, I'm taking this but not yet.. Review is coming soon. |
Why is the folder That would allow much more flexibility and remove the data from the application folder. |
IMHO this PR should have documentation on how to enable SSL for PostgreSQL. A md file or in the general README.md with the instructions and parameters describing how to configure it. Like what should be in each one of the files root.crt, postgresql.key, postgresql.crt, in which folder those files should be and anything else that could help. |
Signed-off-by: Matt Krick <[email protected]>
Signed-off-by: Matt Krick <[email protected]>
Signed-off-by: Matt Krick <[email protected]>
documentation added! ready to merge as soon as tests pass |
… CloudSQL without the CloudSQL Proxy.
const ca = readFileSync(path.join(PG_CERT_DIR, 'root.crt')) | ||
const key = readFileSync(path.join(PG_CERT_DIR, 'postgresql.key')) | ||
const cert = readFileSync(path.join(PG_CERT_DIR, 'postgresql.crt')) | ||
return {ca, key, cert, rejectUnauthorized: false} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed rejectUnauthorized: true
to false
because the certificate provided by GCP CloudSQL only has a as name of the server the one used by the CloudSQL Proxy (we are going to use it in the future). You can see other similar cases on internet like this one.
IMHO, this could be improved using a parameter PG_SSL_REJECT_UNAUTHORIZED
. We could set it to true or false depending on the use case. If you think we should do it that way, please add that to the PR. If not, it is working!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to share the error I saw
node:internal/process/promises:279
triggerUncaughtException(err, true /* fromPromise */);
^
Error [ERR_TLS_CERT_ALTNAME_INVALID]: Hostname/IP does not match certificate's altnames: Host: postgresql.test-instance-6.parabol.local. is not cert's CN: parabol-proving-ground:test-instance-6-postgresql-1b252b94
at new NodeError (node:internal/errors:372:5)
at Object.checkServerIdentity (node:tls:346:12)
at TLSSocket.onConnectSecure (node:_tls_wrap:1542:27)
at TLSSocket.emit (node:events:527:28)
at TLSSocket.emit (node:domain:475:12)
at TLSSocket._finishInit (node:_tls_wrap:946:8)
at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:727:12) {
reason: "Host: postgresql.test-instance-6.parabol.local. is not cert's CN: parabol-proving-ground:test-instance-6-postgresql-1b252b94",
host: 'postgresql.test-instance-6.parabol.local',
IT GOES AND GOES with more stuff that are less relevant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1 I don't know. To me it seems to be a setup issue on our side and I would rather fix that than disabling this check. Basing this solely on this comment: GoogleCloudPlatform/nodejs-docs-samples#1735 (comment)
const ca = readFileSync(path.join(PG_CERT_DIR, 'root.crt')) | ||
const key = readFileSync(path.join(PG_CERT_DIR, 'postgresql.key')) | ||
const cert = readFileSync(path.join(PG_CERT_DIR, 'postgresql.crt')) | ||
return {ca, key, cert, rejectUnauthorized: false} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1 I don't know. To me it seems to be a setup issue on our side and I would rather fix that than disabling this check. Basing this solely on this comment: GoogleCloudPlatform/nodejs-docs-samples#1735 (comment)
Problem found when running migrations. It shows an error
The PG migrations are using the file |
Signed-off-by: Matt Krick <[email protected]>
Suggestion: change all variables here from PGXXX to POSTGRES_SSL_XXX to follow the same format. Current variables
Added in the PR so far:
Proposed:
|
This reverts commit d351c3c.
Signed-off-by: Matt Krick <[email protected]>
Signed-off-by: Matt Krick <[email protected]>
Signed-off-by: Matt Krick <[email protected]>
Signed-off-by: Matt Krick [email protected]
Description
Fixes #7174
Demo
N/A
Testing scenarios
root.crt, postgresql.key, postgresql.crt
topackages/server/postgres
. You are now connecting via SSL@rafaelromcar-parabol could I ask you to test this? I think you can probably self sign a cert faster than me 🙂