How to Configure Spanner Row Level Security

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up spanner row level security by building filtered views and database roles. Because the engine lacks native row policies, you grant roles read rights on views. Teams often start by giving engineers broad table roles to ship apps fast. When roles stay too wide, anyone who logs in can read every customer row. How spanner row level security works with views Google Cloud Spanner does not offer built-in row policies on base tables today. Instead, teams build a view layer on top of their c

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 row level security by building filtered views and database roles. Because the engine lacks native row policies, you grant roles read rights on views. Teams often start by giving engineers broad table roles to ship apps fast. When roles stay too wide, anyone who logs in can read every customer row.

How spanner row level security works with views

Google Cloud Spanner does not offer built-in row policies on base tables today. Instead, teams build a view layer on top of their core database tables. Each view includes a filter that checks a tenant key or user role. Next, you create fine-grained database roles for each team or app service. You revoke direct read rights on the base table from those roles. You then grant each role read permissions on its matching filtered view. When a user runs a query against the view, only permitted rows return. You also link Cloud IAM identities to these database roles for login checks.

Designing tenant tables for filtered access

Good row filtering starts with a clean schema design across your tables. Every shared table needs a clear column for the tenant or region key. Without this column, a view has no way to split rows by team. Many teams also place tenant keys first in the primary key path. This layout keeps related rows together on disk and speeds up filtered reads. You must also plan how parent and child tables share these filter keys. When child tables inherit the parent key, view filters stay fast and simple. Poor key choices force full table scans that hurt app speed at scale.

What view filters solve and what keeps the session active

Filtered views work well when apps always read through one fixed database role. They keep one customer from reading data that belongs to another customer. Still, managing hundreds of views across fast-changing schemas creates heavy work for teams. Every new table or column requires updates to your view definitions and role grants. Also, engineers who fix production bugs often need direct access to base tables. Native role setup decides who logs in, not what individual queries do in flight. Once an engineer holds a broad role, they can run wide queries or updates. View filters also return full column values for every row that matches the rule. That means raw emails, phone numbers, card numbers, and national IDs stay exposed.

Row-Level Security + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev sits inline in the wire protocol beside those services as an open-source proxy, a sidecar for your Postgres or API. 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 login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run, and hoop.dev data masking rewrites matched sensitive values in responses in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

Does Google Cloud Spanner have native row level security policies?

No, the database engine does not include native row policy objects on base tables. Teams achieve row filtering by creating SQL views and granting access through database roles.

How do database roles help restrict row access?

Database roles let you block direct table reads while allowing reads on filtered views. Users assume a role at login and only query the views assigned to them.

What happens to sensitive columns inside permitted rows?

A view filter returns every column in the view for all matching rows. To protect emails, phone numbers, or card numbers, you need field masking in flight.

The query runs. The emails stay hidden.