Search code examples
postgresqlgoogle-cloud-platformgoogle-cloud-sqlgoogle-cloud-iamcloud-sql-proxy

Connecting to Cloud SQL from Azure Data Studio using an IAM user


Following the instructions here, I'm having problem connecting to the DB from Azure Data Studio using the token I generate. It connects to the DB successfully, but as soon as I want to run a simple query ( I already gave my user read access there), it gives me this connection error, and I need to connect using the token again and the disconnection happens again randomly after a short while:

FATAL: Cloud SQL IAM user authentication failed for user "[email protected]" FATAL: pg_hba.conf rejects connection for host "...", user "[email protected]", database "db-name", SSL off

I did some search and found there is also a way of logging in with IAM database authentication using the Cloud SQL Auth proxy but the documentation is limited to Postgress command line and not a GUI database tool like Azure Data Studio. Can anyone shed some light on this about what's needed if you want to connect with a GUI tool in this case?

And about changing the pg_hba.conf file, since I work with a cloud SQL instance, I'm not sure how to turn sslmode off on the cloud instance. I checked the connection tab of my instance and SSL encryption wasn't checked there (not sure if that's the same),and I changed the sslmode to disable on my Azure Data Studio for the connection but it won't allow me to connect after this change:

FATAL: pg_hba.conf rejects connection for host "*.*.*.*", user "[email protected]", database "database", SSL off

Help, anyone?


Solution

  • I've found the answer: we can connect using IAM database authentication using the Cloud SQL Auth proxy. The only step after to be done from the GUI DB tool (mine is Azure Data Studio) would be, to connect to the IP (127.0.0.1 in my case)the Cloud SQL Auth proxy listens on(127.0.0.1 is the default) after starting the Cloud SQL Auth proxy using:

    ./cloud_sql_proxy -instances=<GCPproject:Region:DBname>=tcp:127.0.0.1:5432