Conversation
prvnsmpth
marked this pull request as draft
April 26, 2026 12:58
Replace application-side permission predicates with PostgreSQL RLS on documents, embeddings, and content_blobs. Requests run in transaction-local context as omni_documents_user with the viewer email/scope, while background services use a privileged omni_documents_system role. - Migration 112: RLS + FORCE policies, fail-closed helper functions, hardened document roles; deactivates admin-scoped API keys and limits new keys to public/user scope - run-migrations.sh: provisions separate user/system runtime logins so a user-facing service can never assume the system document role - shared: DatabasePool gains a system pool and begin_document_user/system helpers; DocumentRepository scopes reads by role - searcher: user/public/system access scopes, internal-token requirement on identity-bearing endpoints, system-scoped storage/typeahead reads - AI: user/system connection contexts; embedding and storage repositories use the system pool; system scope requires the internal token - web: per-request RLS-scoped db, public/user API-key scopes only, RLS-filtered aggregates and document reads - tests: RLS permission/role-separation integration tests, permission-filter and API-key scope unit tests, CI security job; AI integration tests updated to seed real group memberships (RLS resolves groups from the DB) - docs: deployment/rollout guide
CI wiring for the RLS regression tests will be introduced later; keep the tests in the repo but do not run them in CI yet.
Merge the login and role: user-facing services log in as omni_user and background services as omni_system directly, instead of a login role that switches to a NOLOGIN role via SET ROLE. This removes the SET ROLE switching entirely and makes the privilege boundary structural (omni_user holds no membership in omni_system). - migration 112: create omni_user/omni_system as LOGIN roles with their table grants; policies and current_user guards use the new names - run-migrations.sh: only provisions passwords (privileges live in the migration) - shared pool: drop OMNI_DOCUMENT_DATABASE_ROLE and system-pool SET ROLE; begin_document_user/system keep SET LOCAL ROLE as a no-op for prod and a switch for owner connections in tests - AI connection.py, web hooks, indexing status: updated role names - compose/env/docs/tests: renamed references
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Move document permission filtering from application code into PostgreSQL row-level security (RLS).
documents,embeddings, andcontent_blobsare now protected at the database level, so all read paths (search, typeahead, direct reads, AI tools, aggregates) get the same authorization automatically.High-level changes
documents/embeddings/content_blobswith fail-closed semantics; permissions evaluated from the existing{public, users, groups}document ACL.omni_userfor all user-facing services (web, searcher, AI) andomni_systemfor background/indexing/storage work. NoSET ROLEswitching — a user-facing service holds no membership inomni_system, so there's no path to escalate to the privileged role.public/userscope on their connection; background operations useomni_system.adminkeys are deactivated; keys are nowpublic(public docs only) oruser(owner permissions).docs/document-rls-rollout.md.Validation
omni_usercannotSET ROLE omni_system, and correct public/user/system access.