How to Integrate Streamlit and Spanner Safely

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams pair streamlit and spanner to build fast internal data apps on global relational tables. The Python web app sends queries to the cloud database and displays live results. This setup lets analysts and support teams view records or run updates in a browser. Without clear security rules, those web apps can expose broad database roles to every user. How streamlit and spanner handle logins and data flow A data app runs on a server and talks to the cloud database over gRPC. The app uses a cl

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.

Teams pair streamlit and spanner to build fast internal data apps on global relational tables. The Python web app sends queries to the cloud database and displays live results.

This setup lets analysts and support teams view records or run updates in a browser. Without clear security rules, those web apps can expose broad database roles to every user.

How streamlit and spanner handle logins and data flow

A data app runs on a server and talks to the cloud database over gRPC. The app uses a cloud client library to open sessions and run SQL statements.

In most setups, the app logs in to the database with one cloud service account. Cloud identity rules check if that service account can read or write specific tables.

When a user clicks a button in the browser, the Python script builds a query. The script sends that query through the shared database session and renders the returned rows.

The database only sees the service account identity, not the person using the browser. The app server holds all the database permissions for every person who opens the page.

Common failure modes with shared service accounts

Many teams put a static JSON key file on the app server during testing. That key often stays in place when the app moves to production.

If an attacker steals that key file, they get full access to the database. Shared keys also make rotation hard because changing the key breaks the live web app.

Overbroad roles create another big risk for internal tools. An app that only needs to read order status might hold a full database write role.

End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

A bug in a text input box could let a user run bad delete statements. Database logs will only show the shared app identity, which hides who ran the query.

To fix this, teams should drop static key files and use workload identity roles. Give each app its own cloud service account with the smallest possible database role.

Split read apps from write apps so report viewers never touch an active write session. Use fine-grained database roles to restrict which tables and columns that service account can read.

Scoping network paths and protecting sensitive fields

Network rules should lock down where the Python app can send traffic. Place the app server and the database inside the same private cloud network space.

Block public internet paths so only approved app hosts can reach the database endpoint. Set up strict firewall rules between your web tier and your data tier.

Internal tools often pull tables that hold sensitive customer fields. Support dashboards might query tables with emails, phone numbers, card numbers, or national IDs.

Data masking rewrites matched fields in query results before they reach the browser screen. This step keeps raw sensitive strings out of shared dashboards and local browser caches.

Teams should also log every query alongside the logged-in web user identity. Tying user logins to database queries gives security teams a clear audit trail during incidents.

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

How should a Streamlit app log in to Spanner without static keys?

Attach a dedicated cloud service account to the compute host that runs your Python app. The client library will use the host identity to log in without storing key files.

How can teams limit what tables a dashboard can query?

Create a custom database role that only grants select rights on the required tables. Assign that specific role to the app service account so other tables stay off limits.

Why do database audit logs miss the end user identity from web apps?

The web app pools connections under a single cloud service account for all browser users. Without user context in the session, the database only logs the shared app account name.

The query runs. The emails stay hidden.