How to Configure AlloyDB Service Account

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up an alloydb service account by creating a cloud identity and granting it database roles. Next, you register that identity inside the database and assign table permissions. Teams often create one shared identity for all backend apps and scripts. They grant broad admin rights so nothing breaks during deploys. That fast setup creates big risks when an app or user runs bad queries. A single broad role lets any script read or delete sensitive rows across every table. How to set up an all

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 an alloydb service account by creating a cloud identity and granting it database roles. Next, you register that identity inside the database and assign table permissions.

Teams often create one shared identity for all backend apps and scripts. They grant broad admin rights so nothing breaks during deploys. That fast setup creates big risks when an app or user runs bad queries. A single broad role lets any script read or delete sensitive rows across every table.

How to set up an alloydb service account

Setting up an alloydb service account takes work in two places. First, you create the identity in your cloud project. Second, you add a matching user inside the database engine. The cloud identity handles the network check and login handshake. The database user controls what tables the app can read or write.

Start by creating a dedicated identity for each app or workload. Do not share one identity across many services. Give the identity only the cloud role needed to reach the cluster. Avoid project-wide admin roles that open up other cloud resources.

Next, log in to the database as an admin user. Managed database clusters do not give customers full system superuser rights. Instead, your admin user belongs to a managed admin role with high privileges. Use this admin user to create a new database user for the workload.

After the user exists, grant it permissions on specific schemas and tables. Most apps only need to read, insert, or update rows in one schema. They rarely need rights to drop tables or create new database users. Splitting roles for migrations and daily app traffic keeps permissions tight.

Why you should split human and machine identities

Many teams let engineers use an app identity to debug production issues. An engineer downloads a key or impersonates the workload role from a laptop. This habit ruins your audit logs right away. Every query in the log looks like it came from the app.

Service-to-Service Authentication + Service Account Governance: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

When a bad update happens, you cannot tell who ran the statement. You only see the shared machine name in the log entries. Give humans their own named identities and keep machine accounts for code. Clear identity split makes incident reviews much faster and cleaner.

What native identity setup solves and what it misses

Native service accounts solve the problem of static passwords in config files. When you tie logins to cloud identities, you cut down on leaked keys. You also get a central place to turn off an app login. If a service is retired, you disable its cloud identity in seconds.

Still, login checks only decide who can open a database session. Once the session starts, the database trusts every command that fits the role. If an app needs read rights on a customer table, it sees everything. It can pull emails, phone numbers, card numbers, and national IDs in bulk.

The same gap hits engineers who use shared identities for fixing. A role that allows updates for one fix allows updates on all rows by default. Native roles cannot pause a risky delete command to ask for peer review. They also cannot rewrite sensitive fields like card numbers in query results on the fly.

Check every Postgres query on the wire

Database roles and network rules decide who can open a session. They do not read what each SQL statement does after login. With hoop.dev, you run an open-source proxy, a sidecar for your Postgres, inline in the Postgres wire protocol. 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 apps and agents keep their login details and change only the host and port in the connection string their tool uses.

Before a query runs, hoop.dev guardrails refuse bad deletes or drops with a real Postgres error, or hold risky queries for approval. On the way back, hoop.dev data masking rewrites sensitive values in returned rows in memory, and every verdict goes to the audit trail. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and generates evidence for HIPAA, GDPR, and PCI DSS. See the code on GitHub.

Frequently asked questions

Should multiple apps share one alloydb service account?

No, give each app its own dedicated identity and database role. This setup limits blast radius if one workload is compromised. It also makes database audit logs much easier to read.

Does an alloydb service account need admin database rights?

Daily app traffic only needs rights to read and write specific tables. Keep schema creation and admin rights for separate migration jobs. Never run normal web traffic under an admin database role.

Can database roles hide sensitive columns from app or human queries?

Standard roles can block access to a whole table or column. Still, they cannot mask values like emails or phone numbers in query results. If a role has read access, it receives the raw text.

The query runs. The emails stay hidden.