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:
~shell
CUBEJS_DB_SSL_CA="-----BEGIN CERTIFICATE-----\nMIIEBjCCAu6gAwIBAgIJAMc0ZzaSUK51MA0GCSqGSIb3DQEBCwUAMIGPMQswCQYD\nVQQGEwJVUzEQMA4GA1UEBwwHU2VhdHRsZTETMBEGA1UECAwKV2FzaGluZ3RvbjEi\n-----END CERTIFICATE-----"
~
But the postgres driver fails with:
~shell
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):
~javascript
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:
Expected behavior
Version:
0.24.2
Additional context
Reproduced locally and on cube cloud, connecting to a Google Cloud SQL postgres 11 database
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
@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 (https://github.com/motdotla/dotenv/issues/458), it's better solution from DX perspective to load keys from the FS.
Thanks
Thanks, @ovr. Good work refactoring those pieces of code, BTW.
I was able to connect from Cube Cloud now using pem files.
@petrusgomes
Happy to hear! If you are using Cube Cloud, npx deploy --upload-env will update certs inside the Cube Cloud.