mirror of
https://github.com/block/buzz.git
synced 2026-11-15 22:02:04 +00:00
fix(identity): harden corporate identity lifecycle
Signed-off-by: Cea Stapleton Cordasco <261786559+cea-block@users.noreply.github.com>
This commit is contained in:
@@ -188,9 +188,8 @@ CREATE UNIQUE INDEX idx_users_okta ON users (community_id, okta_user_id)
|
||||
-- Conformance: verified identity is community-scoped. An issuer-qualified uid
|
||||
-- is the stable product/user-management identity; a Nostr pubkey is the
|
||||
-- protocol credential currently bound to it. This table is intentionally a
|
||||
-- binding foundation, not a full grant/session lifecycle model. Revocation
|
||||
-- columns are reserved for follow-up admin/rotation flows, while PR1 only
|
||||
-- creates or validates active bindings during existing auth paths.
|
||||
-- binding and lifecycle authority. Revocation scope distinguishes principal
|
||||
-- disablement, a single-key revocation, and an operator-authorized rotation.
|
||||
|
||||
CREATE TABLE identity_bindings (
|
||||
community_id UUID NOT NULL REFERENCES communities(id),
|
||||
@@ -205,10 +204,29 @@ CREATE TABLE identity_bindings (
|
||||
revoked_at TIMESTAMPTZ,
|
||||
revoked_by BYTEA,
|
||||
revoked_reason TEXT,
|
||||
revocation_scope TEXT NOT NULL DEFAULT 'principal'
|
||||
CHECK (revocation_scope IN ('principal', 'key', 'rotation')),
|
||||
rotation_completed_at TIMESTAMPTZ,
|
||||
rotated_to_pubkey BYTEA,
|
||||
rotation_by BYTEA,
|
||||
rotation_reason TEXT,
|
||||
CONSTRAINT chk_identity_bindings_issuer_not_empty CHECK (length(issuer) > 0),
|
||||
CONSTRAINT chk_identity_bindings_uid_not_empty CHECK (length(uid) > 0),
|
||||
CONSTRAINT chk_identity_bindings_pubkey_len CHECK (length(pubkey) = 32),
|
||||
CONSTRAINT chk_identity_bindings_revoked_by_len CHECK (revoked_by IS NULL OR length(revoked_by) = 32)
|
||||
CONSTRAINT chk_identity_bindings_revoked_by_len CHECK (revoked_by IS NULL OR length(revoked_by) = 32),
|
||||
CONSTRAINT chk_identity_bindings_rotation_state CHECK (
|
||||
(rotation_completed_at IS NULL
|
||||
AND rotated_to_pubkey IS NULL
|
||||
AND rotation_by IS NULL
|
||||
AND rotation_reason IS NULL)
|
||||
OR
|
||||
(rotation_completed_at IS NOT NULL
|
||||
AND rotated_to_pubkey IS NOT NULL
|
||||
AND length(rotated_to_pubkey) = 32
|
||||
AND (rotation_by IS NULL OR length(rotation_by) = 32)
|
||||
AND rotation_reason IS NOT NULL
|
||||
AND length(rotation_reason) > 0)
|
||||
)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX idx_identity_bindings_active_principal
|
||||
@@ -219,6 +237,35 @@ CREATE UNIQUE INDEX idx_identity_bindings_active_pubkey
|
||||
WHERE revoked_at IS NULL;
|
||||
CREATE INDEX idx_identity_bindings_pubkey
|
||||
ON identity_bindings (community_id, pubkey);
|
||||
CREATE INDEX idx_identity_bindings_revoked_principal
|
||||
ON identity_bindings (community_id, issuer, uid)
|
||||
WHERE revoked_at IS NOT NULL AND revocation_scope = 'principal';
|
||||
|
||||
CREATE TABLE identity_principals (
|
||||
community_id UUID NOT NULL REFERENCES communities(id),
|
||||
issuer TEXT NOT NULL,
|
||||
uid TEXT NOT NULL,
|
||||
disabled_at TIMESTAMPTZ,
|
||||
disabled_by BYTEA,
|
||||
disabled_reason TEXT,
|
||||
PRIMARY KEY (community_id, issuer, uid),
|
||||
CHECK (length(issuer) > 0),
|
||||
CHECK (length(uid) > 0),
|
||||
CHECK (disabled_by IS NULL OR length(disabled_by) = 32),
|
||||
CHECK ((disabled_at IS NULL) = (disabled_reason IS NULL))
|
||||
);
|
||||
|
||||
CREATE TABLE identity_revoked_keys (
|
||||
community_id UUID NOT NULL REFERENCES communities(id),
|
||||
pubkey BYTEA NOT NULL,
|
||||
revoked_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
revoked_by BYTEA,
|
||||
reason TEXT NOT NULL,
|
||||
PRIMARY KEY (community_id, pubkey),
|
||||
CHECK (length(pubkey) = 32),
|
||||
CHECK (revoked_by IS NULL OR length(revoked_by) = 32),
|
||||
CHECK (length(reason) > 0)
|
||||
);
|
||||
|
||||
-- ── Events (partitioned by month on created_at) ──────────────────────────────
|
||||
-- Conformance: "Channel-less global events and DMs". `community_id` leads the
|
||||
|
||||
Reference in New Issue
Block a user