feat(plugins): sandbox hardening — OS permission model, egress choke point, bound acting user, author signatures

Closes the four gaps the security review surfaced:

- OS permission model on the prod plugin child (Node --permission with
  fs-read scoped to the compiled server dir + the plugin's own code dir, no
  fs-write/child_process/worker/native). A plugin can no longer read trek.db
  or the .jwt_secret/.encryption_key files, nor shell out — the direct-fs and
  RCE escapes that bypassed the RPC layer. Opt-out via TREK_PLUGIN_PERMISSIONS=off.
- Egress guard extended from fetch to the net.Socket connect choke point, so
  node:http/https/net/tls obey the declared-egress allowlist too (no declared
  egress = no outbound). Under the permission model there is no clean escape to
  an unwrapped runtime. Kernel/network-namespace containment remains the
  container step.
- Trip reads are membership-checked against the acting user the HOST binds from
  the authenticated invocation, not an asUserId the plugin supplies; a job/onLoad
  (no user) can't read user-scoped trips.
- Optional minisign (Ed25519) author signatures verified offline, TOFU-pinned
  (migration 158). Unsigned plugins install on sha256 alone; a signed plugin
  can't silently drop its signature or swap its author key.

Server suite green (permission-model activation verified against the Koffi
reference plugin on dev1).
This commit is contained in:
Maurice
2026-07-04 00:31:01 +02:00
committed by Maurice
parent 45ef63cbc1
commit 332e5c3c42
17 changed files with 565 additions and 80 deletions
+9 -7
View File
@@ -16,7 +16,9 @@ function fakeTransport() {
describe('createPluginContext', () => {
it('maps each ctx method onto the right RPC call', async () => {
const { transport, rpc } = fakeTransport();
const ctx = createPluginContext('p', {}, transport);
// An invocation-scoped ctx: trip reads carry `_inv` so the host can bind the
// acting user to this invocation.
const ctx = createPluginContext('p', {}, transport, 'inv-1');
await ctx.db.query('SELECT 1', 'a');
expect(rpc).toHaveBeenCalledWith('db.query', { sql: 'SELECT 1', args: ['a'] });
@@ -24,8 +26,8 @@ describe('createPluginContext', () => {
await ctx.db.migrate('001', 'CREATE TABLE t (x)');
expect(rpc).toHaveBeenCalledWith('db.migrate', { id: '001', sql: 'CREATE TABLE t (x)' });
await ctx.trips.getById(1, 42);
expect(rpc).toHaveBeenCalledWith('trips.getById', { tripId: 1, asUserId: 42 });
await ctx.trips.getById(1);
expect(rpc).toHaveBeenCalledWith('trips.getById', { tripId: 1, _inv: 'inv-1' });
await ctx.ws.broadcastToTrip(1, 'ping', { a: 1 });
expect(rpc).toHaveBeenCalledWith('ws.broadcastToTrip', { tripId: 1, event: 'ping', data: { a: 1 } });
@@ -36,11 +38,11 @@ describe('createPluginContext', () => {
await ctx.db.exec('DELETE FROM t');
expect(rpc).toHaveBeenCalledWith('db.exec', { sql: 'DELETE FROM t', args: [] });
await ctx.trips.getPlaces(1, 42);
expect(rpc).toHaveBeenCalledWith('trips.getPlaces', { tripId: 1, asUserId: 42 });
await ctx.trips.getPlaces(1);
expect(rpc).toHaveBeenCalledWith('trips.getPlaces', { tripId: 1, _inv: 'inv-1' });
await ctx.trips.getReservations(1, 42);
expect(rpc).toHaveBeenCalledWith('trips.getReservations', { tripId: 1, asUserId: 42 });
await ctx.trips.getReservations(1);
expect(rpc).toHaveBeenCalledWith('trips.getReservations', { tripId: 1, _inv: 'inv-1' });
await ctx.ws.broadcastToUser(9, 'poke', { x: 2 });
expect(rpc).toHaveBeenCalledWith('ws.broadcastToUser', { userId: 9, event: 'poke', data: { x: 2 } });