question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot run in heroku with SSL on

See original GitHub issue

I am using standard Postgres in Heroku, which has SSL on by default. Whenever I try to run the migrations, I get hit with:

[ERROR] error: no pg_hba.conf entry for host "${ip}", user "${user}", database "${database}", SSL off
    at Connection.parseE (/app/node_modules/db-migrate-pg/node_modules/pg/lib/connection.js:539:11)
    at Connection.parseMessage (/app/node_modules/db-migrate-pg/node_modules/pg/lib/connection.js:366:17)
    at Socket.<anonymous> (/app/node_modules/db-migrate-pg/node_modules/pg/lib/connection.js:105:22)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:191:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:563:20)

My migration command:

package.json:

    "migrate": "db-migrate --config migrations-config.js",
    "migrate-up": "npm run migrate up"

My migrations-config: ‘use strict’

import {postgres} from 'config'
import {parse as urlParse} from 'url'

const parsed = urlParse(postgres.connectionUrl)
const auth = parsed.auth.split(':')
const user = auth[0]
const password = auth[1]

export default {
  driver: 'pg',
  user,
  password,
  host: parsed.hostname,
  database: parsed.pathname.substring(1),
  port: parsed.port,
  schema: '${schema}',
  ssl: (process.env.NODE_ENV === 'production')
}

and my config.js entry:

export const postgres = {
  connectionUrl: process.env.DATABASE_URL
}

If I change the ssl to be explicitly true via:

ssl: true
``` in the migrations config, the result is the same.

Any suggestions on how to fix this would be amazing!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

4reactions
shtocommented, Feb 7, 2021

For others coming here at a later time, this is what helped me.

I am using a database.json file as the default configuration. Turns out Heroku already offers a default JSON config for the database, so in the particular environment you are running the app in, all you need to add is this:

    "staging": {
      "overwrite": {
        "driver": "pg",
        "ssl": {
          "rejectUnauthorized": false
        }
      }
    }

rejectUnauthorized is the key element here.

1reaction
Aleniuscommented, Feb 21, 2021

Thanks @shto, you solved my problem!

Just to be overly clear for people who are bad at reading the docs (as myself). You have to pass in the explicit env you defined in your database.json when running the migration, e.g.:

"postinstall": "yarn db:migrate:up --env staging"
Read more comments on GitHub >

github_iconTop Results From Across the Web

Heroku SSL
SSL is a cryptographic protocol that provides end-to-end encryption and integrity for all web requests. Enable SSL on apps that transmit ...
Read more >
SSL Error on Heroku app - Stack Overflow
I cannot get ssl to work properly on my heroku app. I have successfully add the crt key witch gives me: Resolving trust...
Read more >
Installing an SSL certificate on Heroku SSL - Hosting
Please keep in mind that for Heroku, it's necessary to combine the certificate and the CA Bundle into one file. You can open...
Read more >
Troubleshooting Heroku SSL errors - DNSimple Help
This server could not prove that it is www.alpha.com; its security certificate is from www.bravo.com. This may be caused by a misconfiguration or...
Read more >
How to Install an SSL Certificate on Heroku?
Via Heroku Dashboard · Open the Certificate · Select the necessary application from the list, then select Settings · Scroll down the page...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found