Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Lumber not allowing pass-through of dialectOptions for Sequelize #452

Closed
antoniojtorres opened this issue Jul 18, 2020 · 13 comments
Closed
Assignees

Comments

@antoniojtorres
Copy link

antoniojtorres commented Jul 18, 2020

This may be more of a feature request / limitation than a bug. Thanks in advance.

Expected behavior

Setting up ForestAdmin using lumber for the first time. Have a backend service in heroku using Heroku Postgres. When generating the lumber command and adding my database connection. Once that runs I expect lumber to run successfully.

Actual behavior

When running the command I received the error "SequelizeConnectionError: self signed certificate". This is because heroku postgres uses self-signed certificates for this database.

When specifying ssl as true, lumber-generate.js generates these options for Sequelize
{ logging: false, dialectOptions: { ssl: true } }

This isn't enough for my scenario.

The installation can be pushed through with
{ logging: false, dialectOptions: { ssl: true, rejectUnauthorized: false } }

This issue is not about what is right or wrong in terms on how to connect. What I am suggesting is providing the ability to have a pass-through for database specific flags so users can tackle their edge cases. The current implementation in lumber-generate has a very narrow set of options.

Failure Logs

? Does your database require a SSL connection? Yes
✖ Connecting to your database

Cannot connect to the database due to the following error:
SequelizeConnectionError: self signed certificate

Context

Node 12.16.3
NPM 6.14.4

  • Lumber Package Version: 3.6.4
  • Database Dialect: PostgreSQL
  • Database Version: 12.3

Thank you all for the wonderful code and product. Big fan.

PS: As you may have figured, when I launched the admin the cert validation error is also present there. I am stuck :(

@rap2hpoutre
Copy link
Contributor

Hi @antoniojtorres! Thank you for your feedback and this detailed explanation 👍 . I guess we should improve this, I opened an issue on our product board about this need.

@snwfdhmp
Copy link

Hi, I need this too !

@djpate
Copy link

djpate commented Sep 4, 2020

Same, I can't use DigitalOcean managed DB because of this.

@snwfdhmp
Copy link

snwfdhmp commented Sep 7, 2020

I cannot use Heroku managed DB myself because of this.

@rap2hpoutre
Copy link
Contributor

@snwfdhmp & @djpate Thank you for your feedback. This concern has been reported to the product team which is aware of the issue. This is currently in our roadmap. You will be notified as soon as it has been released!

@snwfdhmp
Copy link

snwfdhmp commented Sep 7, 2020

Thanks a lot ! You can test if this works with Heroku simply via their free Postgres add-ons

@rap2hpoutre
Copy link
Contributor

Related issue here: https://community.forestadmin.com/t/ssl-issues-with-forestadmin/837

(Side note: I'm working on a patch, I hope to release it this week).

@rap2hpoutre
Copy link
Contributor

rap2hpoutre commented Sep 21, 2020

Hi @antoniojtorres @djpate @snwfdhmp

We just released a new version of Lumber that adds a DATABASE_REJECT_UNAUTHORIZED parameter in Lumber generated projects (it is set to false by default to ease users onboarding). If you update Lumber to the latest version then start a new project, you should not be annoyed anymore with the SequelizeConnectionError: self-signed certificate message.

If you want to fix your actual project without re-running the install command, add this line to your .env file:

DATABASE_REJECT_UNAUTHORIZED=false

Then edit models/index.js (here):

-  databaseOptions.dialectOptions.ssl = true;
+  if (process.env.DATABASE_REJECT_UNAUTHORIZED === false) {
+    databaseOptions.dialectOptions.ssl = { rejectUnauthorized: false };
+  } else {
+    databaseOptions.dialectOptions.ssl = true;
+  }

A quick note about the chosen implementation: I first created an implementation with a dialectOptions for Lumber, but after some discussion with other members of the team, we finally decided to implement a fix for this need only (the main argument is that we do not need to develop something heavy for problems that are not identified yet).

TL;DR: Issue fixed, update to latest Lumber version.

Thank you for your patience 🙏 Let me know if you have any issue, I would be glad to help you!

@snwfdhmp
Copy link

@rap2hpoutre thanks a lot !

@bmewj
Copy link

bmewj commented Sep 23, 2020

Hey, the fix doesn't work.

The environment variable DATABASE_REJECT_UNAUTHORIZED doesn't automatically get parsed and converted to a boolean, so === false doesn't work.

@rap2hpoutre
Copy link
Contributor

@bartjoyce Whoops. Thank you for spotting this, and sorry for the mess. A new PR is on its way!

@rap2hpoutre
Copy link
Contributor

@bartjoyce It has just been fixed thanks to your comment!

Could you try again with the latest version of lumber? (v3.7.2)


If you want to fix your actual project without re-running the install command, add this line to your .env file:

DATABASE_REJECT_UNAUTHORIZED=false

Then edit models/index.js (here):

-  databaseOptions.dialectOptions.ssl = true;
+ const rejectUnauthorized = process.env.DATABASE_REJECT_UNAUTHORIZED;
+ if (rejectUnauthorized && (JSON.parse(rejectUnauthorized.toLowerCase()) === false)) {
+   databaseOptions.dialectOptions.ssl = { rejectUnauthorized: false };
+ } else {
+   databaseOptions.dialectOptions.ssl = true;
+ }

Let me know if it fixed your issue 🙏

@rap2hpoutre
Copy link
Contributor

Feel free to re-open if you still have any issues.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants