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

Postgres driver (and maybe others) don't support SSL certs as env variables #1495

Closed
petrusgomes opened this issue Dec 1, 2020 · 4 comments · Fixed by #1512 or #1538
Closed

Postgres driver (and maybe others) don't support SSL certs as env variables #1495

petrusgomes opened this issue Dec 1, 2020 · 4 comments · Fixed by #1512 or #1538
Assignees
Labels
bug Something isn't working docs Issues that require a documentation improvement

Comments

@petrusgomes
Copy link

petrusgomes commented Dec 1, 2020

Describe the bug
When using environment variables to set SSL ca, cert and key, file contents are not read correctly because newlines (/n) are escaped.

I tried like suggested in the example from cube.dev docs:

CUBEJS_DB_SSL_CA="-----BEGIN CERTIFICATE-----\nMIIEBjCCAu6gAwIBAgIJAMc0ZzaSUK51MA0GCSqGSIb3DQEBCwUAMIGPMQswCQYD\nVQQGEwJVUzEQMA4GA1UEBwwHU2VhdHRsZTETMBEGA1UECAwKV2FzaGluZ3RvbjEi\n-----END CERTIFICATE-----"

But the postgres driver fails with:

error connecting Error: error:0909006C:PEM routines:get_name:no start line

I was able to succesfully connect adding a "replace" to the following code (in PostgresDriver.js):

ssl = sslOptions.reduce(
        (agg, { name, value }) => ({
            ...agg,
            ...(process.env[value] ? { [name]: process.env[value].replace(/\\n/g, '\n') } : {}),
        }),
        {}
    );

To Reproduce
Steps to reproduce the behavior:

  1. Setup database to expect SSL
  2. Set CUBEJS_DB_SSL_CA, CUBEJS_DB_SSL_CERT and CUBEJS_DB_SSL_KEY as PEM file contents
  3. Start server
  4. See error

Expected behavior

Version:
0.24.2

Additional context
Reproduced locally and on cube cloud, connecting to a Google Cloud SQL postgres 11 database

@ovr ovr self-assigned this Dec 2, 2020
@hassankhan hassankhan self-assigned this Dec 3, 2020
@hassankhan hassankhan added bug Something isn't working docs Issues that require a documentation improvement labels Dec 3, 2020
@hassankhan hassankhan linked a pull request Dec 3, 2020 that will close this issue
@ovr
Copy link
Member

ovr commented Dec 3, 2020

Hello @petrusgomes,

Thank you for the issue, So, I am working on it. I will come back to you shortly with a better solution.

Thanks

@ovr ovr closed this as completed in #1512 Dec 4, 2020
@ovr
Copy link
Member

ovr commented Dec 7, 2020

@petrusgomes

We added support for loading SSL keys from the file system in v0.24.4.

CUBEJS_DB_SSL_CA=./server-ca.pem
CUBEJS_DB_SSL_KEY=./client-key.pem
CUBEJS_DB_SSL_CERT=./client-cert.pem

Because dotenv doesn't support multiline support (motdotla/dotenv#458), it's better solution from DX perspective to load keys from the FS.

Thanks

@petrusgomes
Copy link
Author

Thanks, @ovr. Good work refactoring those pieces of code, BTW.
I was able to connect from Cube Cloud now using pem files.

@ovr
Copy link
Member

ovr commented Dec 7, 2020

@petrusgomes

Happy to hear! If you are using Cube Cloud, npx deploy --upload-env will update certs inside the Cube Cloud.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docs Issues that require a documentation improvement
Projects
No open projects
3 participants