How to Configure Couchbase Row Level Security
You set up couchbase row level security by splitting data into scopes and collections. You can also filter records inside your app logic or query views. Most teams start by granting role access to a whole bucket or collection. When roles are too broad, one user can read every document in that group. A simple bug or a broad query can then expose private user records. How to set up couchbase row level security Unlike relational databases, this document store does not filter single rows with nat
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 couchbase row level security by splitting data into scopes and collections. You can also filter records inside your app logic or query views. Most teams start by granting role access to a whole bucket or collection. When roles are too broad, one user can read every document in that group. A simple bug or a broad query can then expose private user records.
How to set up couchbase row level security
Unlike relational databases, this document store does not filter single rows with native policies. Instead, it controls who can read data at the bucket, scope, and collection levels. To restrict document reads, teams group records into separate collections by tenant or department. Next, admins create database roles that point to one specific scope or collection. They assign those roles to app accounts or human users who log in.
When a single collection holds mixed data, teams must build filter rules in code. Every query that the app sends must include a clause that checks user identity. Some teams also build custom API services that sit in front of the cluster. These services check the user token and append a filter before running any query. Both methods need strict code reviews so developers never forget a filter clause.
Teams also use query views or functions to limit which documents a user gets. The admin grants permission to run the function instead of reading the raw collection. Inside the function, a query checks the user name and returns matching records. This setup mimics row rules, though it adds extra database objects to maintain.
What native collection roles solve and miss
Native scopes and collections work well when you have a small number of tenants. They let you isolate big groups of documents using built-in database roles. If an app only needs data from one tenant, collection roles block outside reads. This setup stops a service account from touching collections that belong to other teams.
Still, collection limits break down when thousands of users share the same collection. You cannot create a separate collection for every single customer or support agent. Also, developers and analysts often log in with shared roles to fix production bugs. Native roles decide who can log in and read a collection as a whole. They do not inspect what individual queries do in flight during a live session.
Row-Level Security + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Once an engineer has read access to a collection, every document is open. If they run a broad query, the database returns all fields in those documents. Sensitive fields like emails, phone numbers, card numbers, and national IDs come back intact. Native collection roles cannot rewrite matched fields in results or pause risky delete statements.
Managing document access across engineering teams
Relying on app code for document security leaves a gap during manual database debugging. Support engineers and data analysts bypass the app layer when they run direct queries. If they share a database login, audit logs cannot show who ran which query. You only see the shared role name in the cluster log, not the person.
Maintaining custom query functions for every table and role also slows down schema changes. When a product team adds a new document type, admins must write new functions. If an admin makes a mistake in a filter clause, private data leaks out. Teams need a way to inspect queries and mask fields at the statement level.
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 Couchbase have built-in row level security policies?
No, the database does not offer native row policies like some relational systems do. Instead, you isolate data using scopes, collections, query functions, or app-level query filters.
How do scopes and collections help restrict document access?
Scopes and collections let you group related documents inside a bucket and assign roles. A user with a collection role can only read or write documents inside that collection.
How can teams protect sensitive fields inside shared collections?
When users query a shared collection, dynamic data masking can rewrite matched fields in results. This replaces emails, phone numbers, card numbers, or national IDs during the query session.
Related guides
In this post