getting SSL error on GeddyJs using Heroku PG on dev environment - node.js

i am using GeddyJs with a heroku cedar app deployment. I am using Heroku Postgres services for the database.
I have configured the username/password/hostname/dbname in the config file on geddyjs but when i go to run node app.js it throws an error for no pg_hba.conf i know this related to SSL not being used while accessing the db remotely but i have no clue how to force SSL on the connection..
Here is the error log:
error: no pg_hba.conf entry for host "70.199.196.17", user "12345", database "database1", SSL off
at p.parseE (/Users/mikedevita/Web/Sites/gorelative.com/node/node_modules/pg/lib/connection.js:503:11)
at p.parseMessage (/Users/mikedevita/Web/Sites/gorelative.com/node/node_modules/pg/lib/connection.js:363:17)
at Socket.p.attachListeners (/Users/mikedevita/Web/Sites/gorelative.com/node/node_modules/pg/lib/connection.js:86:20)
at Socket.EventEmitter.emit (events.js:96:17)
at TCP.onread (net.js:397:14)
[Tue, 05 Mar 2013 22:39:49 GMT] ERROR Worker 843 died.
my config/development.js file:
var config = {
detailedErrors: true
, debug: true
, hostname: 'localhost'
, port: 3000
, model: {
defaultAdapter: 'postgres'
}
, db: {
postgres: {
port: 5432
, password: 'foobar'
, database: 'database1'
, host: 'ec2-107-21-126-45.compute-1.amazonaws.com'
, user: '12345'
}
}
, sessions: {
store: 'memory'
, key: 'sid'
, expiry: 14 * 24 * 60 * 60
}
};
module.exports = config;

You need to add ssl: true to your postgres config.
postgres: {
port: 5432
, password: 'foobar'
, database: 'database1'
, host: 'ec2-107-21-126-45.compute-1.amazonaws.com'
, user: '12345'
, ssl: true
}
Geddy simply passes this config object to the pg module. Check the pg.client wiki page for more info.

If you are trying to connect from outside heroku you need to connect with SSL. We only allow connections from outside heroku if they are encrypted with SSL
error: no pg_hba.conf entry for host "70.199.196.17", user "12345", database "database1", SSL off says that you can't connect with SSL off.
Also you may be sanitizing your database name with database1, but if you're not, I can guarantee you that your database name is not, in fact, database1.
Also you should NOT NOT NOT be hard-coding your credentials in a file. Read them out of your environment.

Related

Can't connect to Heroku postgres DB using Sequelize / NodeJS as missing sslmode tag

I'm playing with Heroku / DigitalOcean ("DO") App hosting services, trying to simply connect my NodeJS app to a Heroku/DO database. These services populate my environment variables with the following:
DATABASE_URL="postgresql://username:password#url:ip/dbname?sslmode=require"
Unfortunately, when I'm running Sequelize, I get the following error message:
ConnectionError [SequelizeConnectionError]: no pg_hba.conf entry for host "[my ip address]", user "[db user]", database "[db name]", SSL off
I think the connection string might be misconfigured as I can clearly see it's trying to connect over ssl.
$ node -v
v15.9.0
Hi i share my connection with Digital Ocean DB PostgreSQL cluster
production: {
host: process.env.DB_HOST,
port: process.env.DB_PORT,
database: process.env.DB_DATABASE,
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
dialect: 'postgres',
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: false
}
}
}

How to connect to postgresql database inside AWS EC2 instance using Node.js and Knex

I rented an EC2 instance of Ubuntu 16.xx on AWS and installed PostgreSQL on it. I created a database and table inside the PostgreSQL on EC2. Right now I am trying to connect to and get data from the database via a local Node.js project using knex.
I already enabled the inbound rule for port 5432 to IP from anywhere.
However, it returns error message as below:
Error: connect ECONNREFUSED 13.229.xxx.xxx:5432
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1142:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '13.229.xxx.xxx',
port: 5432
}
How am I gonna fix it? Do I need to install and implement a reversed proxy? If so, how do I set it up? I know there is RDS on AWS, but I need to use EC2 to implement it.
Here are some of my codes:
This is the knex setting, I have pg installed. The connection to a local database is successful. But when I switch the host to whether a public IP/ private IP/ ec2-13-229-xxx-xxx.ap-southeast-1.compute.amazonaws.com. They all return the above error message.
development: {
client: 'postgresql',
connection: {
host: '13.229.xxx.xxx',
database: 'project2',
user: 'postgres',
password: 'postgres',
port: 5432,
},
pool: {
min: 2,
max: 10,
},
migrations: {
tableName: 'knex_migrations',
},
},
This is the Node.js code that I used to connect to the server. A very simple one, just to test the connection.
const express = require('express');
const hbs = require('hbs');
const app = express();
const knexConfig = require('./knexfile')['development'];
const knex = require('knex')(knexConfig);
let query = knex.select('*').from('users');
query
.then((data) => {
console.log(data);
})
.catch((err) => console.log(err));
This is my firewall setting which is turned off
Also, I paused my Kaspersky.
This is my pg_hba.conf file
And I am not sure where to add the permission of my personal IP.
This issue was related to the pg_hba.conf being restricted to localhost only.
Additionally the postgres.conf needed to have listen_addresses = '*'.
By whitelisting outside access, it was possible to access the database.
Additional support from this article.

How to connect to postgres in aws server with pem file?

I want to connect to postgres in Aws server. I have installed "pg" to node.
I have tried to use the connection String, but there is no way to add private key there. So I also try with
const pool = new Pool({
user: 'dbuser',
host: 'database.server.com',
database: 'mydb',
password: 'secretpassword',
port: 3211,
privateKey : require('fs').readFileSync('./ssh_keys/my_key')
})
In both cases I get connection refused.

Node : Connecting remote database to node server

I have node server on which i used mysql module as shown below
const db = mysql.createConnection({
host:'localhost',
user: 'root',
password: '',
database: 'test'
});
db.connect(function(err){
if (err) console.log('Errors', err)
console.log('connenected');
})
when i replace ip address of remote database or ip address of my local machine on which xammp is running instead of localhost it fails somehow i tried to find out solution some says i need to use port in connection but it fails. Thanks in advance
Step1: Allow database to connect remote IP by given this SQL.
GRANT ALL PRIVILEGES ON *.* TO 'root'#'ipaddressofyourpc' IDENTIFIED BY 'password' WITH GRANT OPTION;
Step2: Flush the PRIVILEGES
FLUSH PRIVILEGES;
Step3:
var mysql = require('mysql');
var connection = mysql.createPool({
connectionLimit: 100,
host:'ipaddressofremotedb',
user:'usernameofdb',
password:'password',
database:'dbname',
port: 3306,
debug: false,
multipleStatements: true
});

Heroku postgres database not connecting

I'm playing around on Heroku and trying to link to a postgres DB. My app is linked directly to the github source code. When I run it locally with the Heroku DB credentials and with npm start it works, but not when it is deployed, I've got this error:
{"name":"SequelizeConnectionError","message":"password authentication failed for user \"riunhwzbjuwwgw\"","parent":
{"name":"error","length":103,"severity":"FATAL","code":"28P01","file":"auth.c","line":"285","routine":"auth_failed"},"original":
{"name":"error","length":103,"severity":"FATAL","code":"28P01","file":"auth.c","line":"285","routine":"auth_failed"}}
Any ideas at all?
Edit : here's the connection
var sequelize = new Sequelize(config.db.dbName, config.db.username, config.db.password, {
host: config.db.host,
dialect: config.db.dialect,
port: config.db.port,
dialectOptions: {
ssl: true
},
logging : false
});
and my variables
db: {
dbName: process.env.DBNAME,
username : process.env.DBUSER,
password : process.env.DBPASSWORD,
host : process.env.DBHOST,
dialect: "postgres",
port : 5432
}
Like I said, it works locally. The password is set like the DBUSER riunhwzbjuwwgw, could it be something those slashes? \"riunhwzbjuwwgw\"

Resources