Enable IAM database authentication on Cloud SQL for PostgreSQL, create an IAM database user, and connect with the Cloud SQL Auth Proxy or the Go connector, without putting a database password in the application.

Cloud SQL IAM database authentication lets a Google identity log in to PostgreSQL with a short-lived token instead of a password stored in the application or in a secret file.
The setup has two layers that are easy to mix up: IAM roles that allow the principal to connect to the instance, and ordinary GRANT statements inside PostgreSQL that allow that database user to read or write tables.
This guide enables the flag, creates an IAM user, and connects with the Auth Proxy and the Go connector. Encore provisions Cloud SQL in your project; it does not claim that its own runtime connections use IAM database authentication.
On a PostgreSQL instance, enable IAM database authentication (the cloudsql.iam_authentication flag). Then add a database user of type IAM, using the IAM email for a user account or the service account address, as described in creating an IAM user. Grant that principal roles/cloudsql.instanceUser and, for the proxy or connector, roles/cloudsql.client.
Inside PostgreSQL, the user exists but starts with no rights on your tables. Connect as a built-in user and GRANT the privileges the app needs. Login names for IAM users follow Cloud SQL's naming rules; if the address is truncated in the database, use the name Cloud SQL shows in the Users list.
The Cloud SQL Auth Proxy and the Cloud SQL Go connector can request an IAM database token and refresh it. A typical local proxy command, after Application Default Credentials are set, looks like this:
sslmode=disable on the local psql connection is normal when the proxy is already terminating TLS to Cloud SQL. Do not use that on a direct public-IP connection. The Go connector IAM example passes an IAM option to the dialer so each new connection gets a fresh token, which is required because tokens expire in about an hour.
IAM database authentication replaces a long-lived database password in the app, and it does not replace network path controls: the instance should still sit on a private IP, and Cloud Run or GKE should reach it with a connector or Direct VPC egress.
Best fit: services and operators that already use Google identities and want database logins to follow those identities.
Encore provisions Cloud SQL for databases declared with sqldb.NewDatabase when you deploy to your GCP account, as the GCP infrastructure docs describe. encore run starts Postgres locally, and Encore provisions an IAM role for the service, or a service account on GCP, for cloud permissions. Use encore db shell, encore db proxy or encore db conn-uri to reach a deployed instance from your machine.
Encore does not document that those runtime connections use Cloud SQL IAM database authentication. If you add a sidecar or a human operator that connects to the same instance with IAM DB auth, that is your client configuration, next to the instance Encore provisioned.
A coding agent working in the repository changes schema and queries against the declared database, not an IAM database user you created by hand.
Best fit: applications that want Cloud SQL provisioned from code, with IAM database authentication reserved for operators or clients you configure explicitly.
Use IAM database authentication when you want Google principals to log in without a stored database password and you are prepared to grant both IAM roles and PostgreSQL privileges. Use a built-in database user and a secret when that is the path your platform already injects. Use Encore when you want the instance declared in application code, and keep IAM DB auth as a separate, documented choice for the clients you control.
Enable IAM database authentication on the instance, create a database user whose name matches the IAM principal, grant that user privileges inside PostgreSQL, and connect through the Cloud SQL Auth Proxy or a language connector with IAM authentication turned on. The client obtains a short-lived token, so you do not store a database password in the app.
The principal typically needs roles/cloudsql.instanceUser to log in with IAM, and roles/cloudsql.client to connect through the proxy or connector, plus any project-level conditions your organization requires. Grant the database privileges separately with GRANT in PostgreSQL.
The token is short-lived, on the order of one hour, which is why the Auth Proxy and official connectors refresh it for you. A client that copies a token once and reuses it for days will eventually fail to authenticate.
Encore provisions Cloud SQL in your GCP account and Encore provisions an IAM role for the service, or a service account on GCP, for the service's cloud permissions. It does not document that application connections use IAM database authentication. Use encore db shell, encore db proxy or encore db conn-uri to reach the instance, and treat IAM DB auth as a technique for clients you configure yourself.
Deploy to your cloud on AWS and Google Cloud
without managing infrastructure
Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.