How to Configure Cloud SQL Service Account
You set up a cloud sql service account by making an identity in your cloud project. Next, you link that identity to your database instance and grant it specific database roles. Teams often use these accounts so apps and scripts can log in without human intervention. Still, teams often grant broad admin roles during the initial setup to move fast. Broad permissions give every app or user under that account full control over production tables. How a cloud sql service account works A cloud sql s
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 a cloud sql service account by making an identity in your cloud project. Next, you link that identity to your database instance and grant it specific database roles. Teams often use these accounts so apps and scripts can log in without human intervention. Still, teams often grant broad admin roles during the initial setup to move fast. Broad permissions give every app or user under that account full control over production tables.
How a cloud sql service account works
A cloud sql service account acts as a non-human identity for your apps and workloads. You first create the account in your cloud project and assign project-level permissions to it. Then, you register the account inside the database engine as a valid database user. When an app runs, it requests a short token from the cloud platform to log in. This workflow removes the need to store static database passwords inside your app config files.
Inside Cloud SQL for PostgreSQL, you must still manage database roles after the account logs in. Because it is a managed service, customers cannot create or use true superuser accounts. Instead, the platform provides a special cloudsqlsuperuser role with some high-level privileges. The default postgres admin user belongs to this role and can create roles and databases. A Google-managed system user called cloudsqladmin holds the actual superuser rights, which customers cannot change.
When you add a service account to the database, you choose which roles to grant. If you grant the cloudsqlsuperuser role, that account can create extensions, event triggers, and replication setups. If the account only needs to read data, you must build a custom read-only role. You then attach that smaller role to the service account user inside the database engine.
Why native roles are not enough for team access
Setting up a service account solves how an app or script proves its identity. It ensures that only approved cloud workloads can open a network session to the database. It also stops engineers from pasting long-lived passwords into source code or deployment scripts. For automated backend services with fixed queries, this native setup works well.
Still, native service accounts leave a big gap when engineers or tools run ad-hoc queries. Cloud permissions only check who is allowed to log in at the start of a session. Once the session starts, the database only checks the broad role tied to that account. It does not inspect individual SQL statements in flight before they hit the database engine.
Service-to-Service Authentication + Service Account Governance: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Also, multiple apps or team scripts often share the same service account in production. When two workloads share one account, your database logs show every query under one name. You cannot tell which person or workflow ran a destructive update or read sensitive rows. Native roles also return raw table data to anyone who has select rights on a table. If a table holds emails, phone numbers, card numbers, or national IDs, the query returns them in plain text. You have to build manual views for every table if you want to hide those fields.
How to scope permissions for service accounts
To keep your database safe, start by separating human access from machine service accounts. Never let engineers log in with the same service account that your backend apps use. Give each app its own dedicated identity so you can revoke access for one service alone.
Next, avoid granting the cloudsqlsuperuser role to standard app accounts. That role can create replication publications and event triggers, which most web apps never need. Instead, grant select, insert, and update rights only on the specific tables each app uses. Review your database user list often and remove old service accounts that no longer run.
Govern statements and responses across databases and APIs
Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev sits inline in the protocol beside each supported service as an open-source proxy, a sidecar for your database or API. For every query or command an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human approval.
First, hoop.dev guardrails block banned queries before they run or hold risky ones for review, and hoop.dev data masking rewrites matched sensitive values in responses in memory. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.
Frequently asked questions
Can a cloud sql service account have full superuser rights?
No, Cloud SQL for PostgreSQL is a managed service and does not give customers superuser attributes. The highest role you can assign is cloudsqlsuperuser, while the system user cloudsqladmin keeps true superuser rights.
Does the default postgres user work like a service account?
No, the default postgres user is a built-in database admin account that starts without a password. You must set a password for it before logging in, whereas service accounts use cloud identity tokens.
How do I limit what a service account can read in a table?
In a native setup, you must revoke direct table access and grant select rights on specific columns or views. Otherwise, any role with table read access will return all rows and columns in full by default.
Related guides
In this post