Files
buzz/migrations/0033_relay_admin_action_lease.sql
Duncan 5505e608b9 feat(relay): OPERATOR/MODERATOR role model for relay admin API with NIP-98 auth
Gate the relay admin moderation API (/api/admin/v1) behind explicit
authentication configuration selected by BUZZ_ADMIN_AUTH: token (default),
disabled, or nip98. In nip98 mode every request carries a signed kind-27235
NIP-98 event; the authenticated pubkey resolves to an OPERATOR or MODERATOR
principal from RELAY_OPERATOR_PUBKEYS, the RELAY_OWNER_PUBKEY fallback, or the
relay_operators table. Replaces the BUZZ_ADMIN_INSECURE_NO_AUTH bypass with a
role model that is revocable without rotating a shared secret and fails closed
at every boundary.

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
2026-08-12 23:20:29 -04:00

30 lines
1.2 KiB
SQL

-- Relay admin action lease + outbox retry support.
--
-- Adds per-action exclusive lease columns to relay_admin_actions so that:
-- (a) concurrent same-request_id retries cannot both run the mutation branch,
-- (b) the action recovery worker can claim and re-drive stranded
-- pending/enforcing actions after a process crash.
--
-- Adds attempt_count and retry_after to relay_admin_outbox so that delivery
-- failures are retryable (with backoff) rather than immediately terminal.
ALTER TABLE relay_admin_actions
ADD COLUMN action_lease_token UUID,
ADD COLUMN action_lease_expires_at TIMESTAMPTZ;
-- Index for the action recovery worker: find stranded actions quickly.
CREATE INDEX idx_relay_admin_actions_lease
ON relay_admin_actions (action_lease_expires_at)
WHERE state IN ('pending', 'enforcing');
ALTER TABLE relay_admin_outbox
ADD COLUMN attempt_count INT NOT NULL DEFAULT 0,
ADD COLUMN retry_after TIMESTAMPTZ;
-- Replace the pending-delivery index to include retry_after so the worker
-- claim query can filter efficiently.
DROP INDEX IF EXISTS idx_relay_admin_outbox_pending;
CREATE INDEX idx_relay_admin_outbox_pending
ON relay_admin_outbox (retry_after NULLS FIRST, created_at)
WHERE state = 'pending';