The Simplest Way to Make Caddy and Cosmosdb Work Like They Should
Running caddy and cosmosdb together routes web traffic to fast cloud data stores. This setup lets your web server handle TLS while backend apps read and write records. Teams choose Caddy because it manages web certificates with very little manual work. They pair it with Azure CosmosDB to store JSON documents across many cloud regions. Yet putting these two tools together brings real security and network challenges. You must control how traffic flows and how each app logs in to the database. H
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 caddy and cosmosdb together routes web traffic to fast cloud data stores. This setup lets your web server handle TLS while backend apps read and write records.
Teams choose Caddy because it manages web certificates with very little manual work. They pair it with Azure CosmosDB to store JSON documents across many cloud regions. Yet putting these two tools together brings real security and network challenges. You must control how traffic flows and how each app logs in to the database.
How data and permissions flow between caddy and cosmosdb
In a standard setup, Caddy sits at the edge of your network. It takes incoming HTTPS requests from users and checks their TLS certificates. Caddy does not talk to the database on its own in most setups. Instead, it forwards clean requests to a backend app service over a private network.
That backend app then opens a session to CosmosDB using an SDK or REST API. To log in, the app needs either a master key or an Azure role. Cloud identity roles are much safer than static master keys for daily runs. When you use cloud roles, the app gets a short token from Azure Active Directory. The database checks this token before it allows any read or write action.
Some teams also put Caddy in front of the CosmosDB REST endpoint for internal tools. In this path, Caddy terminates TLS and routes internal calls to the database URI. Even here, the calling tool must still send valid auth headers for CosmosDB to check.
Common failure modes and how to scope roles
The biggest mistake teams make is sharing one primary master key across all apps. A master key gives full admin control over every container and item. If a developer leaks that key in a log file, anyone can wipe your data. You also lose track of which person or app ran a bad query.
Another common issue is leaving the database open to all public IP addresses. Even with strong keys, public database endpoints invite constant automated attacks. You should lock down the network path between your app tier and the database. Set up private endpoints inside your virtual network so traffic is masked in responses before reaching the public internet.
CosmosDB RBAC + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Next, replace shared keys with narrow role assignments for each backend service. Give read-only roles to reporting apps so they cannot change or delete records. Give write roles only to the specific services that need to save new user data. If engineers need to run manual checks, map their individual user logins to strict roles.
Keeping logs and masking sensitive fields
Good security requires clear logs of both web requests and database queries. Caddy writes structured web logs that show who called your API and when. On the database side, you should turn on diagnostic logs in your cloud portal. These logs record every query, point read, and role change across your containers.
Be careful not to write sensitive user data into your plain text web logs. Your database containers often hold private fields like emails, phone numbers, and card numbers. If an engineer queries a container for support, data masking rewrites matched fields in results. This keeps raw card numbers and national IDs out of local screens and log files.
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 Caddy talk directly to the CosmosDB REST API?
Yes, Caddy can route HTTP traffic to the database REST URI. Still, the client app must still build and sign the required Azure auth headers.
Should we use master keys or Azure roles for app logins?
Always use Azure roles and managed identities for your apps and engineers. Master keys grant too much power and are hard to rotate without downtime.
How do we stop public traffic from hitting our database?
Turn off public network access in your cloud database settings right away. Use private endpoints so only your internal app subnet can reach the data store.
Related guides
In this post