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

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams pair cloud sql and json rpc to expose database records through light remote calls. An app server receives a structured request and runs the matching query against the database. This pattern keeps database drivers off client devices and centralizes query logic in one service. Engineering teams use it to build internal tools, microservices, and automated agents. Yet a simple transport protocol does not solve database security on its own. You still need strict role scoping, clear logs, and t

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 json rpc to expose database records through light remote calls. An app server receives a structured request and runs the matching query against the database.

This pattern keeps database drivers off client devices and centralizes query logic in one service. Engineering teams use it to build internal tools, microservices, and automated agents. Yet a simple transport protocol does not solve database security on its own. You still need strict role scoping, clear logs, and tight network rules.

How cloud sql and json rpc handle requests and roles

In a standard setup, a client sends a method name and parameters over HTTP. The receiving service parses the payload, checks the method, and opens a database session. Cloud SQL for PostgreSQL runs as a managed service with specific role limits. Customers cannot create or use database accounts with full superuser attributes.

Instead, Google provides a custom admin role with select high-level rights. The default admin user starts without a password, so you must set one first. This default account can create roles, create databases, and log in. Still, a Google-managed system account holds the actual superuser rights on the instance. Customers cannot delete or change these built-in system roles.

When your RPC server connects to the database, it should never use the admin account. The admin role can create extensions, event triggers, and replication rules. A web service or internal tool worker does not need those powers. You should create a dedicated database user that only reads or writes specific tables.

Common failure modes and how to scope access

The biggest risk in this architecture is a shared service account. Many teams give the RPC server one broad database login for all incoming requests. If ten internal apps call that service, the database sees only one user. Database logs then show the server account instead of the person or agent calling it.

JSON Web Tokens (JWT) + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Broad methods create another huge risk for production data. Some teams build a generic query method that accepts raw SQL strings in the payload. That choice turns a clean remote call into an open door for bad queries. One bad call can drop tables or dump sensitive rows like emails and phone numbers.

To fix this, map each remote method to a single fixed query with typed inputs. Split your database users by task so read methods use a read-only database role. Write methods should use a separate role limited to the exact tables they update. You should also place the database on a private network path.

Only the RPC worker nodes should reach the database port on that private network. If an engineer needs to check data by hand, do not share the service password. Give each person or service a distinct identity and log every query with user context. Masking rules can also rewrite emails, card numbers, and national IDs in query results.

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

Should my JSON RPC server use the default postgres user in Cloud SQL?

No, the default admin user has broad rights to create roles and databases. Create a restricted user with only the table rights your RPC methods need.

How do we stop raw SQL injection through RPC methods?

Never pass raw query strings inside request parameters. Map each method name to a fixed, parameterized query on the server side.

Why do our database logs show only one user for all RPC calls?

Your server uses one shared connection pool for every client request. Separate roles by service or pass caller identity through an access layer that logs each user.

The query runs. The emails stay hidden.