How to Configure Spanner User Roles

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up spanner user roles by linking cloud identity rules with database grants. First, assign a broad cloud role, then add fine-grained roles inside the database. Most engineering teams start by giving developers full database reader or writer access. This fast setup helps teams ship apps without waiting on ticket queues. Still, broad permissions let any logged-in user read whole tables or change production rows. How spanner user roles work in Google Cloud Google Cloud Spanner splits acce

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 user roles by linking cloud identity rules with database grants. First, assign a broad cloud role, then add fine-grained roles inside the database. Most engineering teams start by giving developers full database reader or writer access. This fast setup helps teams ship apps without waiting on ticket queues. Still, broad permissions let any logged-in user read whole tables or change production rows.

How spanner user roles work in Google Cloud

Google Cloud Spanner splits access control into two distinct layers. The first layer uses cloud identity rules at the project or instance level. These coarse rules decide who can reach the database instance or manage backups. If a user gets a general reader role here, they can read every table. Most teams find that instance-level roles give out way too much power.

The second layer happens inside the database engine using fine-grained access control. A database admin creates custom roles right inside the database schema. The admin then grants specific read or write rules on tables, columns, or views. Next, the admin links a cloud identity role to that specific database role. When a user logs in, the system checks their cloud identity first. Then the database limits their session to the exact tables tied to their role.

Choosing between cloud identity and fine-grained roles

Teams must decide which layer fits each person and service account. Coarse cloud roles work well for automated apps that need full database reach. They also fit platform engineers who manage instance size, backups, and storage nodes. You should not give these wide roles to support staff or data analysts.

Fine-grained roles work best for human users who only need a few tables. You can build a role for support staff that only reads order tables. You can also restrict write rules so an app only updates status columns. Splitting roles this way shrinks the blast radius if someone steals a key. Still, maintaining hundreds of database roles across many instances takes lots of manual work.

User Provisioning (SCIM) + Lambda Execution Roles: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native roles solve and what they miss

Native Spanner roles do a great job of locking down initial logins. They stop unapproved users from reaching your instances or reading restricted tables. You can also pair them with short-lived service account keys to cut risk. For static app workloads, native roles provide a solid baseline for database safety.

Yet native roles only check permissions when a session starts or a table opens. Once a user has table access, the role cannot judge individual queries in flight. A developer with legitimate read access can still pull ten thousand customer phone numbers. Native roles cannot rewrite emails, card numbers, or national IDs inside query results. They also cannot pause a risky update statement to ask a manager for approval.

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 cloud IAM roles and Spanner database roles?

Cloud IAM roles grant access across the whole database instance and all tables. Spanner database roles limit access to specific tables, views, and columns inside one database.

Can Spanner user roles hide sensitive data inside a column?

Database roles can block a user from reading a sensitive column at all. Still, native roles cannot mask emails or card numbers inside results from allowed columns.

How do you remove broad access when moving to fine-grained roles?

You must first grant the user a specific fine-grained role inside the database. Next, you remove their broad project or instance reader role in the cloud console.

The query runs. The emails stay hidden.