How to Configure Spanner Replication User

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a spanner replication user by creating a service account in Google Cloud. Then you grant that account read roles for your database change streams. Teams often assign broad project roles to get data pipelines running fast. Those wide permissions let the account read or change every table in the instance. If an attacker steals that key, they gain full control over your data. How a spanner replication user works in Google Cloud Google Cloud Spanner does not use standard database login

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 replication user by creating a service account in Google Cloud. Then you grant that account read roles for your database change streams. Teams often assign broad project roles to get data pipelines running fast. Those wide permissions let the account read or change every table in the instance. If an attacker steals that key, they gain full control over your data.

How a spanner replication user works in Google Cloud

Google Cloud Spanner does not use standard database logins with passwords. Instead, it relies on cloud identity and access management for every request. A replication tool needs a dedicated cloud service account to read database changes. This account acts as the spanner replication user for your data pipeline.

Data movement tools read row updates through a feature called change streams. Change streams track inserts, updates, and deletes across your chosen tables. The replication service account must have permission to read both the database and the stream. You can also use fine-grained roles at the database level to limit table reads. The service account logs in with a workload identity or a downloaded key file. Once logged in, the pipeline reads the stream and sends records to your sink.

Scoping permissions for change stream pipelines

Many engineers grant the database admin role to their pipeline account during testing. That role allows the account to drop tables, change schemas, and write data. A replication job only needs to read change stream records and metadata. You should create a custom role or pick a read-only database role instead.

You can scope the change stream itself to watch only specific tables and columns. This step keeps sensitive tables out of the replication flow from the start. Fine-grained access control lets you bind database roles to the cloud service account. The account can then read only the stream you built for that job. You should also avoid static JSON key files whenever your setup allows it. Workload federation lets your pipeline log in without storing long-lived keys on disk.

User Provisioning (SCIM) + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native roles solve and what they leave open

Cloud identity roles do a great job of deciding who can log in. They verify that your pipeline service account has the right to open a session. They also block that account from deleting databases or changing cloud settings. This setup protects your cloud project from basic privilege abuse.

Still, native cloud roles leave a large gap during active database sessions. Once a user or tool logs in, the role checks stop at the door. The database does not check the content of individual queries in flight. If an engineer uses that same role to debug, they can run broad reads. Static roles also expose raw sensitive fields like emails, phone numbers, and card numbers. If a watched table holds national IDs, the stream sends those raw values out. Native cloud logs also struggle to tie shared service account queries to specific people.

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

Does Cloud Spanner use standard SQL users for replication?

No, Cloud Spanner uses cloud service accounts and identity roles for all logins. You can pair those cloud accounts with fine-grained database roles for stricter limits.

What is the safest way to let a replication tool log in?

Use workload identity federation instead of downloading static key files to your servers. Give the service account a read-only role scoped only to the required change stream.

Can native replication roles hide sensitive fields in results?

Native roles can block a user from reading an entire table or column. Still, they do not rewrite matched fields like card numbers or emails in query results.

The query runs. The emails stay hidden.