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: add SSL options to PostgreSQL connection #379
Conversation
Some database providers only accepts requests with SSL enabled (e.g. Timescale Cloud). We support the following SSL options: ssl, cert, key, ca Those options will map from Knex.js to the library https://github.com/iceddev/pg-connection-string thanks to the Knex.js PR knex/knex#3410 Please be careful when configuring SSL connection. Passing key value into cert or inversely can trigger an uncaught exception and even `process.on('uncaughtException', fn)` cannot catch it.
for local and CircleCI environments. Previously, test was failing with a single-domain certificate. SSL certificate was rejected for CircleCI as the host didn't match the certificate information (localhost). For tests, we used a self-signed multi-domains certificate to check database SSL connections. However generating a self-signed multi-domain certificate isn't enough for Node.js, as it will reject it because it is self-signed. To overcome this, we have to sign it with another root certificate (that can be self-signed). For Knex connection configuration, we need to provide the two certificates as `sslcert` and `sslca` properties. In real world usage, you may only need to specify one of them.
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.
Thank you @woyuen.
Please make sure appropriate context of your individual commit messages and of this PR are included in squashed commit message before merging.
docker-compose.override.yml
Outdated
@@ -35,6 +35,22 @@ services: | |||
volumes: | |||
- timescaledb-v1.7.1-pg12-data:/var/lib/postgresql/data/pgdata | |||
|
|||
# Service used only test environment to check if SSL database connections work |
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.
in test environment
EDIT: removed after refactoring.
Some database providers only accepts requests with SSL enabled
(e.g. Timescale Cloud).
We support the following SSL options: ssl, cert, key, ca
Those options will map from Knex.js to the library
https://github.com/iceddev/pg-connection-string
thanks to the Knex.js PR
knex/knex#3410
Please be careful when configuring SSL connection.
Passing key value into cert or inversely can trigger
an uncaught exception and even
process.on('uncaughtException', fn)
cannot catch it.
Add multi-domains certificate to PostgreSQL Docker image to check
that SSL connections is correctly handled in tests.