<p>I am using terraform to set up a simple application that has a postgres db via Cloud SQL in google cloud platform (GCP). I set up a GCP Cloud SQL Auth proxy for my postgresql db using <a href="https://github.com/GoogleCloudPlatform/cloud-sql-proxy" rel="nofollow noreferrer">this guide</a>. I set up the proxy as a sidecar to my main kubernetes application. I also set up a GCP service account to be used for authentication in the cloud proxy. In other words, I set the <code>service_account_name</code> in the <code>kubernetes_deployment</code> resource in my terraform file to be a gcp service account with the necessary roles to connect to the database.</p>
<p>Now, I'd like to use python and sql alchemy to connect to this postgresql db through the Cloud SQL proxy. Everything I found online (like <a href="https://cloud.google.com/sql/docs/mysql/connect-admin-proxy" rel="nofollow noreferrer">this documentation</a>) suggest that I need to add a username and password like this to connect to the cloud proxy: <code>mysql+pymysql://&lt;db_user&gt;:&lt;db_pass&gt;@&lt;db_host&gt;:&lt;db_port&gt;/&lt;db_name&gt;</code>. However, my google service account doesn't have a username and password.</p>
<p>My question: is there a way to connect to the google cloud auth proxy without a password using my gcp service account?</p>

kamykam
<p>The Cloud SQL Python Connector is a Python package that makes connecting to Cloud SQL both easy and secure for all three supported database engines (Postgres, MySQL, and SQL Server), from anywhere (local machine, Cloud Run, App Engine, Cloud Functions, etc.). <a href="https://cloud.google.com/blog/topics/developers-practitioners/how-connect-cloud-sql-using-python-easy-way" rel="nofollow noreferrer">(source: gcp blogs)</a></p>
<p>This connector uses IAM permissions and TLS certificates for getting connected to the cloud sql instances. This <a href="https://github.com/GoogleCloudPlatform/cloud-sql-python-connector" rel="nofollow noreferrer">source code</a> is available in github and there are versions available for java and go languages as well.</p>
