How do I connect to postgres through a proxy in node.js

104 Views Asked by At

TL; DR: my node app is deployed to heroku, which uses dynamic IPs. I want to proxy all Postgres requests through a static IP. How can I add a proxy to the node pg library? There don't seem to be any resources online for this.

Longer version:

I'm using Amazon RDS Postgres database, and deploying my node.js backend to Heroku.

Up until now, I've been able to just whitelist my development IP addresses in the RDS security settings, to prevent random hackers from hitting my database and trying to guess my password.

However, I'm deploying to heroku, and they don't use fixed IPs. They have a whole bunch of IPs which are switched in and out, so there's no way to know which IP my backend will be running on, ahead of time.

As such, I have determined the best way for me to connect to RDS is through a static IP proxy. My plan is

Heroku node.js app --> Proxy (static, known IP) --> RDS.

However, I'm not sure how to open a Postgres connection using a proxy!

I've done a lot of googling, and people here and there seem to suggest using SOCKS. However, none of the things I've found work for me.

So, my question is:

  1. Does anyone have an example of how I can connect to my Postgres database, using the node pg library, through a proxy?
  2. If not, is there a simpler way to securely configure RDS? Should I allow access from any IP, and just upload a special key to my server or something?

Please advise on best practices... thank you!

0

There are 0 best solutions below