How to Configure Spanner Service Account
You set up a spanner service account by making a cloud identity and adding database roles. Next, you attach that identity to the app or workload that needs database access. Many teams rush this step and grant broad project roles to get things working fast. That shortcut gives every workload full power to read, change, or delete all tables. How a spanner service account works in practice A service account is a non-human identity for your apps, scripts, and backend jobs. It proves who the app i
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 spanner service account by making a cloud identity and adding database roles. Next, you attach that identity to the app or workload that needs database access. Many teams rush this step and grant broad project roles to get things working fast. That shortcut gives every workload full power to read, change, or delete all tables.
How a spanner service account works in practice
A service account is a non-human identity for your apps, scripts, and backend jobs. It proves who the app is when it talks to your cloud database. You create the account in your cloud project and pick a clear name for it.
After you make the account, you attach Identity and Access Management roles to it. You can set these roles at the project, instance, or single database level. Instance-level roles apply to every database inside that instance, which is often too broad. Database-level roles keep the account locked to just the one database it needs.
Inside the database, you can also use fine-grained roles to limit table access. A reader role lets the app run select queries without changing any rows. A writer role lets the app insert, update, and delete rows in permitted tables. Admin roles allow schema changes and full database control, so use them with great care.
Apps should log in with attached workload identities or federated tokens instead of saved keys. Static key files are easy to leak in code repos or build logs. Workload identities rotate short-lived tokens on their own and remove manual key work.
What native roles solve and what they miss
Native roles do a great job of deciding which app can reach a database. They stop unknown apps from logging in and block readers from dropping tables. When an app runs on its own, a scoped role is often enough.
The gap shows up when people or shared tools use these accounts to debug issues. Once a session starts with a valid role, the database trusts every query that follows. A user with write access can update the wrong rows during a late-night fix. A developer with read access can pull full tables of customer emails and card numbers.
Service-to-Service Authentication + Service Account Governance: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Shared accounts also make audit logs hard to read during a security review. The cloud log shows which service account ran a query, not which person typed it. Teams also struggle when they need to grant temporary write access for one quick task. Role bindings stay active until someone remembers to remove them, leading to permission creep.
Ways to keep database permissions tight
Start by creating one unique account for each app or microservice you run. Never share one account across multiple apps or mix test and production workloads. If one app has a bug, its limited role keeps other databases safe.
Use fine-grained database roles when an app only needs a few specific tables. Review your role list every month and remove bindings that nobody uses anymore. Turn on data access audit logs so you can see when accounts read sensitive tables. Still, native IAM checks who logs in, not what each query does in flight.
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
Should I use JSON keys for my spanner service account?
No, avoid downloaded key files whenever you can because they never expire by default. Use workload identity federation or attached compute identities so tokens rotate on their own.
What is the difference between instance roles and database roles?
An instance role gives the account permissions across every database inside that Spanner instance. A database role limits the account to one specific database, which is much safer.
Can I limit a service account to specific tables in Spanner?
Yes, Spanner supports fine-grained access control inside the database engine. You grant the account a fine-grained user role and assign table permissions with SQL grants.
Related guides
In this post