How it works
Core concept: Create a separate access control table that defines which users and teams can access which documents. Use foreign filters to enforce these permissions at query time. Tenant tokens carry user identity:Data structure
Access control table
Create a separate “access” index to define permissions:Main documents
Documents reference the access control table:Setting up relationships
- Create access control index with documents defining who can access what
- Add foreign key to your main index pointing to access table:
- Configure filterable attributes on access table:
Using tenant tokens with RBAC
The tenant token contains the authenticated user’s identity:Multi-level RBAC example
Combine user, team, and role filtering:- Jeremy has editor or owner role, OR
- Product/engineering teams have at least editor role
Handling wildcard access
For public documents, setteams = ["*"] in the access table:
Performance considerations
- Access table size: Each document’s access rules create entries. For 1000 documents with 10 team access rules each, you need ~10,000 access records.
-
Filter specificity: The foreign filter must match ≤ 100 access records. Design your access control structure to stay within this limit:
- Use team-based rules instead of per-user rules where possible
- Group documents by access level (public, internal, secret)
- Consider combining user + team checks:
(user = "..." OR (teams IN [...] AND roles IN [...]))
- Denormalization trade-off: If RBAC queries regularly hit the 100-document limit, consider denormalizing permission fields directly into documents instead of using joins.
Security best practices
- Token validation: Always validate tenant tokens server-side before searching
- Immutable filters: Construct the filter on the server, never client-side
- Scope limitation: Limit token expiration and use short-lived tokens when possible
- Audit logging: Log access attempts for compliance and debugging
- Regular review: Periodically audit access control table entries to remove stale permissions
Example: Implementing on the server
Next steps
Tenant tokens
Learn how to generate and manage tenant tokens
Foreign filters
Understand foreign filter syntax and capabilities
Define relationships
Set up join relationships for RBAC