Nodejs connect to Redshift using temporal credentials error - node.js

I'd like to connect to Redshift using temporal credentials.
I'd tried connecting with master username and password and it works fine. The problem of the temporal credentials is the username that is following format:
username: 'IAM:awsuser'.
So I think the connection is not understanding correctly the ":". So it always through invalid password. I have try this username and password from the Redshift query-editor and it connects without any problem.
This is the configuration I'm using:
const configRed = {
host: 'redshift-cluster-name.aaaaaaa.eu-west-1.redshift.amazonaws.com',
user: 'IAM:awsuser',
password: data.DbPassword,
database: 'dev',
port: 5439,
idleTimeoutMillis: 0,
max: 10000
};
redshiftPool = new psql.Pool(configRed);
redshiftCon = await redshiftPool.connect();
I have also tried using the username with encodeURIComponent:
user: encodeURIComponent('IAM:awsuser'),
It through next error:
"errorMessage": "password authentication failed for user \"IAM:awsuser\"",
Could be possible to change the connection URL in the PG library, for some custom URL like:
jdbc:redshift:iam://examplecluster.abc123xyz789.us-west-2.redshift.amazonaws.com:5439/dev

Specifying "ssl: true" in the params argument when creating the Pool object indeed works:
const configRed = {
host: 'redshift-cluster-name.aaaaaaa.eu-west-1.redshift.amazonaws.com',
user: 'IAM:awsuser',
password: data.DbPassword,
database: 'dev',
port: 5439,
idleTimeoutMillis: 0,
max: 10000,
ssl: true
};

Related

Nodejs Postgress Error no pg_hba.conf entry for host

I'm creating a new pool object a follows:
import { Pool, PoolConfig } from "pg";
const options = {
host: process.env.DB_HOST,
port: Number.parseInt(process.env.DB_PORT as any),
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
connectionLimit: Number.parseInt(process.env.DB_CONNECTION_LIMIT as any),
ssl: false,
} as PoolConfig;
export const pool = new Pool(options);
But when i try to do pool.query I'm getting the following error:
"There was an error processing your request: no pg_hba.conf entry for host \"172.31.0.1\", user \"admin\", database \"todos\", no encryption"
I've also tried to set the ssl to true but it seems not working.
What maybe posibly the problem here

Nodejs mssql server connection throws an error

I want to connect my mssql database from nodejs.
I am using sequelize and tedious module for this.
My connection configs like this
const sequelize = new Sequelize(
"mydb",
"username", "password", {
host:config_data.host,
"dialect":"mssql",
"port":1433
dialectOptions: {
instanceName: "MSSQLSERVER"
},
},
);
When I tried to run script, it throws an error.
(node:14584) UnhandledPromiseRejectionWarning: SequelizeConnectionError: Failed to connect to 192.168.10.220:1433 - Could not connect (sequence)
I apply all steps in configuration manager.
Enabled TCP/IP
Started Server SQL browser
Added 1433 port to Firewall
There is also additional error when host is "localhost".(Currently writed IP address)
(node:13552) UnhandledPromiseRejectionWarning: SequelizeConnectionError: Failed to connect to localhost:1433
- 4292:error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol:c:\ws\deps\openssl\openssl\ssl\statem\statem_lib.c:1947:
I need to help, is there someone have any idea ?
You need to set encrypt to false in your Sequelize inside options.
const sequelize = new Sequelize(
"mydb",
"username", "password", {
host:config_data.host,
"dialect":"mssql",
"port":1433,
"options": {
encrypt: false,
enableArithAbort: false
},
dialectOptions: {
instanceName: "MSSQLSERVER"
},
},
);
The issue is because of TLS protocol mismatch between Source & Destination server. In my case my App server was Ubuntu 20.04 & my SQL Server(Express 2012) was on Windows server. I also tried to downgrade TLS protocols on Ubuntu but nothing worked. So finally I disabled tls encryption in Sequelize.
Make sure options are given as expected by Sequelize
const sequelize = new Sequelize(dbConfig.DB, dbConfig.USER, dbConfig.PASSWORD, {
host: dbConfig.HOST,
port: dbConfig.PORT,
dialect: dbConfig.dialect,
pool: {
max: dbConfig.pool.max,
min: dbConfig.pool.min,
acquire: dbConfig.pool.acquire,
idle: dbConfig.pool.idle,
},
// The below options are important to supress ssl issue on
// AWS EC2 ubuntu when db server is on windows. There is TLS protocol issue
// Which by using these options we disable tls encryption
dialectOptions: {
// Observe the need for this nested `options` field for MSSQL
options: {
encrypt: false,
enableArithAbort: false
}
}
});

JS postgres - wrong username connection

So im trying to connect my local postgres DB to my node.js server.
But im facing the ennoying issue of wrong username.
error: password authentication failed for user "Yoav Genish"
error log:
name: 'error',
length: 169,
severity: 'FATAL',
code: '28P01',
The Yoav Genish is my win10 user name and postgres just default it as the superadmin.
I have a user with premission for the DB called me and i specified it in a .env file.
Here's the .env file:
HOST='localhost'
USER = 'me'
DATABASE= 'api'
PASSWORD= 'password'
PORT=5432 '
and here's the code:
require('dotenv').config();
const Pool= require('pg').Pool;
const ENVDATA = {
HOST: process.env.HOST,
USER: process.env.USER,
DATABSE: process.env.DATABASE,
PORT: process.env.PORT,
PASSWORD: process.env.PASSWORD
}
var pool = new Pool(ENVDATA);
Also i verified the the ENVDATA is indeed the data in the .env file.
again, the issue is that i want to log into the local DB with the me username, but i keep getting the above error.
thanks in advance!
It appears to be a syntax problem. One should use Lower Case properties when passing data to the Pool meaning
const ENVDATA = {
host : process.env.HOST,
user: process.env.USER,
.
.
.
But i found an even "clener" solution and it's using the URI String instead:
const PGURI = `postgres://${process.env.USER}:${process.env.PASSWORD}#$
{process.env.HOST}:${process.env.PORT}/${process.env.DATABASE}`;
var pool = new Pool({
connectionString: PGURI
});

Mongo authentication fail or invalid connection string

Using "mongoose": "^5.4.21", and Mongo Atlas, I can not seem to connect to my database in my node.js application
I tried to encode my connection string but that gives me Invalid connection string, if I remove encodeURIComponent I get authentication failed
mongoose.connect(encodeURIComponent("mongodb+srv://name:}Izu#[{!6o#cluster-oxzyp.mongodb.net/"), { dbName: "website", useNewUrlParser: true });
You can separate the username and password part of the connecting URI into the options section as shown below:
mongoose.connect("mongodb+srv://cluster-oxzyp.mongodb.net", {
user: 'name', //assuming this is your username
pass: '}Izu#[{!6o', //assuming this is your password
dbName: "website",
useNewUrlParser: true
});
This is probably happening due to the presence of # character in your password. Or you can try doing it like below:
mongoose.connect(`mongodb+srv://name:${encodeURIComponent('}Izu#[{!6o')}#cluster-oxzyp.mongodb.net/`, {
user: '',
pass: '',
dbName: 'website',
useNewUrlParser: true });

Unhandled rejection SequelizeConnectionError: password authentication failed for user "ankitj"

This happens even when the DB user specified in .env file is different. For the record "ankitj" is also the username of my system. I don't understand why this is happening.
Here's the error:
Unhandled rejection SequelizeConnectionError: password authentication failed for user "ankitj"
at connection.connect.err (/home/ankitj/Desktop/skillbee/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:128:24)
at Connection.connectingErrorHandler (/home/ankitj/Desktop/skillbee/node_modules/pg/lib/client.js:140:14)
at Connection.emit (events.js:160:13)
at Socket.<anonymous> (/home/ankitj/Desktop/skillbee/node_modules/pg/lib/connection.js:124:12)
at Socket.emit (events.js:160:13)
at addChunk (_stream_readable.js:269:12)
at readableAddChunk (_stream_readable.js:256:11)
at Socket.Readable.push (_stream_readable.js:213:10)
at TCP.onread (net.js:599:20)
I'm assuming that you're getting this error using Sequelize with Node.js. I ran into the same error when I had the following:
const sequelize = new Sequelize(
process.env.DATABASE,
process.env.DATABASE_USER,
process.env.DATABASE_PASSWORD,
{
dialect: 'postgres',
}
)
I was able to solve the issue by replacing it with a connection ur:
const sequelize = new Sequelize("postgres://postgres:postgres#localhost/gql", {
dialect: 'postgres'
// anything else you want to pass
})
where gql is the name of DATABASE in my .env file.
The user "ankitj" executes the command to run the Node script, so the script is trying to connect as that user. I first tried to solve this on the Postgres end by adding a user and granting permissions, but was unable to get that to work--I'd be interested in seeing that solution--but specifying a connection url worked for me.
I had the same issue when I was using the default password for the PostgreSQL. Try to change it from the command line as follows.
psql
\password
Then Enter a new password and update your .env files and that should Work.
Instead of using the process.env variables I put the actual names but wrapped in quotes (" ") and it's worked.
I have faced the same issue when I connect with NodeJS and Postgres SQL. I found a solution. We need to check db.config.js file(database config file) and index.js(where u called the const sequelize = new Sequelize(.......) properties name is matching or not.
// db.config.js
module.exports = {
user: '******',
host: 'localhost',
database: '***********',
password: '***',
port: 5432,
dialect: "postgres", // we need to implement
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
}
};
const Sequelize = require("sequelize");
const dbConfig = require("../config/db.config.js");
const sequelize = new Sequelize(dbConfig.database, dbConfig.user, dbConfig.password, {
host: dbConfig.host,
dialect: dbConfig.dialect,
operatorsAliases: false,
pool: {
max: dbConfig.pool.max,
min: dbConfig.pool.min,
acquire: dbConfig.pool.acquire,
idle: dbConfig.pool.idle
},
})
Mentioned the above params line as (dbConfig.database, dbConfig.user, dbConfig.password) we need to check with db.config.js file
Note: please add dialect properties on the db.config.js file.
Now Problem is solved...Thanks
Console verbiage log
I also had the same error but I solved it by using template strings
const sequelize = new Sequelize(`${process.env.DB_NAME}`, `${process.env.DB_USER}`, `${process.env.DB_PASSWORD}`, {
host: process.env.DB_HOST,
dialect: 'postgres'
});

Resources