-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using a proxy #10973
Comments
There are a few options in the Sequelize constructor that provide some flexibility for the connection package. Have you considered |
I think it's possible using const Sequelize = require('sequelize');
const SocksConnection = require('socksjs');
const { FIXIE_VALUES } = require('./config');
const DB = {
host: process.env.DATABASE_HOST || '127.0.0.1',
port: process.env.DATABASE_PORT || 5432
};
const fixieConnection = new SocksConnection(DB, {
user: FIXIE_VALUES[0],
pass: FIXIE_VALUES[1],
host: FIXIE_VALUES[2],
port: FIXIE_VALUES[3],
});
}
const client = new Sequelize(DATABASE_URL, {
dialect: 'postgres',
ssl: true,
dialectOptions: {
ssl: {
require: true
},
stream: fixieConnection,
}
});
// client.sync() Although I am still running into a connection problem: (node:36479) UnhandledPromiseRejectionWarning: SequelizeConnectionError: connect ETIMEDOUT 167.71.XXX.XXX:XXXXX Are there examples of alternate ways to specify a connection stream directly to Postgres? |
@vitalbone Do you also get this |
Unfortunately I can't confirm because I don't have the ability to test the connection to the same static IP or remote database anymore. |
I agree it should be so much easier to actually set up a socket proxy in Sequelize... As hosting in Heroku (dynamic IP infrastructure) and needed to set up Azure firewall (MS SQL) correctly without open the database to all IP's, the only way is a proxy connection, but I can't make this work :( tried your example @vitalbone as: const { DB_HOST, DB_DATABASE, DB_USER, DB_PASS, QUOTAGUARDSTATIC_URL } = process.env;
// SETUP PROXY
const proxy = url.parse(QUOTAGUARDSTATIC_URL);
const proxyConnection = new SocksConnection({
host: DB_HOST,
port: 1433, // MS SQL port
}, {
user: proxy.auth.split(':')[0],
pass: proxy.auth.split(':')[1],
host: proxy.hostname,
port: proxy.port,
});
// SETUP CONNECTION
const sequelize = new Sequelize(DB_DATABASE, DB_USER, DB_PASS, {
host: DB_HOST,
dialect: 'mssql',
logging: process.env.APP_ENVIRONMENT === 'local' ? console.log : false,
pool: {
max: 5,
min: 0,
idle: 10000,
},
define: {
engine: 'InnoDB',
collate: 'latin1_swedish_ci',
},
dialectOptions: {
stream: proxyConnection,
options: {
encrypt: true,
requestTimeout: 300000,
},
},
}); it does not use that proxy as a connection but used my own IP Address :( |
@balexandre have you found any other workaround? I'm at the point where I would have to move off heroku to secure ips :( |
@balexandre same here. I also added a working example with
Output is always TimeoutError and I tried a lot of things. Sequelize seems to pass stream option, but couldn't resolve the issue so far.
This is working for me
Output as expected: |
@Noerdsteil No I've found no solution to this while using Heroku unfortunately. |
Related: #9780 |
|
So? Is it impossible to use sequelize with a proxy? :( |
Our database connection increased heavily after we migrated our apps to AWS Lambda. The RDS DB Proxy did not worked. |
I spent too much time on this so I hope this helps you. I need to connect my Heroku dyno to RDS DB which limits to some inbound IP addresses. I use Postgres and its client does not allow My solution is to use qgtunnel from QuotaGuard. I've tried Proximo but it does not have a working wrapper client for SOCKS5 proxy. Setup a transparent tunnel, add the wrapper to your repo & Procfile and it should work seamlessly. Free advertising for them I guess. |
@jackblk Could you provide an example of your working QuotaGuard qgtunnel? I'm still getting a timeout error with this method, and I'm not very familiar with networking so I can't tell from the documentation what I may be doing wrong. |
Has anyone found a solution to this? |
It would be nice to have proxy support for Sequelize. Using Sequelize on a host with rotating IP addresses makes it near impossible to whitelist connections to an external database. I understand that this would depend on the connection package (node-mysql, pg). These packages do offer support for this feature, but there is no way to initialize Sequelize using those stream options. For example, with the pg package:
Since we can't pass a custom pg instance into Sequelize, how would we go about making this work?
The text was updated successfully, but these errors were encountered: