How to Configure Spanner Grant Permissions

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up spanner grant permissions by combining cloud IAM roles with database roles. Cloud IAM controls instance access, while database roles control access to specific tables. Most engineering teams start by giving developers broad database reader or writer roles. This fast setup helps teams ship code, but it creates security risks. Overly broad roles let users read sensitive data or change production tables by mistake. How spanner grant permissions work in practice Google Cloud Spanner us

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 grant permissions by combining cloud IAM roles with database roles. Cloud IAM controls instance access, while database roles control access to specific tables. Most engineering teams start by giving developers broad database reader or writer roles. This fast setup helps teams ship code, but it creates security risks. Overly broad roles let users read sensitive data or change production tables by mistake.

How spanner grant permissions work in practice

Google Cloud Spanner uses a two-layer model to control who can touch data. The first layer is cloud IAM, which works at the project or instance level. An admin grants a user an IAM role to let them reach the database. If a user has a broad IAM role, they can read every single table.

The second layer is fine-grained access control inside the database itself. Instead of broad IAM roles, admins create custom roles inside the database schema. You use standard grant statements to give those roles read or write rights. You can limit a role to specific tables, views, or even single columns.

After you define the database role, you link it back to cloud IAM. You grant the user an IAM role with a condition that names the database role. When the user logs in, they assume that specific database role for their session. The database then checks every query against the rules for that active role.

Creating and managing fine-grained database roles

To start, a security admin must enable fine-grained access on the user account. You remove the old database reader or writer IAM role from the user first. Next, you give the user the fine-grained access user role in cloud IAM. Without this base role, the user cannot use any internal database roles at all.

Inside the database, an admin creates roles that match different job tasks. For example, a support role might only get read access to an orders table. A billing role might get read and write access to an invoices table. Roles can also inherit rights from other roles to keep the setup clean.

When you grant table access, you can also pick which columns a role sees. This helps when a table holds both public info and private user details. Still, if a query touches a blocked column, the whole query will fail. The user must rewrite their query to ask only for the allowed columns.

AI Agent Permissions + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native permissions solve and what keeps the session active

Native database roles do a great job of limiting static access across teams. They stop a support worker from dropping a table or reading an unrelated schema. They also let you group table rules by job type instead of individual users. This makes it much easier to pass basic security audits each year.

Still, native roles only check who logs in and which tables they name. They cannot inspect what an allowed query actually does while it runs in flight. If a support user needs access to a user table, they see every row by default. If that table holds emails, phone numbers, or card numbers, the user sees them.

Blocking the column in the database role breaks apps and queries that expect it. Instead of failing the query, teams often need masking that rewrites matched fields in results. Teams also need a way to approve single risky write statements before they run. Native database roles stays static and cannot pause a single query for team review.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits inline in the protocol beside the service as an open-source proxy, a sidecar for your database or API. On every production query an agent or human runs, hoop.dev decides whether to pass, mask, block, or escalate it for review.

Before a query runs, hoop.dev guardrails check the statement against your rules, an AI Analyzer you configure can score intent or hold risky calls for human approval, and hoop.dev data masking rewrites sensitive fields in responses in memory. Explore the MIT-licensed project on GitHub.

Frequently asked questions

What is the difference between Spanner IAM roles and database roles?

Cloud IAM roles grant broad access to the whole database instance at once. Database roles live inside the schema and control access to single tables and columns.

Can a user hold more than one Spanner database role at a time?

A user can have permission to use several roles, but only one runs per session. You can grant one role to another role so a user gets combined rights.

Do fine-grained permissions hide sensitive data inside allowed columns?

No, native permissions are all or nothing for each column you grant. If a role can read a column, queries return the raw national IDs or emails.

The query runs. The emails stay hidden.