How to connect via SSL to sequelize DB

node.js, sequelize.js

Solution

As you don't mention the backend DB of choice, I'll give a `mysql` sample and how I'd suggest you go about it.

First, confirm the connection using the `dialect` directly, so for `mysql2` supplying variables as necessary:

const connection = mysql.createConnection({
  host: dbVars.host,
  user: dbVars.user,
  database: dbVars.database,
  password: dbVars.password,
  ssl: {
    key: cKey,
    cert: cCert,
    ca: cCA
  }
});

Once that connection is confirmed, move it to Sequelize as:

const sequelize = new Sequelize(dbVars.database, dbVars.user, dbVars.password, {
  host: dbVars.host,
  dialect: 'mysql',
  dialectOptions: {
    ssl: {
      key: cKey,
      cert: cCert,
      ca: cCA
    }
  }
});

Note: loading the certs properly was a learning curve and required a direct `import` using a `raw-loader`. Example:

import cKey from 'raw-loader!../certs/client-key.pem'; 

Problem

I can't seem to find any documentation for SEQUELIZE.JS on how to use a CA.crt in order to enable connection to my database sitting on a remote server. I figure its something in the options but I can't seem to figure it out I have tried ``` { 'ssl': true 'dialectOptions':{ ssl: { ca: 'path/to/ca' } } } ``` and a few other things but nothing seem to work for me. Can anybody help me? Edit: Here is an error i get when using the ca thing ``` error connecting to db { Error: unable to verify the first certificate at TLSSocket.<anonymous> ```

Original source

Related problems