The Simplest Way to Make Azure Cosmosdb and Tcp Proxies Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Using azure cosmosdb and tcp proxies together lets teams route database traffic over private networks. This setup keeps database endpoints off the public internet while apps read and write data. Teams often run cloud databases inside private virtual networks to meet strict security rules. Developers and apps still need a safe way to reach those database ports from outside. A network layer helps bridge that gap without opening public firewall rules to the world. How azure cosmosdb and tcp prox

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.

Using azure cosmosdb and tcp proxies together lets teams route database traffic over private networks. This setup keeps database endpoints off the public internet while apps read and write data.

Teams often run cloud databases inside private virtual networks to meet strict security rules. Developers and apps still need a safe way to reach those database ports from outside. A network layer helps bridge that gap without opening public firewall rules to the world.

How azure cosmosdb and tcp proxies handle traffic

Azure CosmosDB offers several ways to talk to your data, including wire protocols and HTTPS. When you use azure cosmosdb and tcp proxies, the network layer forwards raw packets directly. The client app opens a socket to the listener address on a specific port. The forwarder then sends those bytes straight to the database endpoint inside the private network.

Logins still happen between the client tool and the database engine itself. The client sends a master key, a token, or an identity token over the wire. Because the network forwarder works at layer four, it does not read the database protocol. It only sees source addresses, target addresses, and encrypted byte streams moving back and forth.

One tricky part is how the database client handles partition routing in direct mode. The database often tells the client to talk to many backend node addresses at once. Standard port forwarders struggle when the client tries to reach dozens of changing backend ports. Teams usually switch their client settings to gateway mode so traffic uses one standard port.

Common failure modes and network scoping

Relying only on raw socket forwarding creates several big security gaps for engineering teams. First, most teams end up sharing one master connection string across many users and apps. If someone leaves the team, rotating that shared key can break production jobs right away.

Second, raw socket tools cannot see which person ran a specific query or drop command. Network logs only show that a packet went from one IP address to another. Audit teams need to know who read customer records, not just when a socket opened. Also, raw network forwarders cannot rewrite sensitive fields like emails, phone numbers, or card numbers.

Azure RBAC + CosmosDB RBAC: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

To reduce risk, teams must lock down both network paths and database roles at once. Start by placing the database inside a private subnet using private endpoints on your cloud. Block all public network traffic at the database level so only internal subnets can talk. Next, stop using master keys for human users who need to check production data.

Use role-based rules tied to your cloud identity provider for every person and service. Give each app a narrow role that can only read or write specific data containers. Set up separate read-only roles for developers who only need to debug live issues. Keep network routes narrow so the forwarding host can only reach the exact database port.

Handling TLS and DNS resolution

Database clients check the server certificate name before they send any login keys or data. If a client connects to a local forwarder address, the certificate name might not match. You must set up private DNS zones so the real database hostname resolves to the forwarder. This step lets TLS checks pass without turning off certificate checks in your client code.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.

Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Why do database connections fail through a standard port forwarder?

Clients in direct mode try to reach many dynamic backend node ports that aren't forwarded. Switching the client setting to gateway mode routes all traffic through a single known port.

Can a layer four forwarder filter out sensitive data fields?

No, a raw TCP tool only moves encrypted bytes and cannot read database queries. It cannot rewrite fields like emails, phone numbers, or national IDs inside query results.

How do we avoid certificate errors when routing database traffic?

Use split-horizon DNS so the official database hostname points to your internal routing address. That way, the client sees the exact hostname listed on the server TLS certificate.

The query runs. The emails stay hidden.