24 lines
1.4 KiB
SQL
24 lines
1.4 KiB
SQL
-- Run ONLY through the normal owner/migration identity, never the runtime adapter.
|
|
-- Global PREAUTH data: no tenant identifiers, memberships or tenant RLS bypass.
|
|
CREATE SCHEMA rmm_oidc_auth;
|
|
REVOKE ALL ON SCHEMA rmm_oidc_auth FROM PUBLIC;
|
|
|
|
CREATE TABLE rmm_oidc_auth.login_states (
|
|
state_hash bytea PRIMARY KEY CHECK (octet_length(state_hash) = 32),
|
|
binding_hash bytea NOT NULL CHECK (octet_length(binding_hash) = 32),
|
|
expires_at bigint NOT NULL CHECK (expires_at > 0),
|
|
created_at bigint NOT NULL DEFAULT floor(extract(epoch FROM clock_timestamp()))::bigint,
|
|
encryption_key_ref text NOT NULL CHECK (length(encryption_key_ref) BETWEEN 1 AND 256),
|
|
encryption_nonce bytea NOT NULL CHECK (octet_length(encryption_nonce) = 12),
|
|
ciphertext bytea NOT NULL CHECK (octet_length(ciphertext) BETWEEN 16 AND 4096),
|
|
CHECK (expires_at > created_at AND expires_at <= created_at + 600)
|
|
);
|
|
CREATE INDEX login_states_expiry ON rmm_oidc_auth.login_states (expires_at, state_hash);
|
|
REVOKE ALL ON rmm_oidc_auth.login_states FROM PUBLIC;
|
|
|
|
-- Deployment must explicitly grant its dedicated global auth-service runtime role:
|
|
-- GRANT USAGE ON SCHEMA rmm_oidc_auth TO <auth_service_runtime_role>;
|
|
-- GRANT SELECT, INSERT, DELETE ON rmm_oidc_auth.login_states TO <auth_service_runtime_role>;
|
|
-- Do NOT grant schema CREATE, table ownership, UPDATE, TRUNCATE, superuser,
|
|
-- BYPASSRLS, tenant-table privileges or general migration privileges to that role.
|