Most RAG systems copy company documents into a vector store and lose the permissions on the way. permission-aware-rag syncs documents and their access permissions, and enforces them inside Postgres with row-level security, so a query can only ever see chunks the asking user may open in the source system.
Every chunk stores the principals allowed to read it: users, groups, domains, public and repository teams. A user is expanded into every principal they hold through nested groups, and each query runs in a read-only transaction that tells Postgres those principals. Even a query with no WHERE clause cannot see past the policy, and the query connection is checked on connect so it cannot bypass row-level security.
Search takes one of two paths, both under row-level security: exact for readers who can see little, so recall stays complete, and HNSW for wide readers. A background worker keeps documents current from each source's change feed, identity poll and a periodic reconcile; a source that falls behind is hidden until it catches up, and an expired share stops working at its expiry by the database clock.
The sources are faithful fakes of Google Drive, Confluence and GitHub, each with an oracle that answers "can this person open this?" from the product's native rules. Property-based leak tests run 10,000 random sequences of permission changes in CI and check every step against the oracles, and the time a revocation takes to reach search is measured per source and kind of change. Embeddings run on a local model by default, so no API key is needed.