The Simplest Way to Make Hashicorp Vault and Spanner Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Running hashicorp vault and spanner together lets teams issue short-lived cloud roles for database work. Your secret store manages service account keys while the database checks permissions on every query. This workflow stops developers from keeping long-lived cloud keys on their laptops. Instead, users ask the secret store for a temporary identity when they need to run SQL. When the timer runs out, the cloud provider deletes that temporary identity. How hashicorp vault and spanner share iden

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.

Running hashicorp vault and spanner together lets teams issue short-lived cloud roles for database work. Your secret store manages service account keys while the database checks permissions on every query.

This workflow stops developers from keeping long-lived cloud keys on their laptops. Instead, users ask the secret store for a temporary identity when they need to run SQL. When the timer runs out, the cloud provider deletes that temporary identity.

How hashicorp vault and spanner share identity and permissions

In production, these two systems do not talk to each other over a direct wire. Google Cloud IAM sits between them and handles all trust checks. You configure HashiCorp Vault with a privileged Google Cloud service account. That main account holds rights to create new accounts or mint short-lived tokens.

Next, you map secret engine roles to specific Google Cloud IAM roles for Spanner. One role might grant read rights on a single database instance. Another role might allow schema edits or data writes for an app release. When an app or engineer logs in to HashiCorp Vault, it checks their identity first. Then it calls the Google Cloud API to generate a temporary credential.

The user or app takes that credential and sends a query to the database. Spanner checks Google Cloud IAM to confirm the credential has the right database role. If the check passes, the database runs the query and returns the rows. When the lease time ends, HashiCorp Vault tells Google Cloud to revoke the credential.

Common failure modes and how to scope database roles

This setup solves key rotation, but several failure modes still hurt production teams. The first issue happens when teams give the secret store too many cloud permissions. If the root account holds project owner rights, a single mistake can expose every resource. You should restrict the root account so it only manages specific database roles.

A second problem comes from Google Cloud service account quotas and propagation delays. Creating a brand new service account for every user session hits cloud limits fast. Instead, configure HashiCorp Vault to mint short-lived OAuth tokens for pre-made service accounts. Pre-made accounts work right away and avoid IAM propagation delays across regions.

HashiCorp Vault + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

A third gap involves visibility inside the database itself. Cloud IAM roles control who can query a database or use fine-grained roles. Still, multiple engineers who share the same Vault role also share the same cloud identity. When someone runs a bad update, the database logs only show the shared service account. Teams then struggle to tie a specific SQL statement back to one human user.

Scoping network paths and sensitive data rules

To fix shared identity gaps, give each team or job a narrow role. Use fine-grained roles inside Spanner to restrict which tables and columns a role can read. Keep human debug roles separate from automated app roles at all times. Set short lease times for human sessions so unused tokens expire within an hour.

You should also lock down network paths to both systems. Place the secret store and the database inside private cloud networks. Require engineers to log in with their main work identity before they request any token. Even with tight IAM roles, raw tables often hold emails, phone numbers, or card numbers. Adding query-level logging and data masking rewrites matched fields in results before users read them.

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 runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values 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

How does HashiCorp Vault issue credentials for Spanner?

HashiCorp Vault uses its Google Cloud secrets engine to talk to Cloud IAM. It creates temporary OAuth tokens or service account keys mapped to specific Spanner IAM roles.

Should we generate service account keys or OAuth tokens for database work?

Always choose OAuth tokens when your client tools support them. OAuth tokens expire on their own and avoid the cloud quota limits of new keys.

Can IAM roles restrict which Spanner tables a developer can read?

Standard Cloud IAM roles apply to the whole database instance. To restrict specific tables, link your cloud service account to Spanner fine-grained roles inside the database.

The query runs. The emails stay hidden.