Skip to content

PostgreSQL URI connection strict ?sslmode=require should enable dialectOptions.ssl=true #10015

Closed

Description

@ceefour

What are you doing?

"use_env_variable": "POSTGRESQL_URI" in config.json

The POSTGRESQL_URI contains ?sslmode=require as described in official libpq: https://www.postgresql.org/docs/9.3/static/libpq-ssl.html

(alternative to require: verify-ca and verify-full)

What do you expect to happen?

sequelize connects via SSL, i.e. implicitly sets dialectOptions.ssl=true

What is actually happening?

sequelize connects regularly.

Workaround is to set dialectOptions.ssl=true manually, however correct behavior is that this can be set from env variable.

Note: This is related to previous issues #9712, #6932, #5891,

Dialect: postgresql
Dialect version: 7.5.0
Database version: 10
Sequelize version: 4.39.0
Tested with latest release: Yes, 4.39.0

Activity

  1. added
    type: feature
    on Oct 11, 2018
  2. justinkalland commented on Oct 11, 2018

    @justinkalland
    Contributor

    It appears that with the node-postgres module you can't use sslmode=mode. However you can use ssl=true and that defaults to sslmode=require (found a note on that in the docs).

    It is also possible with the node-postgress module to pass an object for ssl (code).

    I will submit a pull request that adds support for ?ssl=true to the URI for Postgres. If needed I can add support for sslmode sslca sslkey sslcert sslrootcert but I suspect it unnecessary.

  3. ceefour commented on Oct 12, 2018

    @ceefour
    Author

    @justinkalland this is really great!

  4. dnuske commented on Sep 21, 2022

    @dnuske

    this solution worked for me:

    const Sequelize = require('sequelize');
    
    const sequelize = new Sequelize({
        database: process.env.POSTGRES_DB,
        username: process.env.POSTGRES_USER,
        password: process.env.POSTGRES_PASSWORD,
        host: process.env.POSTGRES_HOST,
        port: process.env.POSTGRES_PORT,
        dialect: "postgres",
        dialectOptions: {
            ssl: {
                require: true,
                rejectUnauthorized: false
            }
         },
    });
    

    credit to https://catalins.tech/nodejs-postgresql-heroku-error-no-pghbaconf-entry-for-host-ssl-off#bonus-sequelize-solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions