How to Configure Cloud SQL IAM Authentication

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up cloud sql iam authentication, you link cloud identities to database users. You then let your cloud provider check short-lived login tokens instead of static passwords. Many engineering teams start with one shared admin login for all developers. This shared login creates big audit blind spots and raises the risk of data loss. When every developer shares the same broad database role, you cannot trace who ran a bad query. How cloud sql iam authentication works in practice In a standard

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

To set up cloud sql iam authentication, you link cloud identities to database users. You then let your cloud provider check short-lived login tokens instead of static passwords. Many engineering teams start with one shared admin login for all developers. This shared login creates big audit blind spots and raises the risk of data loss. When every developer shares the same broad database role, you cannot trace who ran a bad query.

How cloud sql iam authentication works in practice

In a standard database setup, the database engine checks a stored password hash at login. With cloud sql iam authentication, the database delegates that identity check to the cloud provider. You first enable the feature on your database instance and grant the user login rights. Next, you create a database user account that matches the user or service identity. When a person or app tries to log in, they ask the cloud API for a token. That token acts as a temporary password during the database login step.

Once the user logs in, the database engine still controls what tables they can read or write. In Cloud SQL for PostgreSQL, customers do not get a true superuser account. A system user managed by Google holds the actual superuser rights on the instance. Customers cannot change or delete these built-in system roles. Instead, you use a special admin role that grants most high-level rights. The default postgres admin user belongs to this role and can create databases and other roles. Still, this default user starts without a password and lacks full superuser or replication attributes. You must assign clear database permissions to each mapped identity after you set up the login flow.

What native identity setup solves and what it misses

Moving away from static passwords fixes several major security headaches for operations teams. You no longer need to rotate shared database passwords or store secrets in plain text files. When an engineer leaves the company, you revoke their central cloud account right away. That single change blocks their database login without touching the database instance itself. It also stops developers from sharing one master password across local machines and test apps.

Still, native identity setup only decides who can open a database session. Once the session starts, the cloud login check is over. The database then relies entirely on internal table grants to govern every single query. If a user gets the high-level admin role to run migrations, they keep those broad rights all day. Native login tools cannot inspect individual SQL statements in flight or block a sudden table drop. They also cannot mask sensitive fields like emails, phone numbers, card numbers, or national IDs in query results. If a developer queries a production user table, the database returns raw data to their screen. To protect production data during live sessions, teams need controls that operate at the query level.

Service-to-Service Authentication + Cloud Functions IAM: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Planning database roles for engineers and apps

A good setup splits human users from automated app accounts. Apps should use dedicated service identities with narrow table permissions for their specific tasks. Human engineers should not use the default admin account for daily debugging work. Instead, group engineers by their job needs and grant read-only roles where possible. Keep the main admin role locked down for rare schema changes or extension setups. Even with clean role groups, someone will eventually need temporary write rights to fix a live bug. Planning how you review and control those active write sessions is key to safe database operations.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits inline in the protocol beside the service as an open-source proxy, a sidecar for your database or API. On every production query an agent or human runs, hoop.dev decides whether to pass, mask, block, or escalate it for review.

Before a query runs, hoop.dev guardrails check the statement against your rules, an AI Analyzer you configure can score intent or hold risky calls for human approval, and hoop.dev data masking rewrites sensitive fields in responses in memory. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Does Cloud SQL for PostgreSQL give you a true superuser account?

No, because it is a managed service, only a Google system user holds true superuser rights. Customers use a special Cloud SQL admin role that provides select high-level privileges like creating extensions and event triggers.

How does the default postgres user work in Cloud SQL?

The default postgres user belongs to the managed admin role and can log in, create roles, and create databases. It is created without a password, so you must set one before you log in with it.

Does cloud sql iam authentication replace PostgreSQL table permissions?

No, it only verifies the identity of the user when they first log in to the instance. You still must grant standard PostgreSQL role and table permissions inside the database to control data reads and writes.

The query runs. The emails stay hidden.