While Fly is working on the PITR functionality, we would like to host our database on the GCP, and I consider that connecting it with our app through a VPN tunnel offers better security than firewall rules.
My biggest concern is that the app should be started after the tunnel is brought up, or it will crash otherwise.
So I assume that tunnel has to be permanent somehow.
It creates the authenticated, encrypted connection to your SQL instance without having to do all the plumbing yourself.
You could run this is its own container/app or in a side-car way by adding the process to your app (probably better). Then use secrets to inject the service account credentials into the app so the proxy can use them to connect.
Thanks! I quickly glanced through the documentation, which requires a companion server-side setup.
It means a necessity of setting up an HA cluster for it on top of the HA PostgreSQL cluster
Hmm, where did you see/read that?
From my experience there’s no such setup needed. I use the cloudsql proxy with a single postgres instance, smallest size, no HA config or server-side setup required.
The Cloud SQL Auth proxy uses a secure tunnel to communicate with its companion process running on the server. Each connection established through the Cloud SQL Auth proxy creates one connection to the Cloud SQL instance.
Ah, I see. This is a bit misleading, all you need to run is the cloudsql proxy, the rest (proxy server, etc) GCP handles for you.
I’d recommend reading the rest of the doc, towards the bottom is a section Requirements for using the Cloud SQL Auth proxy, it has a pretty short list of what you need, it’s really straightforward to setup.
You can do this, the most reliable setup is to run wireguard servers within GCP and then make each Fly VM a wireguard client.
However, this is not buying you much. You still need a public IP, it’s just something that Wireguard owns. Wireguard is a little more secure than doing TLS + public IP for Postgres, but that comes at a lot of extra complexity.
If this were me, I’d be inclined to just connect to Cloud SQL over TLS on a public IP. And then make sure Cloud SQL requires client certificate validation to accept a connection.
My instance has a public IP but it’s locked down with the firewall rules to block all incoming connections and it’s not used (just an artifact of how I created the instance). Even when I connect from my local machine I use the cloudSQL proxy.
Could you share where you found that information? Cause I can’t observe any such thing. When I start the proxy the connection is handled entirely by the proxy & GCP infra and the public IP of my instance is not opened up to any outside connections.
Running /usr/local/bin/cloud_sql_proxy should go into the start script, not the Dockerfile.
Is the cloud proxy really running? Anything in the logs? Hard to say what’s wrong without more information.