How to Configure Cosmos DB Row Level Security
You set up cosmos db row level security by tying role rules to specific partition keys. The database engine does not have a built-in row filter like SQL tables do. Teams must build these filters using cloud identity roles or scoped resource tokens. Most teams start by giving apps and engineers broad read or write roles. Broad roles let one user read every item inside a shared container. How cosmos db row level security works This database stores items inside containers and groups them by a pa
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 set up cosmos db row level security by tying role rules to specific partition keys. The database engine does not have a built-in row filter like SQL tables do. Teams must build these filters using cloud identity roles or scoped resource tokens. Most teams start by giving apps and engineers broad read or write roles. Broad roles let one user read every item inside a shared container.
How cosmos db row level security works
This database stores items inside containers and groups them by a partition key. To limit what a user can read, you must scope permissions to that key. You can do this in two main ways within the cloud platform.
First, you can use cloud identity roles with fine-grained data actions. You create a role assignment and add a condition that checks the partition key. When a user logs in, the database checks their identity token against this rule. If the query asks for a different partition key, the database blocks the read.
Second, you can use native database users and resource tokens. Your app backend checks who the user is and asks the database for a token. You scope this token to one container and one specific partition key value. The client app then uses that short-lived token to read only its own items.
Both paths require a good partition key design from day one. If you group all tenant data under one key, native rules cannot split the items. You would have to filter rows inside your app code instead.
What native partition scoping solves and where it falls short
Scoping permissions to a partition key works well for multi-tenant apps. It keeps one customer from reading another customer's items at the storage layer. You do not have to write extra filter logic into every single app query.
Still, this setup only decides who can log in and which partition they can touch. It does not check what individual queries do in flight once a session starts. This leaves a major gap when engineers, support staff, or AI tools run queries.
Row-Level Security + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Engineers often need to check data across many partitions to fix a bug. Giving them a token for every single partition key takes too much time. Teams end up giving staff broad read roles across the whole container instead.
Once an engineer has container-wide access, native rules cannot hide sensitive fields inside an item. Every query returns the full JSON document, including emails, phone numbers, and card numbers. Native roles also cannot require peer approval before someone runs a delete command.
How to plan your partition design for data access
Before you write any role rules, look at how your items are grouped. Pick a partition key that matches your security boundary, like a tenant ID or user ID. This lets your identity rules map straight to one partition key value.
Keep sensitive fields in mind when you design your item layout. Since native rules return the whole item, you may need to split secret data out. Some teams put public profile data in one container and billing data in another. You can then assign strict role rules to the billing container alone.
Review your role assignments often to find accounts with broad container permissions. Replace static master keys in your apps with scoped identity roles right away. Master keys bypass all partition rules and give full control over the account.
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 sits inline in the wire protocol beside those services as an open-source proxy, a sidecar for your Postgres or API. On every query an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run, and hoop.dev data masking rewrites matched sensitive values in responses 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 Cosmos DB have native row level security like SQL Server?
No, it does not use SQL row predicates to filter table rows. Instead, you limit data access by scoping permissions to specific partition key values.
Can I restrict access to a single JSON field inside an item?
Native roles and resource tokens apply to the whole item, not single fields. To hide emails or card numbers in results, you need dynamic data masking in flight.
Why do master keys bypass partition key rules?
Master keys grant full admin control over the whole database account. To enforce partition rules, apps and users must log in with identity tokens or resource tokens.
Related guides
In this post