The Simplest Way to Make Cosmosdb and Linkerd Work Like They Should
Running cosmosdb and linkerd together secures traffic from your cluster to Azure data stores. This setup gives your team encrypted pod traffic and clear metrics for database calls. Linkerd handles traffic inside the cluster using lightweight sidecars on every pod. Azure Cosmos DB lives outside the cluster as a managed cloud database. Making them work together requires clear egress rules and strict identity scoping. How cosmosdb and linkerd handle identity and data flow Data starts in your app
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.
Running cosmosdb and linkerd together secures traffic from your cluster to Azure data stores. This setup gives your team encrypted pod traffic and clear metrics for database calls. Linkerd handles traffic inside the cluster using lightweight sidecars on every pod. Azure Cosmos DB lives outside the cluster as a managed cloud database. Making them work together requires clear egress rules and strict identity scoping.
How cosmosdb and linkerd handle identity and data flow
Data starts in your app pod and passes through the local Linkerd sidecar. Linkerd uses mutual TLS to secure traffic between pods inside the cluster. Still, Cosmos DB sits outside the cluster on Azure cloud networks. When a pod calls Cosmos DB, traffic leaves the mesh as external egress. Linkerd does not extend mesh mutual TLS to external cloud databases. Instead, the app SDK must open a standard TLS session to Azure.
Identity also works at two separate layers in this architecture. Linkerd checks pod identities using cluster service accounts for internal calls. Cosmos DB checks cloud identities using Azure role assignments or master keys. Your app pod needs a valid cloud identity to read or write data. Teams often link cluster service accounts to Azure managed identities for this step. The app gets a token from Azure and sends it to Cosmos DB. Linkerd watches the TCP stream and records latency and byte counts.
Common failure modes and how to scope network paths
A common failure happens when Linkerd tries to probe external database ports. If port rules are wrong, the sidecar may block or drop the call. Teams fix this by marking the database port as an opaque port. Or they add the database subnet to the Linkerd skip list for outbound traffic. Skipping outbound ports stops the sidecar from breaking the TLS handshake with Azure. Still, skipping ports also means you lose mesh metrics for those calls.
Another major risk comes from shared master keys in app settings. Many teams put one broad Cosmos DB key into a cluster secret. Every pod in the namespace then shares the same admin database rights. If one pod gets breached, the attacker can read or delete all data. Worse, database logs only show the shared key, not the human or pod.
CosmosDB RBAC + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
To fix this, give each service its own workload identity and narrow role. Scope each role down to the exact database container the app needs. Use private endpoints so traffic stays on the cloud backbone network. Lock down network policies so only approved pods can reach the database IP. For human debug work, avoid handing out static database keys to engineers. Track every query and mask sensitive fields like emails or card numbers in results.
Auditing human and service queries outside the mesh
Linkerd tracks service traffic well, but engineers still need direct database access. During an incident, a developer may run queries from a laptop or pod. Linkerd only sees raw TCP bytes for external TLS calls to Azure. It cannot log the exact query text or mask sensitive data fields. Teams need a clear way to verify identity and log every database action. Putting strict controls on database sessions closes the gap left by service meshes.
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
Does Linkerd encrypt traffic all the way to Cosmos DB?
No, Linkerd mutual TLS only runs between pods inside your cluster. Your app SDK handles the TLS encryption to the external Azure endpoint.
Why do Cosmos DB calls fail after adding the Linkerd sidecar?
Protocol detection can conflict with external TLS handshakes on non-standard ports. Marking the port as opaque or skipping outbound ports fixes the issue.
How should pods log in to Cosmos DB without static keys?
Use Azure workload identity tied to each Kubernetes service account. Grant each identity a narrow role on only the required database containers.
Related guides
In this post