The Simplest Way to Make Azure Cosmosdb and Microsoft Entra ID Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams link azure cosmosdb and microsoft entra id to manage database logins with user identities. This setup replaces shared master keys with role checks for every person and app. In production, this workflow lets developers and services read or write data using temporary tokens. Security teams can control who reaches each database account from one central directory. When someone leaves the team, removing their directory user blocks their database sessions right away. How azure cosmosdb and mi

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.

Teams link azure cosmosdb and microsoft entra id to manage database logins with user identities. This setup replaces shared master keys with role checks for every person and app.

In production, this workflow lets developers and services read or write data using temporary tokens. Security teams can control who reaches each database account from one central directory. When someone leaves the team, removing their directory user blocks their database sessions right away.

How azure cosmosdb and microsoft entra id handle logins and roles

The login flow starts when a user or app asks the directory for a token. Microsoft Entra ID checks the user identity and returns a signed token with short life. The client app sends this token with its database request to the Azure CosmosDB account.

Next, the database checks the token signature and looks up the assigned roles for that identity. Azure CosmosDB splits permissions into two distinct planes for management and data operations. Control plane roles let admins create databases, change throughput, or update network rules in the portal. Data plane roles control who can read, write, or delete items inside specific containers.

Managed identities make this flow work well for apps that run inside the cloud. You assign a system identity to your compute service and grant it a data role. The app gets tokens on its own, so engineers do not store secrets in files.

Common failure modes and how to scope roles and network paths

Many teams still leave primary master keys turned on after they set up identity logins. If an engineer puts a master key into a script, anyone with that file gets full control. You should turn off local key logins on the database account to stop this bypass.

Another common issue is giving broad data roles to every developer on the team. When everyone holds write permissions across all containers, one bad query can wipe out production items. Instead, scope roles down to the exact database or container each group needs to read.

Microsoft Entra ID (Azure AD) + CosmosDB RBAC: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Shared service accounts also create blind spots in your security logs during an incident. When ten engineers use the same app identity to run queries, logs show only one name. Require individual user logins for human work so every query maps to a real person.

Database logs often miss the full details of who read sensitive fields during a session. If a table holds emails, phone numbers, card numbers, or national IDs, raw queries return them. Adding data masking rewrites matched fields in results before they reach the client screen.

Finally, lock down network paths so tokens alone cannot reach the database from public networks. Use private endpoints to keep all database traffic inside your virtual network boundaries. Pair private network routes with conditional directory rules that check device health before issuing tokens.

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 we disable master keys completely in Azure CosmosDB?

Yes, you can turn off local key logins in the database account settings. Once turned off, all users and apps must send a valid directory token to run queries.

What is the difference between control plane and data plane roles?

Control plane roles manage the account itself, such as creating containers or changing settings. Data plane roles let users and apps read, write, or delete the actual records inside containers.

How do we audit who ran a specific query?

Enable diagnostic logs on the database account and send them to your central log workspace. Each data plane log entry records the directory principal ID and the operation it ran.

The query runs. The emails stay hidden.