Quack lets clients query a DuckDB database over the network, but it can't limit which tables or rows they see.
I wrote vcatbridge, a DuckDB extension that can. Your data stays in one DuckDB, SourceDB. You serve a second one, SharedDB, which reaches SourceDB's tables only through a policy.
Follow along here (Python, DuckDB 2.0.0): https://github.com/n6k-io/duckdb-virtual-catalog/blob/main/docs/quack-row-policies.md
The policy, set on SourceDB
SELECT vcatbridge_set_context('b1', 'tenant', 42);
SELECT vcatbridge_set_policy('b1', 'main.users', 'select', 'tenant_id = $tenant');
SELECT vcatbridge_set_policy('b1', 'main.users', 'insert', 'tenant_id = $tenant');
SELECT vcatbridge_set_policy('b1', 'main.users', 'update', 'tenant_id = $tenant');
SELECT vcatbridge_set_policy('b1', 'main.orders', 'select', 'tenant_id = $tenant');
secrets gets no policy, and nothing gets delete. Only SourceDB can change these.
What SharedDB sees
SELECT * FROM users;
-- (1, 42, 'ada'), (2, 42, 'grace')
INSERT INTO users VALUES (5, 7, 'mallory');
-- Invalid Input Error: vcatbridge: row violates the check predicate on this table
DELETE FROM users WHERE id = 2;
-- Permission Error: crossing: 'users' does not have 'delete' permission
FROM secrets;
-- Catalog Error: Table with name secrets does not exist!
secrets isn't hidden behind a permission error. It isn't in SharedDB's catalog, so there's nothing to name.
The query crosses as a plan, not SQL text
EXPLAIN SELECT name, sum(amount) FROM users JOIN orders ON id = user_id GROUP BY name;
Crossing Remote <- everything below runs on SourceDB
└─ Projection name, sum(amount)
└─ Aggregate group by name
└─ Join INNER, id = user_id
├─ Projection id, name
│ └─ Crossing Floor users
└─ Projection user_id, amount
└─ Crossing Floor orders
Each Crossing Floor is a table SharedDB doesn't scan itself. SourceDB swaps it for a scan with the row filter applied, so the filter never appears in SharedDB's plan. A function crosses only if it's on the bridge's whitelist.
Serve it over Quack, locked down
SharedDB runs quack_serve, then vcatbridge_lockdown, which takes files, network, extensions and settings away from it. From any DuckDB:
ATTACH 'quack:localhost:9494' AS app;
SELECT * FROM app.users;
-- (1, 42, 'ada'), (2, 42, 'grace')
FROM quack_query('quack:localhost:9494', 'SELECT * FROM read_csv(''/etc/passwd'')');
-- Permission Error: File system LocalFileSystem has been disabled by configuration
The threat model, including the leaks it accepts: https://github.com/n6k-io/duckdb-virtual-catalog/blob/main/SECURITY.md
It's submitted as a community extension (https://github.com/duckdb/community-extensions/pull/3570), so it's unsigned until that merges.
n6kd does all of this in one binary, with policies from a file: n6kd quack -f schema.sql --perms perms.yml. https://github.com/n6k-io/n6kd