Row-level and document-level access solve different resource problems. Choose the boundary that matches the underlying data, then preserve it when records become passages, indexes, previews, or generated answers.
Access granularity follows the resource model
Document-level access decides whether a principal may use an entire file or document resource. Row-level access decides which records in a structured collection may be returned or changed. Neither automatically protects derived AI artifacts.
PostgreSQL’s row-security documentation describes policies restricting visible or modifiable rows and important owner and privileged-role behaviour. Verify the actual database role and configuration rather than assuming enabling a feature covers every connection.
For a proposed design, map trusted user context to the authoritative resource policy. Decide how document fragments inherit access and how structured rows are transformed into retrieval evidence. Service credentials must not unintentionally bypass the intended boundary.
Compare fictional support resources
A general troubleshooting manual has one approved audience and can be protected as a document. Customer support notes live in a table where each row belongs to a different account. Protecting only the table or a generated combined document would expose unrelated customers.
If those rows are indexed as passages, the retrieval layer must preserve the row’s account relationship. A correct database policy does not help if an unrestricted ingestion job copies all rows into a broadly accessible search index.
| Resource | Boundary to verify |
|---|---|
| Single-audience manual | Document permission and derived chunks |
| Multi-account notes table | Row scope under actual execution role |
| Mixed-sensitivity document | Appropriate split or supported finer policy |
| Search index copy | Original resource relationships preserved |
| Generated answer cache | User and source permission context |
Test with neighbouring fictional accounts and a deliberately overprivileged service connection. Inspect both direct queries and derived retrieval paths.
Avoid false equivalence between layers
A database control can be strong within its documented scope while the application leaks through exports or caches. Document access can be appropriate for files but too coarse for mixed-account content. Review the complete data path.
Finer granularity adds metadata, policy, and testing complexity. Coarser boundaries can simplify operations when content is genuinely shared by one audience. Choose the smallest accurate model and avoid aggregating protected resources in ways that erase their distinctions.
This access comparison is proposed. The StackFlight case study describes private account data without claiming this exact row-security implementation. Pair it with document storage boundaries.
Access granularity FAQ
Does database row security protect an external index automatically?
No. Preserve and enforce the relevant relationship in every derived path.
Is document access always too coarse?
No. It can be appropriate when the whole document has one valid audience.
What should an implementation review inspect?
Check actual roles, bypass conditions, policy scope, ingestion credentials, derived metadata, and positive and negative fixtures.