Appearance
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 migrateis the only place migrations run. It runs the kernel's, the platform crates' and every compiled module's migrations, then records each module inkernel.modules(id, version). It runs as a one-shot process (themigratecontainer) with the owner URL.orbit tenant provisionalso runs it first. The auth sidecar's schema follows the same rule: the one-shotauth-migrateservice 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,schedulerandallrefuse to start whenORBIT_MIGRATION_DATABASE_URLis set.webalso refuses the worker URL, andworker/schedulerrefuse the doors URL.--roletakes a list, so one container runsworker,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, "runorbit migrate") for a module that is compiled in but not migrated. The write itself goes throughkernel.set_module_enabled(module, enabled):SECURITY DEFINER, owned by the owner role,search_path = pg_catalog, pg_temp;EXECUTErevoked fromPUBLICand granted toorbit_runtimeonly (not toorbit_workerororbit_doors);- the tenant is
kernel.current_tenant(), never an argument: no tenant set, no write; - the module must be in
kernel.modules;kernelitself never is; - the module's dependencies are checked again inside the function (
kernel.modulesrecords each module'srequiresat 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_modulesstays under FORCE row-level security, so the row must belong to the transaction's tenant even inside the function. The runtime role still has onlySELECTonkernel.tenant_modules.
Consequences
- Deploying a build with a new module means running
orbit migratebefore the new web and worker processes start (the compose file orders this withservice_completed_successfully). - Code running as the runtime role (any module handler, or anyone holding its credentials) can call
kernel.set_module_enableddirectly, 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 setapp.tenant_iditself: 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 inkernel.module_switcheswith no matchingkernel.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).