The Simplest Way to Make Azure Active Directory and Azure Cosmosdb Work Like They Should
Pairing azure active directory and azure cosmosdb lets teams control database access with user identities. This setup replaces shared master keys with short-lived tokens for apps and engineers. Master keys give broad access to all data and settings in a database account. When teams share those keys in chat or config files, they lose track of who ran which query. Linking your directory to your database fixes this gap. Every person and app logs in with a single identity. You can then grant read o
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.
Pairing azure active directory and azure cosmosdb lets teams control database access with user identities. This setup replaces shared master keys with short-lived tokens for apps and engineers.
Master keys give broad access to all data and settings in a database account. When teams share those keys in chat or config files, they lose track of who ran which query. Linking your directory to your database fixes this gap. Every person and app logs in with a single identity. You can then grant read or write rules down to the container level.
How azure active directory and azure cosmosdb handle identity and data
The workflow between azure active directory and azure cosmosdb splits control tasks from data tasks. Control tasks include making new databases, changing network rules, or setting up backup policies. Data tasks include reading items, writing records, and running queries inside containers. Cloud admins often handle control tasks first, then forget to lock down data tasks.
When a user or app needs data, it asks the directory for a token. The directory checks the user identity and returns a signed token with a short lifespan. The client app sends this token with each request to the database. The database checks the token against its internal role list before it runs the query.
Apps that run in the same cloud can use managed identities for this flow. A managed identity ties the app straight to a directory record without a stored secret. The cloud rotates the underlying credentials in the background on a set schedule. Engineers do not need to copy secrets into build pipelines or local files.
Common failure modes and how to scope roles
Many teams still fall back on the primary master key during local testing. Developers copy the connection string into a local file to make an app work fast. That key bypasses directory roles and gives full write rights to the whole account. If a laptop gets lost or a repo leaks, the attacker gets total control.
Another common risk comes from broad directory roles given to shared service accounts. If five microservices share one identity, you cannot tell which service caused a spike. You also cannot block one broken service without taking down the other four. Each app and team member needs a distinct identity with narrow permissions.
Active Directory + Azure RBAC: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
To fix this, admins should disable local key access on the database account. This rule forces every request to bring a valid directory token. Next, separate your control plane roles from your data plane roles. An engineer who needs to read items for support does not need rights to delete containers.
You should also lock down network paths between your apps and your database. Public endpoints expose your data plane to login attempts from anywhere on the internet. Private endpoints keep traffic inside your virtual network and block outside requests by default. Combine private network paths with directory roles to build a strong defense.
Even with role checks in place, native logs can miss item-level details. Turning on full diagnostic logs for every read request creates huge storage bills. Teams also struggle to hide sensitive fields like emails, phone numbers, or card numbers in query results. You need a clear way to inspect queries and rewrite sensitive fields on the fly.
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
Can we disable master keys completely in Azure CosmosDB?
Yes, you can turn off local key logins in the database account settings. Once turned off, every user and app must log in with a directory token.
What is the difference between control plane and data plane roles?
Control plane roles manage the database account, network rules, and container setup. Data plane roles control who can read, write, or delete items inside those containers.
How do we protect sensitive fields when engineers query containers?
Native roles grant access to whole containers rather than single item fields. To hide emails or card numbers in results, apply data masking rules during the query session.
Related guides
In this post