The Simplest Way to Make Active Directory and Cosmosdb Work Like They Should
You link Active Directory and CosmosDB by mapping user groups to database roles. This setup lets your team log in with work accounts and skip shared keys. In many shops, devs copy primary database keys into local files to run tests. That habit creates big security risks when people change teams or leave the company. Linking your directory service to your cloud database fixes this identity gap right away. Now every person and app uses a single identity to read or write data. How active directo
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 link Active Directory and CosmosDB by mapping user groups to database roles. This setup lets your team log in with work accounts and skip shared keys.
In many shops, devs copy primary database keys into local files to run tests. That habit creates big security risks when people change teams or leave the company. Linking your directory service to your cloud database fixes this identity gap right away. Now every person and app uses a single identity to read or write data.
How active directory and cosmosdb share identity and permissions
The link between active directory and cosmosdb relies on token exchange and role assignments. First, a user or app logs in to the directory service to prove identity. The directory checks the user rules and issues a signed token with group claims. Next, the client app sends this token along with the query to the database.
The database checks the token signature and reads the role claims inside the payload. You must set up two layers of rules inside the cloud database account. The control plane rules govern who can change database settings, backups, and network rules. The data plane rules govern who can read, write, or delete actual JSON documents.
Admins map directory security groups directly to these specific data plane role definitions. When a developer joins a group, they get the matching database rights right away. When an admin removes them from the group, their database permissions stop working fast. This flow removes the need to rotate master keys every time staff changes.
Common failure modes and how to scope roles
Many teams still fail by handing out broad contributor roles to every single developer. A broad control plane role often lets users view the master database keys anyway. Once a user grabs a master key, they bypass all directory role checks completely. You must lock down control plane roles so regular users cannot read account keys.
Shared service accounts cause another major headache for security and audit teams in production. When five apps share one directory identity, the audit logs become very hard to read. You cannot tell which app ran a slow query or wiped a document collection. Give every single app and microservice its own managed identity in the directory instead.
Active Directory + CosmosDB RBAC: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Unlogged queries also hurt teams when sensitive customer data lives inside the document store. Directory logs show who asked for a token, not what data they pulled back. You should turn on diagnostic logs to record every data plane request and response. You can also set up data masking to rewrite emails and card numbers in results.
Setting up clean network paths and daily workflows
Identity rules work best when you pair them with tight network paths in production. Turn off public network entry on the database so outside traffic hits a wall. Use private endpoints to keep all database traffic inside your own virtual network space. This step stops attackers from using a stolen token from a home laptop.
Keep human users out of production data during normal daily work whenever you can. Let automated deployment tools handle schema changes and index updates through their own identities. When an engineer needs to fix a live bug, grant temporary group membership only. Remove that group membership as soon as the ticket closes to keep rights minimal.
Govern statements and responses across databases and APIs
Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.
First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.
Frequently asked questions
Can we turn off local master keys in CosmosDB completely?
Yes, you can disable local key access in the database account settings. This setting forces every user and app to use directory tokens for all requests.
What is the difference between control plane and data plane roles?
Control plane roles manage the database account, such as adding regions or changing throughput. Data plane roles control who can read, write, or delete items inside containers.
How do we protect PII like phone numbers in document queries?
Role assignments only block or allow full container access for a given user identity. To hide specific fields like phone numbers or national IDs, use dynamic data masking.
Related guides
In this post