Configuring Cloud SQL password policies and IAM login

Published
Length
4 min read

Luis Felipe Dias

All posts

Cloud SQL password policies enforce complexity and rotation for built-in auth. IAM database authentication uses short-lived OAuth tokens instead of passwords. These controls decide who can connect. They do not check what each statement does. They do not filter what data returns. Many teams think these close the security gap for AI agents. They do not. Both features sound like security controls. They operate at different layers. Password policies govern credential strength and lifecycle. IAM aut

AWS IAM Policies + Password Vaulting: the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

Cloud SQL password policies enforce complexity and rotation for built-in auth. IAM database authentication uses short-lived OAuth tokens instead of passwords. These controls decide who can connect. They do not check what each statement does. They do not filter what data returns. Many teams think these close the security gap for AI agents. They do not.

Both features sound like security controls. They operate at different layers. Password policies govern credential strength and lifecycle. IAM authentication removes stored passwords. It uses tokens that expire after one hour. Neither inspects the SQL sent to the database. A read-only role can still return every permitted row. A user with write privileges can run destructive statements. The gap is in the lack of a check on the statement itself.

Cloud SQL password policies

Cloud SQL built-in authentication uses a username and password. You must enable password policies explicitly. They are not active by default. Once on, they enforce minimum length and complexity. They limit password reuse. They block passwords that match the username. They set a minimum interval between changes. You can set per-user expiry in days. You can set account lockout after failed attempts. These policies do not apply to hashed passwords. If you set a password using a hash, the rules will not take effect.

These policies reduce the risk of weak credentials. They do not change user privileges. A user with a strong password holds their granted rights. If they have SELECT on a table, they can read it. If they have DELETE, they can remove rows. The policy governs the key to the door. It does not control what happens inside.

IAM database authentication limits

IAM database authentication uses a different approach. Users log in with a short-lived OAuth 2.0 token. The principal needs the cloudsql.instances.login permission. The token is valid for only one hour. The Cloud SQL Auth Proxy handles token refresh. This makes the experience smoother for applications. IAM login requires SSL.

Enabling the cloudsql.iam_authentication flag does not stop password logins. Both methods work side by side. Legacy users with standing passwords can still connect. An IAM user starts with no privileges. They can only access objects granted to PUBLIC. You must use standard PostgreSQL GRANT statements for specific tables. IAM authentication solves credential storage. It does not solve permission scoping. A user with SELECT on a wide table can still pull sensitive data.

AWS IAM Policies + Password Vaulting: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

pgAudit records and misses

Cloud SQL uses pgAudit for SQL statements. It uses Cloud Audit Logs for admin operations. pgAudit is not on by default. You must set the cloudsql.enable_pgaudit flag. You must create the extension. You must set the pgaudit.log flag. This specifies which commands to record. Examples include READ, WRITE, or DDL. The pgaudit.log flag defaults to none. Nothing is logged until you configure it. You must enable Data Access audit logs in Cloud Logging. These are disabled by default for Cloud SQL.

pgAudit entries record the audit class and command. They record the database, statement, and user. This is valuable for post-incident review. It is a record, not a prevention. If an agent exposes sensitive data, pgAudit logs it. The data has already left the database. If an agent runs a destructive statement, pgAudit logs it after the damage. The trail tells you who did what. It does not stop the action. It does not filter the result. For AI agents, this visibility is necessary but not sufficient. You need a control that acts in real time. It must act on the connection before the statement reaches the database.

Statement-level control with hoop.dev

The missing layer is a check on the wire. An open-source proxy runs next to your database. It reads every statement an agent sends. It reads every row the server returns. hoop.dev is a sidecar for your Postgres instance. It runs beside the database, not in place of it. Agents change one thing in their connection string. They update the host and port. No SDK is needed. No prompt changes are needed. No agent-side config is needed. The agent never knows it is there.

With hoop.dev in the path, you apply guardrails. These refuse destructive statements before they land. A DELETE with no WHERE clause is blocked. The agent receives a readable error. You can use Data Masking. It rewrites sensitive values in the result set. This happens before values reach the client. The request itself is never touched. Only the copy of the result is rewritten. This works for psql, an ORM, a dashboard, or an agent. See the Data Masking documentation for rule definitions.

Every statement and decision is written to an audit trail. This is per resource. You get a record of what the agent tried. Unlike pgAudit, hoop.dev acts in real time. It does not replace your IAM authentication. It does not replace your password policies. It does not replace your pgAudit setup. It rides next to them. It adds control over what each statement does. It controls what comes back. You can explore the source code in the hoop.dev GitHub repository.

Frequently asked questions

Does IAM authentication on Cloud SQL stop password logins?
No. Enabling the flag allows IAM token logins. It does not prevent existing users from using passwords. Both methods work simultaneously.

Can pgAudit prevent an agent from reading sensitive data?
No. pgAudit records SQL statements after execution. It provides an audit trail for review. It does not block statements. It does not mask results in real time. You need a control that acts on the connection. It must act before the result reaches the client.

How does hoop.dev integrate with Cloud SQL?
hoop.dev runs as a sidecar next to your Postgres instance. Agents point their connection string at the proxy. Credentials and clients stay the same. The proxy reads the Postgres protocol. It applies guardrails and masking. It records every statement and decision. See the Postgres setup docs for details.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.