Skip to content

Dispatch function owner: isolated role experiment

Status: isolated proof of mechanics, not production provisioning or a production dispatch API. Run tests/dispatch_function_owner_poc.sh; it uses a disposable PostgreSQL container and temporary Rails copy. It does not change the development database, enable a provider or prove tenant authorization.

A non-login, non-superuser, non-BYPASSRLS role receives schema USAGE and INSERT on one RLS-protected test table. An administrator temporarily grants schema CREATE to transfer ownership of a specific SECURITY DEFINER test function to this role, immediately revokes CREATE, and grants app EXECUTE only on that function. The app cannot assume the function-owner role or directly write the table. The function uses a fixed search path and checks that its requested tenant matches transaction-local context; forced RLS applies to the function owner. A second routine is not granted to the app.

A Rails SQL dump and restore omit owner and ACL metadata. In the experiment, restore therefore initially makes the migration role the function owner, and our existing restore hook closes execution to the app. A test-only admin reconciliation transfers ownership and grants one signature after restore. This proves a possible mechanism, not a secure production reconciliation: the experiment does not authenticate a function body against a trusted manifest, check every owner/grant/overload or implement deployment and rollback.

Tests exercise valid context, missing or mismatched context, direct app table writes, unapproved function execution, role assumptions, restricted owner capabilities and a foreign-tenant RLS write under the owner role. The app can still set its own tenant context; this mechanism does not protect against a compromised app identity or validate product authorization. The fixture has no real selection, grouping, immutable dispatch graph or external transport.

Current infra/docker/postgres/provision.sql deliberately rejects any app-executable routine in notifi_dispatch. The test confirms provisioning fails after the test-only allowlist grant. Thus the current fail-closed restore and provisioner are safe defaults but do not yet support an authorized creation function. A separate owner and a function grant must not be enabled in the real environment until provisioning and restoration agree on the same explicit policy.

  • Design administrator-controlled creation and verification of the NOLOGIN role, exact capabilities, memberships, owners and secret-free lifecycle; the migration role cannot create roles by itself.
  • Define one versioned, reviewed allowlist of exact routine signatures, expected owners and approved definitions/security properties. Validate before granting, fail closed on unexpected routines, overloads, ownership, search paths or inherited privileges, and prevent an attacker from changing the manifest.
  • Coordinate fresh migration, Rails dump/restore, routine ownership transfer, app EXECUTE grants, provisioning reruns and rollback. Ensure no partially reconciled capability is externally observable; do not broaden PUBLIC access.
  • Test real migration and app roles, concurrent/failed restore and reconciliation, routine tampering, direct table access, tenant boundaries, RLS, schema owner and all grants. A SQL function grant alone is not product authorization.
  • Specify how future worker identities and retention operations get only their own necessary permissions. The production function still needs the complete sealed-graph and idempotency design and tests.