How to Configure Cloud SQL Least Privilege

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up cloud sql least privilege by creating custom database roles with narrow permissions. You then grant each user or app only the exact table actions they need. Many teams skip this step and share the default admin account across apps. Overly broad roles let one bad query drop tables or expose sensitive customer data. How cloud sql least privilege works in practice Cloud SQL for PostgreSQL is a managed database service. Customers cannot create or use database accounts with true superus

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.

You set up cloud sql least privilege by creating custom database roles with narrow permissions. You then grant each user or app only the exact table actions they need. Many teams skip this step and share the default admin account across apps. Overly broad roles let one bad query drop tables or expose sensitive customer data.

How cloud sql least privilege works in practice

Cloud SQL for PostgreSQL is a managed database service. Customers cannot create or use database accounts with true superuser attributes. Google reserves a system user named cloudsqladmin for full superuser tasks. Customers cannot delete or change these built-in system roles or users.

Instead, the service gives you the cloudsqlsuperuser role for high-level admin work. The default postgres user belongs to this role and can create databases and roles. This default user starts without a password, so you must set one before logging in. It does not hold true superuser or replication attributes.

People with the cloudsqlsuperuser role can still run powerful actions. They can add extensions, build event triggers, and set up replication users. They can also create replication publications and subscriptions. Because this role holds wide power, daily users and apps should not use it.

To follow least privilege, you create separate roles for each job function. You build one role for read-only analysts and another for app writes. You grant rights only on specific schemas or tables. You also set default privileges so new tables do not keeps the session active to everyone. When an engineer needs to check a production issue, they log in with a read-only role.

What native roles solve and what they leave open

Native database roles do a good job of controlling who can log in. They also limit which tables a user or app can read or change. Separating admin roles from app roles stops basic accidents during daily work. A read-only user cannot delete rows or drop a production schema.

Still, static database roles only check permissions at the table or column level. They do not inspect what individual statements do in flight during a live session. Once a user has read rights on a customer table, they can pull every row by default. Native roles do not rewrite sensitive fields like emails, phone numbers, or card numbers in query results.

Least Privilege Principle + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Role grants also stay active until an admin revokes them by hand. Over time, engineers collect extra roles across many database instances. If an engineer needs temporary write rights to fix a bug, someone must grant and revoke that role manually. Native permissions also lack a way to require peer approval for a single risky command.

Designing scoped roles for people and apps

A clean role design splits human users from automated workloads. Apps need steady, narrow permissions to read and write specific tables. You should give each microservice its own database user and role. If one service gets compromised, the attacker can only touch that service's tables.

Human users need a different setup because their tasks change day to day. Most daily debugging only requires reading state and checking query plans. You can assign engineers to a base read-only role by default. Reserve the cloudsqlsuperuser role for rare schema migrations or extension updates. This separation keeps daily human sessions safe from accidental writes.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev sits inline in the wire protocol beside those services as an open-source proxy, a sidecar for your Postgres or API. On every query an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run, and hoop.dev data masking rewrites matched sensitive values in responses in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

Does the default postgres user in Cloud SQL have full superuser rights?

No, Cloud SQL is a managed service, so customers cannot get true superuser attributes. The default postgres user belongs to the cloudsqlsuperuser role and can create roles and databases. A Google-managed user named cloudsqladmin holds the actual superuser privileges.

What can a user with the cloudsqlsuperuser role do?

The cloudsqlsuperuser role holds specific admin privileges needed to run a managed database. It can create extensions that require superuser rights and build event triggers. It can also create replication users, publications, and subscriptions.

Why should teams avoid using cloudsqlsuperuser for application traffic?

Using cloudsqlsuperuser for app traffic gives the app power to alter database structures and settings. If a bug or attacker runs a bad query, it can harm the whole instance. Scoping the app to a custom role limits damage to only the tables it needs.

The query runs. The emails stay hidden.