The Simplest Way to Make Cloud SQL and gRPC Work Like They Should

Published
Length
4 min read

Luis Felipe Dias

All posts

Teams pair cloud sql and grpc to serve database records over fast network calls. The service handles incoming requests and runs queries against the managed database. This setup lets backend apps share data across internal networks with low latency. Each service owns its schema and exposes strict methods to other services. Calling apps do not talk to the database directly. Instead, they send structured messages to the service layer. The service checks the request and translates it into a safe da

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 cloud sql and grpc to serve database records over fast network calls. The service handles incoming requests and runs queries against the managed database.

This setup lets backend apps share data across internal networks with low latency. Each service owns its schema and exposes strict methods to other services. Calling apps do not talk to the database directly. Instead, they send structured messages to the service layer. The service checks the request and translates it into a safe database query. This pattern keeps database rules in one place and reduces network clutter.

How cloud sql and grpc handle identity and data flow

Data flows from the client app to the service, then to the database. A client sends a message over HTTP/2 to the remote procedure endpoint. The server reads the message fields and checks the caller identity. Next, the server opens a session to the database using a dedicated role. It runs the query, packs the rows into a response message, and replies.

Cloud SQL for PostgreSQL is a managed service with specific role limits. Customers cannot create or use database accounts with true superuser attributes. Instead, you assign the cloudsqlsuperuser role to admin users for high-level tasks. This role can create extensions, event triggers, and replication users or publications. The default postgres admin user belongs to this role and can create databases. Still, it starts without a password, so you must set one before logging in. A Google-managed system user called cloudsqladmin holds the actual superuser rights. Customers cannot delete or change these built-in system roles.

Because of these rules, your service should never log in as the admin user. You should create a separate database user with narrow table rights for the service. The service uses that account to read or write only the tables it owns.

Common failure modes and how to scope roles

Many teams make the mistake of sharing one database account across ten services. When a bad query slows down the database, you cannot tell which service caused it. Shared accounts also give every service the power to read or drop any table. If one service has a bug, all your data is at risk.

Broad tokens and unlogged queries create big blind spots during security audits. A client might call a service method using a wide network token. The service then runs a query using a generic database user. At the database level, the log only shows the generic service account name. You lose the link between the human caller and the final database action. Sensitive fields like emails, phone numbers, or card numbers might return in full text. Without field controls, masking never rewrites matched fields in results before they reach clients.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

To fix this, give each service its own database role with minimum rights. Split read workloads from write workloads by using two distinct database users. Set up network rules so only the specific service host can reach the database. Do not let client apps bypass the service layer to run direct queries. Keep the cloudsqlsuperuser account locked away for schema updates only. Log both the incoming remote call and the outgoing database query with a shared request ID.

Setting up safe schema changes for service teams

Service updates often need both new message definitions and new database columns. If you change a column name first, the running service will fail right away. Teams must plan database changes so old and new service versions can run together.

First, add the new column using an admin role during a planned change window. Keep the old column in place so current service calls still work fine. Next, deploy the updated service code that writes to both columns. Once all traffic uses the new version, you can remove the old column. Separate the migration role from the daily runtime role used by the service. The runtime role should only select, insert, or update rows in existing tables. It should never have the right to alter tables or drop schemas.

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

Should a gRPC service use the default postgres user in Cloud SQL?

No, the default postgres user has broad role and database creation rights. Create a dedicated user with read and write rights on specific tables only.

Can I grant true PostgreSQL superuser rights to my service account?

No, Cloud SQL reserves true superuser rights for the Google-managed cloudsqladmin account. Customer accounts can only receive the cloudsqlsuperuser role for admin work.

How do I trace which client call triggered a slow database query?

Give each service a unique database user so you can tell apps apart. Pass a trace ID from the remote call into the query comment for logs.

The query runs. The emails stay hidden.