The Simplest Way to Make Spanner and Traefik Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Running spanner and traefik together lets your edge router send safe requests to backend apps. Those apps then read and write data in Google Cloud's distributed SQL database. This setup helps teams handle huge global traffic loads while keeping data consistent across regions. When you link your router and database rules the right way, requests stay fast and safe. How traffic and permissions flow between spanner and traefik Traefik sits at the edge of your network and takes in incoming web or

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 spanner and traefik together lets your edge router send safe requests to backend apps. Those apps then read and write data in Google Cloud's distributed SQL database. This setup helps teams handle huge global traffic loads while keeping data consistent across regions. When you link your router and database rules the right way, requests stay fast and safe.

How traffic and permissions flow between spanner and traefik

Traefik sits at the edge of your network and takes in incoming web or API requests. It checks rules, TLS certs, and user tokens before passing requests to your backend apps. Your backend apps then open sessions to Google Cloud Spanner using gRPC and IAM roles. Traefik does not query the database on its own in a standard setup. Instead, it routes traffic to microservice pods or servers that hold the database client code.

Permissions work across two distinct layers in this architecture. At the edge layer, Traefik middleware checks who the caller is through JSON Web Tokens. At the data layer, Google Cloud IAM checks if the app identity can read or write rows. You can pass caller headers from the router down to the app service. The app can then pick the right database role or log who made the request.

Network paths also need careful setup to keep latency low. Traefik watches container platforms like Kubernetes to find healthy app pods right away. Those pods keep warm session pools open to the Google Cloud database endpoints. If a pod dies, the router stops sending traffic to it right away. This stops failed database writes and keeps user requests moving without drops.

Common failure modes and how to scope roles

Many teams make the mistake of giving one wide service account to all backend apps. When every app behind the router uses the same cloud key, you lose clear audit trails. If one route has a bug, an attacker can reach every table in the database. Another common problem happens when teams leave internal admin routes open on the router. Bad routing rules can expose internal data APIs to the public web.

To fix this, split your app services by what they actually need to do. Give read-only database roles to services that only fetch data for public routes. Give write roles only to specific services that handle updates or orders. Use workload identity features so pods get short-lived cloud tokens instead of static key files. Static keys stored on disk are easy to leak and hard to rotate on time.

End-to-End Encryption + Traefik Middleware Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Unlogged queries are another major gap during live incidents or human debugging sessions. Router logs show the web path and status code, while database logs show the service account. Neither log shows which human engineer ran an ad-hoc query or changed a sensitive row. You also need a way to protect sensitive columns when people query live tables. Data masking rewrites matched fields like emails, phone numbers, card numbers, or national IDs in results.

Setting up safe network paths for production

Keep your database traffic off the public internet by using private cloud network links. Your router should live in a public subnet only if it takes outside user traffic. Backend apps should sit in private subnets with strict firewall rules between them. Only allow the router to talk to the exact ports your backend apps use.

Check your TLS settings on both the edge router and the database client. Traefik can manage certs on its own so edge traffic stays encrypted at all times. Google Cloud Spanner requires encrypted gRPC links for all client traffic by default. When you pair strict edge rules with tight IAM roles, your system stays safe under heavy load.

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 runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Can Traefik route traffic directly to Google Cloud Spanner?

Traefik can forward raw gRPC traffic, but Spanner needs Google Cloud IAM auth and session management. In almost all setups, Traefik routes requests to a backend app that uses the official Spanner client.

How do we trace a web request all the way to a database query?

Have Traefik attach a trace ID header to every incoming web request at the edge. Your backend app can read that header and attach it as a request tag on the Spanner call.

What is the safest way for apps behind Traefik to authenticate to Spanner?

Use federated workload identities instead of static JSON service account keys. Give each microservice its own fine-grained IAM role so it only touches the exact tables it needs.

The query runs. The emails stay hidden.