Skip to content
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

Merged
merged 8 commits into from Aug 15, 2020

Conversation

woyuen
Copy link
Member

@woyuen woyuen commented Aug 14, 2020

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.

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.
@woyuen woyuen requested a review from abruere August 14, 2020 11:30
@woyuen woyuen self-assigned this Aug 14, 2020
Copy link
Member

@abruere abruere left a 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.

@@ -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
Copy link
Member

@abruere abruere Aug 14, 2020

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.

@woyuen woyuen merged commit df1cb9e into dev Aug 15, 2020
@woyuen woyuen deleted the feat/database-ssl-connection branch August 15, 2020 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants