How to Configure Spanner Least Privilege
You set up spanner least privilege by pairing Cloud IAM with internal database roles. This dual setup limits both who can reach the database and what tables they read. Many teams start by giving devs and apps broad project or instance roles. Those wide roles let anyone read or change any table in the database. One bad query or stolen key can then expose or delete production records. How spanner least privilege works in the cloud Google Cloud Spanner splits permissions into two distinct layers
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 spanner least privilege by pairing Cloud IAM with internal database roles. This dual setup limits both who can reach the database and what tables they read. Many teams start by giving devs and apps broad project or instance roles. Those wide roles let anyone read or change any table in the database. One bad query or stolen key can then expose or delete production records.
How spanner least privilege works in the cloud
Google Cloud Spanner splits permissions into two distinct layers. The first layer is Cloud IAM at the project, instance, or database level. Cloud IAM controls who can open a session or manage the database instance. If you only use Cloud IAM, a reader role grants access to every table.
The second layer is fine-grained access control inside the database engine itself. Here, you create specific database roles using standard data control statements. You grant those roles permission to read or write specific tables, views, or columns. Then you link a Cloud IAM user or service account to that database role. When the user connects, they must declare which database role they want to use. Spanner checks Cloud IAM first, and then enforces the table rules for that role.
You can also hierarchical parent and child roles inside the database. A child role passes its permissions up to a parent role for easier management. This structure lets you group table permissions by team or by service function. You should assign roles to groups or service accounts instead of single human accounts. That habit keeps your permission list small and much easier to audit over time.
Scoping service accounts and human users
Apps and human engineers need very different paths into a production database. For apps, you should create one dedicated service account per microservice or job. Each service account gets linked only to the database role for its specific tables. If a billing app only reads invoice rows, its role should block user tables. This limits the blast radius if an attacker steals that app key.
For humans, standing permissions in production create a constant risk of mistakes. Devs often need temporary read access to debug a broken release or bad row. Instead of permanent roles, teams use group bindings that expire after a set time. You should also split admin tasks from daily data queries. No engineer should use an instance admin role just to run a select query.
Least Privilege Principle + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Where native database roles fall short
Cloud IAM and fine-grained roles do a great job of scoping table access. They decide which user or app can open a session and touch a table. Still, they do not inspect the live queries running inside an active session. Once a user has read permission on a customer table, they get every row by default. Native roles also cannot rewrite sensitive fields like emails, phone numbers, or card numbers.
Database roles also lack per-query approval steps for risky data changes in production. If an engineer has write access to fix one row, they can drop thousands. Auditing what each human ran also requires digging through high-volume cloud log sinks. Static roles alone cannot stop a bad update statement once the session starts.
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
What is the difference between Cloud IAM roles and Spanner database roles?
Cloud IAM roles grant broad access to the whole database or instance. Spanner database roles work inside the database to restrict specific tables, views, and columns.
Can I restrict access to specific columns in a Spanner table?
Yes, fine-grained roles let you grant select or update rights on specific columns. You can still hide sensitive columns while letting users query the rest of the row.
How do I audit who has access to my Spanner tables?
You must check both your Cloud IAM policy bindings and the internal system tables. Combining both views shows which users can assume each specific database role.
Related guides
In this post