pg_rebac mirrors SpiceDB's relationships into an indexed readable set. Put it in yourwhere clause and Postgres plans it as one more join, so the fence applies before theorder by and the limit.
Slice 1, pre-release. Running in shadow at Louvain.
begin;
set local rebac.tenant = 'acme';
set local hnsw.iterative_scan = relaxed_order;
select id, body
from passage
where container in (select * fromrebac.readable_set('priya'))
order by embedding <=> $1
limit 20;
commit;
What Postgres plans
Limit
InitPlan 1 -- (select rebac.checked('priya')), evaluated once-> Result
One-Time Filter: (InitPlan 1).col1
-> Nested Loop
-> Index Scan using passage_embedding_idx on passage
Order By: (embedding <=> '[…]'::vector)
-> Index Only Scan using readable_pkey on readable r
Index Cond: ((tenant = (InitPlan 2).col1)
AND (principal = 'priya'::text)
AND (container = passage.container))
explain (costs off) on Postgres 17 and pgvector 0.8, with two InitPlan result lines left out and the long line wrapped. The HNSW scan stays outside; each candidate costs one primary-key probe.
Why it exists
Fenced vector search in 4 to 7 ms
Readers who can see 5% to 50% of a tenant got all k rows at recall 0.90 to 0.96, against 1.9 ms for the same search unfenced.
500,000 passages, HNSW at pgvector defaults, k = 20, hnsw.iterative_scan = relaxed_order, one 4-CPU machine with everything cached. Readers below about 1% take the exact path instead, 1.6 ms at full recall. The study and its method
Revocations in force at commit
Write relationships with rebac.write in your own transaction. A deferred trigger removes the revoked containers from the projection before the commit, whether or not SpiceDB or the daemon is up.
Exact for direct relations, arrows to another type, and subject-set memberships. Removing an arrow or a grant to a set narrows at commit or at the relay's next pass. Writes made outsiderebac.write are narrowed by the sweep. What is guaranteed
Three answers, never an accidental empty set
A permission filter that returns nothing when it is broken looks exactly like one that is working. pg_rebac keeps the cases apart.
RB404
Never asked. Nobody has projected this principal yet. Ask the daemon'sPOST /lookup, then retry.
{ }
Nothing. Asked, and this principal can read nothing. An empty set means exactly that.
RB503
Unavailable. The projection is stale, over its cap, or SpiceDB could not be asked. The read fails closed.
Pure SQL, and a daemon to keep it in step
The schema is one SQL file
Plain SQL and PL/pgSQL, no C extension, so it installs on Postgres 14 or later, hosted or not. The reads, the narrowing trigger, the queues and the checks all live there.
rebacd talks to SpiceDB
A Rust daemon relays the outbox in order, refreshes principals, backfills tenants, and runsrebacd verify, which diffs the projection against SpiceDB and exits non-zero on any extra row. Shadow mode proves a projection before anything reads it.
Install
# the schema, on any Postgres 14+
psql -v ON_ERROR_STOP=1 -f sql/rebac.sql
# the daemon
cargo build --release -p rebacd
DATABASE_URL=postgres://… SPICEDB_TOKEN=… \
./target/release/rebacd --config rebac.toml run