Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to CloudSQL from local nodejs program without whitelisting the IP but rather using local credentials

I want to connect to my GCP Cloud SQL postgres DB from my local nodejs program.

Currently the way i am able to do it is make the DB instance public facing behind authentication and Add my IP address to the Allowed network section.

This seems cumbersome because if i use a VPN or switch to different network those IPs will not be able to access the instance.

So rather i would prefer if node application is able to use my google credentials file stored in my local and understand i have access to the CloudSQL instance.

For other google services i tend to use google auth library but i am not able to find any google recommended way to using an SDK which does this authentication and allows my connection.

How should i use my credentials and get access to the CloudSQL from my local machine then?

Tried reading around the documentation. They explain all Apps in the respective projects have access to the CloudSQL. But don't talk about user account access, or any SDK specific to nodeJS

like image 928
AnandShiva Avatar asked Nov 14 '25 21:11

AnandShiva


1 Answers

Our recommendation is to use the Cloud SQL Node Connector (just recently release to Public Preview): https://github.com/GoogleCloudPlatform/cloud-sql-nodejs-connector.

We're working on putting this into the documentation, but for now the README on GitHub above should have all the details. Feel free to file issues if something isn't clear.

like image 106
enocom Avatar answered Nov 17 '25 21:11

enocom