The Simplest Way to Make Cloud Run and Tcp Proxies Work Like They Should
You pair cloud run and tcp proxies to bridge stateless containers with raw socket backends. This setup lets serverless HTTP workloads talk to databases and legacy services over persistent connections. Standard serverless containers expect web traffic and scale down to zero when idle. Many internal databases and message queues require raw TCP sockets that keeps the session active longer. Placing a forwarding layer between the two systems solves this mismatch for production teams. How cloud run
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.
You pair cloud run and tcp proxies to bridge stateless containers with raw socket backends. This setup lets serverless HTTP workloads talk to databases and legacy services over persistent connections.
Standard serverless containers expect web traffic and scale down to zero when idle. Many internal databases and message queues require raw TCP sockets that keeps the session active longer. Placing a forwarding layer between the two systems solves this mismatch for production teams.
How cloud run and tcp proxies move traffic and check identity
Serverless containers run on dynamic hosts and change IP addresses as traffic spikes. They cannot hold long-lived socket pools to backend data stores on their own. When a container starts, it sends traffic through a local sidecar or network router.
First, the container uses its assigned service identity to prove who it is. Google Cloud IAM checks this role before allowing any outbound network flow. Next, the forwarding component opens a raw socket to the destination server.
The router wraps or forwards raw packets over an encrypted tunnel to the backend. When the database replies, the router sends the response back to the container instance. This flow keeps the database hidden on a private network with no public IP.
Common failure modes with shared identities and open networks
Many teams assign one default service account to every container in a project. If one app gets compromised, the attacker gains network reach to every backend socket. Teams also set up wide subnet rules that allow any container to reach any port.
Raw socket forwarding hides what happens inside the stream from standard cloud logs. Network logs show that a connection opened, but they miss the queries run inside. Shared database accounts make this worse because every container logs in as the same user.
End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
When a bad query locks a table, you cannot trace which user caused it. You also risk port exhaustion when hundreds of containers open new sockets at once. Without strict connection limits, a sudden traffic spike can crash the target database.
Scoping roles and network paths between both systems
Give each serverless service its own dedicated service account with minimal IAM permissions. Grant each role reach only to the specific backend instances that the app needs. Never reuse the default compute account across different teams or staging and production apps.
Route all outbound container traffic through a private virtual network connector. Place your target databases in isolated subnets that reject all public internet traffic. Use firewall rules that check source service accounts and restrict access to exact port numbers.
Set maximum instance counts on your serverless apps to protect downstream socket pools. Keep timeout settings aligned on both sides so half-open sockets close cleanly and fast. Finally, mask sensitive fields like emails, phone numbers, card numbers, and national IDs in query results.
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
Can serverless containers accept inbound raw TCP traffic directly?
No, standard serverless endpoints only accept HTTP, HTTPS, and gRPC web requests from clients. To handle raw sockets, you must place an external load balancer in front or tunnel TCP inside HTTP.
How do you prevent containers from exhausting backend database sockets?
Set a hard limit on the maximum number of container instances that can scale up. Pair that cap with a connection pooler that shares a fixed number of backend sockets.
Do you need a virtual private network connector for private TCP backends?
Yes, unless you use a dedicated sidecar tunnel that authenticates over public cloud APIs. Direct private IP routing requires a network connector or direct VPC egress setup on the service.
Short role checks help teams work fast. Simple rules make each review clear. Good logs keep every team safe. Scoped keys stop bad changes early.
Related guides
In this post