Skip to content

0004. Migrations out of serving processes ​

Status: accepted. Applies to crates/kernel (registry, bus, migration 0002), crates/orbit-bin and deploy/.

Context ​

Until now the web process ran migrations at startup and held the owner connection, so the audited kernel.module.enable / kernel.module.disable commands could run migrations and write kernel.tenant_modules, which the runtime role cannot. A compromise of the web process was therefore a compromise of every schema and policy.

Decision ​

  • orbit migrate is the only place migrations run. It runs the kernel's, the platform crates' and every compiled module's migrations, then records each module in kernel.modules (id, version). It runs as a one-shot process (the migrate container) with the owner URL. orbit tenant provision also runs it first. The auth sidecar's schema follows the same rule: the one-shot auth-migrate service migrates it with the auth migrator role, and the long-running sidecar holds only its runtime role.
  • No serving role holds the owner URL. web, worker, scheduler and all refuse to start when ORBIT_MIGRATION_DATABASE_URL is set. web also refuses the worker URL, and worker/scheduler refuse the doors URL. --role takes a list, so one container runs worker,scheduler.
  • Enabling a module only flips its flag. The kernel commands run on the runtime role like every other command (same transaction, same audit entry). They keep their checks in Rust: the Cedar gate and the resource check on kernel.module/<id>, the dependency checks under a per-tenant advisory lock, and a refusal (CONFLICT, "run orbit migrate") for a module that is compiled in but not migrated. The write itself goes through kernel.set_module_enabled(module, enabled):
    • SECURITY DEFINER, owned by the owner role, search_path = pg_catalog, pg_temp;
    • EXECUTE revoked from PUBLIC and granted to orbit_runtime only (not to orbit_worker or orbit_doors);
    • the tenant is kernel.current_tenant(), never an argument: no tenant set, no write;
    • the module must be in kernel.modules; kernel itself never is;
    • the module's dependencies are checked again inside the function (kernel.modules records each module's requires at migrate time), under the same per-tenant lock: no enable while a dependency is off, no disable while a dependent is on;
    • every switch is appended to kernel.module_switches (tenant, module, new state, transaction id, time, calling login). The table is owned by the owner role, insert-only (a trigger refuses UPDATE and DELETE), under tenant row-level security, and the runtime role may read it but not write it;
    • kernel.tenant_modules stays under FORCE row-level security, so the row must belong to the transaction's tenant even inside the function. The runtime role still has only SELECT on kernel.tenant_modules.

Consequences ​

  • Deploying a build with a new module means running orbit migrate before the new web and worker processes start (the compose file orders this with service_completed_successfully).
  • Code running as the runtime role (any module handler, or anyone holding its credentials) can call kernel.set_module_enabled directly, outside the bus, and so without the Cedar check or an audit entry. It can do so for any tenant whose id it knows, because raw SQL on that role can set app.tenant_id itself: the same limit as row-level security everywhere, which separates tenants for honest code, not against the runtime credentials. It cannot enable an unmigrated module, break a dependency, or alter any table. Such a switch is detectable, not prevented: it leaves a row in kernel.module_switches with no matching kernel.module.* audit entry. Prevention (a separate login that only the bus uses for the kernel commands) is deferred until third-party code runs in process; plugins run in Extism, not as the runtime role.
  • Each connection also checks its login when the process starts: never a superuser or BYPASSRLS; the runtime, worker and doors logins also never CREATEROLE, never the owner of schema kernel, and members of exactly their own group (orbit_runtime, orbit_worker, orbit_doors).

Orbit by SkySync Tech. Licensed under AGPL-3.0.