Artifact recovery floor role contract (migration 766)
This is a provisioning contract, not evidence of provisioning or permission to deploy.
The runtime and migration login roles must be different. The runtime must be NOSUPERUSER,
NOBYPASSRLS, NOCREATEROLE, and must have no direct or transitive membership in the floor
owner. It must not own the database or the public schema, or be able to grant itself
that membership. The migration role must be able to SET ROLE to the floor owner, and the
floor owner must have CREATE on public during ownership transfer. Infra must remove
that temporary schema CREATE after migration. The owner is NOLOGIN, NOINHERIT,
NOSUPERUSER, NOBYPASSRLS, NOCREATEROLE, NOCREATEDB and NOREPLICATION. No runtime
membership may be granted, even without inheritance: SET ROLE would reveal the table.
The cluster administrator provisions the role idempotently, then validates existing role attributes rather than silently changing a pre-existing role:
DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_catalog.pg_roles WHERE rolname = 'supacloud_artifact_floor_owner') THEN CREATE ROLE supacloud_artifact_floor_owner NOLOGIN NOINHERIT NOSUPERUSER NOBYPASSRLS NOCREATEROLE NOCREATEDB NOREPLICATION; END IF; IF EXISTS (SELECT 1 FROM pg_catalog.pg_roles WHERE rolname = 'supacloud_artifact_floor_owner' AND (rolcanlogin OR rolinherit OR rolsuper OR rolbypassrls OR rolcreaterole OR rolcreatedb OR rolreplication)) THEN RAISE EXCEPTION 'unsafe artifact floor owner'; END IF;END $$;An administrator grants supacloud_artifact_floor_owner to the migration role WITH
INHERIT FALSE, SET TRUE and temporarily grants that owner CREATE on public; substitute
properly quoted, verified role names. The migration connection must set
supacloud.artifact_runtime_role to the exact runtime role before running SQLx migrations
766 and 792, and before every later floor migration that hands objects to the owner. It can also set supacloud.artifact_floor_owner_role to the separately provisioned
NOLOGIN owner; when absent, the documented owner name above is used. The migration role,
runtime role and floor owner must all be distinct. An explicitly configured but nonexistent,
identical, unsafe or floor-member runtime role is rejected. Configure the
runtime’s normal application-table grants separately and grant no floor table privileges.
When the setting is absent, migration 766 instead installs an empty, unqualified schema; cutover and debt insertion are refused. Providing a partial or unsafe contract fails the migration. With the full contract, migration 766 keeps the boolean conflict function private to the floor owner;
its debt trigger, owned by the separate role, maintains floor rows. Revoke the temporary
schema CREATE after migration and verify it stayed revoked.
On a configured floor the runtime has no SELECT on artifact_staging_authority, so
migration 792 gives it one SECURITY DEFINER function per statement it runs on that
table. Each function addresses one row by its full key and exact writer nonce, refuses a
workspace other than the caller’s workspace context, and returns no set. Migration 792
hands the functions to the owner of artifact_recovery_content_floor, grants that owner
INSERT, UPDATE and DELETE on the table beside the SELECT from 766, and grants EXECUTE to
the runtime role alone. It reads that result back from the catalog. On a floor whose 766 table was migrated
without the setting, the Core provisioner completes this branch; see “The Core run on an
unqualified 766” below. On a configured floor
migration 792 refuses with 792 requires supacloud.artifact_runtime_role on a configured 766 floor when the connection does not set the runtime role. A set
supacloud.artifact_floor_owner_role that names another role than the floor’s owner is
refused as well. An unconfigured schema keeps its direct SQL.
Before any activation, independently verify real runtime and migration identities, role memberships (including transitive membership), table/function ownership, grants, RLS and the denial of raw floor SELECT, direct conflict-function and trigger-function execution from the runtime role, including a same-workspace sibling-project negative test. Verify both orders of concurrent 711 and generation claims on PG18, and qualify the old-server drain and restart-prevention protocol. Cutover remains hard-disabled in source until that protocol exists. Nothing here authorizes a live role change, migration, activation or deployment.
The qualified integration fixture creates a UUID-named scratch database and separate
UUID-named migration, floor-owner and runtime roles on the configured test cluster. It
runs the real migrations, connects as the runtime LOGIN, checks session_user and
current_user, and removes its own database and roles after normal completion or a
caught panic. The test cluster must already have the 722 observer role required by the
normal migration harness; this fixture does not provision it. The fixture is not an
operational provisioning mechanism. Its default-off control runs legacy writes as an
actual non-owner without a cutover-table grant.
server/tests/fixtures/artifact_recovery/default_off.sql is a schema-only disposable
database control at migration 765. qualified.sql is a negative probe for a database
where 766 is already qualified; run it as the actual dedicated runtime LOGIN, never
through SET ROLE from an administrator. Both require disposable PostgreSQL 18. The
separate cross-replica integration tests cover pre-existing and concurrent 711 claims;
their source is not evidence that they ran or that the remaining generic ports qualify.
Running the provisioner
Section titled “Running the provisioner”The private floors are installed by provision_artifact_floor, which ships at
/usr/local/bin/provision_artifact_floor in the supacloud-server image (and as a copy
in the supacloud-ops image). Server boot and the ordinary migrations never run it. An
operator runs it once per floor, as a one-shot container from the same image tag as the
server it provisions for, with the one-run connection
SUPACLOUD_ARTIFACT_PROVISIONER_DATABASE_URL (bootstrap SUPERUSER) resolved from its
secret source at use time:
provision_artifact_floor [--report|--mail|--archive-settle] <floor-owner-role> <runtime-role> <witness-role>| Flag | Floor | Migrations it is bound to |
|---|---|---|
| none | Core | 768, 770, 771 |
--mail |
Mail archive, after the Core floor | 769, 770, 779 |
--report |
Report | 775 |
--archive-settle |
Archive settlement | 783 |
The one-run connection is the bootstrap superuser (pgadmin in the how-to): the 766
qualification transfers ownership from the application owner, and the 768 role check
requires SET ROLE to the floor owner. A BYPASSRLS-only login is refused by the bin
before any change; there is no half-supported ownership-transfer path. Infra’s
runtime-role script needs no change.
Each run is bound to the checksums of the migrations compiled into the same binary, so the one-shot runs the server’s own image tag, never an image built from other source. A refusal names the floor. Success installs the schema only; runtime qualification and writer-drain activation remain separate steps, under their own authorization.
The Core run on an unqualified 766
Section titled “The Core run on an unqualified 766”A database installed by the how-to runs migrations as the application owner without
supacloud.artifact_runtime_role, so migration 766 leaves the empty, unqualified schema:
the content floor is application-owned, has no owner policy, no marker and no floor-owner
functions. The Core provisioner recognizes exactly that shape and installs the configured
766 contract before 768/770/771: it creates the floor-owner policy, revokes the runtime
and PUBLIC (table and column ACLs), sets the 766 qualified floor role contract marker,
moves the content floor and the four 766 guard functions to the floor owner, grants the
floor-owner reads the 766 functions need, and proves
artifact_recovery_floor_qualified() is true. It also grants the floor owner the billing
reads (artifacts, artifact_ingest_effects, and workspace_artifact_counters) that the
768/770 guards consult, on both fixture shapes.
A foreign or half-configured 766 is refused with a named check, never adopted: the content
floor must share its owner with artifact_recovery_cutovers, have forced row security,
zero policies and no marker, and the four guard functions must be the unconfigured
migration functions owned by that same application owner. The 766 script raises a named
P0001 refusal for every other shape.
Before it changes anything it also enforces the configured 766 role preconditions, each
with its own named refusal: distinct roles, neither role is the operator or the other
role, the runtime is not a member of the floor owner, the operator can SET ROLE to the
floor owner, the floor owner is restricted, the runtime has no CREATE on public and
PUBLIC has none, the runtime does not own the database, is not
SUPERUSER/BYPASSRLS/CREATEROLE, and neither owns nor inherits any of the ten
security tables, their non-internal trigger functions or schema public. After the
direct revoke it asserts the runtime holds no effective table or column privilege on the
content floor, inherited through a role membership included.
The same Core transaction also completes migration 792 on a database migrated without that
setting. 792 also returns
before its configured branch when supacloud.artifact_runtime_role is absent, so its
eight exact-row staging functions stay with the migration login. A qualified 766 floor
routes every staging statement through those functions, so the runtime needs their
configured shape: floor-owned, executable by the runtime alone. The 792 step proves the unconfigured shape first — all
eight present, one owner, SECURITY DEFINER, not set-returning, search_path pinned, no
EXECUTE beyond that owner — and then applies 792’s configured branch:
INSERT, UPDATE, DELETE on artifact_staging_authority for the floor owner, EXECUTE
for the runtime alone while the operator still owns the functions, the owner change on
all eight, and 792’s catalog read-back (eight functions, floor-owned, SECURITY DEFINER,
pinned search_path, no other EXECUTE grantee) plus the runtime’s actual EXECUTE and
its absence on artifact_staging_require_scope. The operator is the bootstrap superuser,
so the step needs no schema CREATE window. A half-owned set, a foreign EXECUTE
grantee, a set owned elsewhere than the staging table, or any other non-unconfigured
shape is refused, never repaired; an installed set is only read back, so a withdrawn
EXECUTE or an added grantee is a refusal and no grant changes. The eight signatures are
one list: EXACT_ROW_STAGING_FUNCTIONS in artifact_floor_objects.rs, pinned to migration
792 and to sql/artifact_792_qualification.sql in both directions by
artifact_floor_objects_tests.
The product cannot write a 766 custody row while the floor is unqualified, which is why a non-empty custody table is a refusal rather than a repair. Per table:
artifact_recovery_cutovers: theartifact_recovery_cutover_floor_guardtrigger (migrations/766_artifact_recovery_fence.sql:167-176) raises55000on everyINSERT/UPDATE, so no cutover row can exist.artifact_recovery_principal_custodyandartifact_recovery_open_receipts: written only byopen_custody_in(artifact_recovery_inventory.rs:65). Its inventory readread_in(:28) joinsartifact_recovery_cutovers(:58) and returnsNonewithout a cutover row, soopen_custody_inreturns at:76-78and never reaches the custody insert (:113) or the open-receipt insert (:131).artifact_recovery_content_debt: the legacy content guard may attempt the insert (766:686), but theartifact_recovery_floor_debt_guardtrigger (766:371-372) runsartifact_recovery_floor_from_debt, which refuses unless the floor is qualified (766:354-355); the attempt aborts the transaction.artifact_recovery_content_floor: inserted only by that same qualified debt trigger (766:359).artifact_isolated_attempt_intents: theartifact_isolated_attempt_intent_fencetrigger (766:497-498) requires an existing custody row and an isolated cutover (766:465-468).
The ownership read-back
Section titled “The ownership read-back”Every provisioner run ends with one read-back before its transaction commits: no floor
object may be owned by a SUPERUSER role or by the operator connection. It covers the
relations each floor installs or takes over, the functions the migrations hand to the
floor owner (766, 768, 770, 771 and 792 for the Core floor; 775 and 776 for the report
floor; 779 for the mail floor; 783 for the archive-settlement floor; 780 for the ranking
floor), and every non-internal trigger function attached to those relations. The declared
sets live in artifact_floor_objects.rs; the provisioner reads them instead of a second
hand-written list, and artifact_floor_objects_tests proves each declared object exists
in its floor’s own sources and that every literal owner handover of those sources is
declared. An absent object is a refusal as well, and a refusal names every offending
object with its privileged owner. On success the run prints one
<floor> floor checked: <object> line per object, so the operator sees the exact list
that was read, not only that nothing was refused.
The runtime’s only door to the staging table
Section titled “The runtime’s only door to the staging table”On a configured floor the exact-row functions are the runtime’s only route to
artifact_staging_authority. Migration 766 grants the floor owner the reads its guards
need but removes no grant another step made. The how-to’s owner-keyed block grants the
runtime SELECT, INSERT, UPDATE, DELETE on every application-owner relation, and on this
table only while public.artifact_recovery_floor_configured() is false (or absent, before
766): the legacy path of an unconfigured schema uses that direct door. The Core provisioner
removes the runtime’s and PUBLIC’s table and column privileges on the first install and
prints the repair (artifact_staging_authority: revoked runtime/PUBLIC privileges). From
then on the predicate is true and a re-applied block leaves the table alone, so every later
deploy runs the block and the provisioners without a repair. A floor that already carries
its receipt never loses the closed door silently: a hand grant of the table reopens it, and
the next provisioner run refuses with the runtime or PUBLIC holds a direct artifact_staging_authority privilege again …; revoke it before re-running. Migration 792’s
header says that “a configured 766 floor
revokes the runtime’s SELECT on artifact_staging_authority”; that sentence is inaccurate
on its own, because 766 only grants the floor owner and this provisioner step is what
closes the door. The applied migration stays byte-exact.
The recovery cutover’s SHARE ROW EXCLUSIVE lock is part of the same door. Migration 860
installs public.artifact_staging_lock(), owned by the restricted floor owner,
SECURITY DEFINER, search_path=pg_catalog, public, PUBLIC revoked and executable by the
runtime alone; the lock it takes belongs to the caller’s transaction. The cutover takes it
through that function when artifact_recovery_floor_configured() is true and keeps the
direct LOCK TABLE on an unconfigured schema. Every other statement the runtime runs on
the table is a 792 function (artifact_staging_rows). The three triggers on the table need
no runtime privilege: artifact_recovery_content_guard is SECURITY DEFINER and belongs
to the floor owner, and artifact_joined_staging_key_guard and
artifact_owner_capture_staging_guard are invoker functions whose bodies only inspect
NEW.object_key, so a configured floor fires them as the floor owner through those
functions.
Receipts and the state functions
Section titled “Receipts and the state functions”Each provisioner owns its receipt table in the same transaction as the install. A receipt
is owned by the floor owner; the runtime, PUBLIC and every other role hold nothing on it,
on the table ACL and on every column ACL. The one exception is a table-level SELECT for
the witness on the mail and archive-settlement receipts, which those witnesses read.
A re-run repairs a receipt that an operator grant, the application owner’s default
privileges or REASSIGN OWNED moved out of that shape, and prints every repair. The proof
of an adoptable owner is public.workspaces: the receipt’s current owner must be the floor
owner or the role that owns workspaces (the application owner). REASSIGN OWNED moves
both, so that case is repaired; any other owner is foreign and is refused with a named
check. A changed checksum, a changed script or a partial floor is likewise a named
refusal, not a repair.
Every provisioner also installs one receipt-state function, owned by the floor owner,
SECURITY DEFINER with search_path=pg_catalog, executable by the runtime alone. Each
returns two booleans and no role OID, checksum or script:
| Function | Floor |
|---|---|
public.artifact_floor_state() |
Core |
public.artifact_report_floor_state() |
Report |
public.artifact_mail_floor_state() |
Mail archive |
public.workflow_external_archive_settle_floor_state() |
Archive settlement |
installed reports a receipt row; matches compares that row with the current binary’s
role names, migration checksums and floor scripts. A server upgrade therefore reads
installed = true, matches = false until the matching provisioner runs once. The feature
panel reads these functions; the runtime gains no direct privilege on a receipt table.
The report floor’s 776 run receipt follows a different contract because a forged run
receipt is a security event, not a routine grant: the report provisioner moves
stripe_report_run_receipts to the floor owner and grants the runtime exactly a
table-level SELECT; the witness holds nothing. The 776 qualification refuses a runtime
write privilege, an added permissive write policy, and any column ACL beyond the floor
owner. A re-run repairs a grant or a column ACL it can revoke; a policy it cannot prove is
a named refusal.
Rolling switch for the report receipt
Section titled “Rolling switch for the report receipt”The report run receipt’s owner changes once. Deploy the new server version first: it
accepts the floor-owned shape, while an older replica still reads the previous
stripe_report_receipt_qualification_776.sql check (c.relowner NOT IN (...), line 4 of
that release) and refuses a floor-owned receipt. While the receipt is still
application-owned, the new server reports the report floor unqualified; the report
feature stays inactive and no report run is created. Run
provision_artifact_floor --report only after every replica runs the new version, or
drain the old replicas’ report path for the switch. Set the witness URL last and
restart: the boot refusal covers an unqualified witness or floor. The current check is
stripe_report_receipt_qualification_776.sql:4 (c.relowner=$1), and the state function
reports only installed/matches.
Grants the provisioner restores
Section titled “Grants the provisioner restores”The private floors’ relations are owned by the floor owner, not by the application owner.
The runtime and PUBLIC hold nothing on them, with two exceptions: the ranking floor’s
contract grants the runtime SELECT on public.backlog_ranking_sweeps, and the report
floor’s 776 contract grants the runtime SELECT on public.stripe_report_run_receipts.
A repair restores exactly those reads and revokes every other table and column privilege.
Application-owner tables, witness and writer grants, and every ACL outside the floor-owner
relations are outside the repair; the provisioner does own the receipt-state functions and
the 766 guard functions it installs.
The how-to’s default privileges grant the runtime DML on every relation the application
owner creates, and PostgreSQL keeps those ACL entries when a relation changes owner. A
floor migration that creates a relation as the application owner and then hands it to the
floor owner therefore leaves the runtime’s grant on it. Every such handover is declared in
artifact_floor_objects.rs (artifact_floor_objects_tests refuses an undeclared one), so
the provisioner run of the same deploy, which follows the migrations, revokes the grant and
names the relation. Boot qualification does not cover that window: it checks the content
floor, the owner-capture floor and the isolated store, not every floor relation. The
receipt relations in particular are read only by the feature panel’s state functions.
Run the provisioners in the order core, --report, --mail, --archive-settle after a
literal GRANT ... ON ALL TABLES IN SCHEMA, a REASSIGN OWNED, or any manual grant on a
floor object. The repair names every relation it restored in the operator output. A
private floor relation whose owner is not the configured floor owner is refused with its
named check. A provisioner receipt may be adopted only from the application owner as
described above; the provisioner never adopts any other object it cannot prove.
The how-to run-as-a-least-privilege-database-role grants on the relations the
application owner owns and on that owner’s default privileges, never on all tables in the
schema. That block can be re-applied on every deploy: the floor-owner relations are outside
its key, and it skips artifact_staging_authority once the Core floor is configured. Infra’s
role script needs no change for the private floors: it must keep using the owner-keyed
grant, keep that skip, and must not add a schema-wide grant.
The mail floor upgrades one released predecessor receipt in place. The predecessor keeps its stored rows and its first provisioning time; the upgrade replaces the issuer and adds the observe policy. A receipt that is neither the current script nor that exact predecessor is refused. No deployment holds a receipt yet; a later script change is carried by the next provisioner run and reported as a changed script, never silently reused.