Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SequelizeConnectionError: self signed certificate

I am trying to connect to a PostgreSQL Database that I've set up in Heroku.

const { Sequelize, DataTypes, Model } = require("sequelize");

// DB Configuration
const sequelize = new Sequelize({
  database: "[won't show db]",
  username: "[won't show username]",
  password: "[won't show password]",
  host: "ec2-54-221-195-148.compute-1.amazonaws.com",
  port: 5432,
  dialect: "postgres",
  dialectOptions: {
    ssl: true,
  },
});

And this is what I am getting as the output:

SequelizeConnectionError: self signed certificate

like image 263
Dmitriy Shin Avatar asked Nov 20 '19 23:11

Dmitriy Shin


3 Answers

This is due to an (accidental) breaking change in node-postgres version 8 (see this GitHub issue).

The solution is to pass rejectUnauthorized: false to the sequelize connection parameters inside of dialectOptions>ssl, as described here by GitHub user jsanta, bypassing the SSL certificate check (which is okay when connecting to a trusted server over a secure connection such as on your local host or between your own servers in the same network):

const sequelize = new Sequelize({
  database: "xxxxx",
  username: "xxxxx",
  password: "xxxxx",
  host: "xxxxx",
  port: 5432,
  dialect: "postgres",
  dialectOptions: {
    ssl: {
      require: true,
      rejectUnauthorized: false // <<<<<<< YOU NEED THIS
    }
  },
});
like image 173
CherryDT Avatar answered Nov 12 '22 14:11

CherryDT


in my case none of the above works, I use the connection string method to apply pg configurations, so I set the query param sslmode=no-verify and I got it works

example

postgres://myuser:mypassword@myhost:5432/mydatabasename?sslmode=no-verify
like image 39
Anas Avatar answered Nov 12 '22 14:11

Anas


It works for me (on sequelize config.json file):

    "dialect": "postgres",
    "dialectOptions": {
      "ssl": {
        "require": true,
        "rejectUnauthorized": false
      }
    }
like image 1
Juan Camilo Camacho Beltrán Avatar answered Nov 12 '22 15:11

Juan Camilo Camacho Beltrán