mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-12-06 12:24:44 +00:00
Part 1 of 4 of the proxy pool design in #545: storage and a CRUD API. Nothing activates an entry yet, so the global proxy is unchanged. - Migration 0028 adds proxy_pool: a unique keyed address hash, at most one active entry (partial unique index), a CHECK that the active entry is enabled, and nullable egress_ip, last_check_at and last_check_ok for the health check. - Addresses are normalized, sealed at rest (AAD proxy_pool.address) and covered by the startup key check and key rotation. Uniqueness uses an HMAC under a sub-key kept on secretBox; RotateSecretKey locks the table and rehashes in its transaction, and pool writes seal under that lock. - GET/POST /api/proxy-pool and PATCH/DELETE /api/proxy-pool/{id} never return an address; a masked address on update keeps the stored one.
34 lines
1.6 KiB
SQL
34 lines
1.6 KiB
SQL
-- Proxy pool: stored candidates for the global egress proxy (#545). Global
|
|
-- configuration: the table is not part of a task archive.
|
|
--
|
|
-- An entry only ever chooses the existing global proxy; it adds no egress path
|
|
-- of its own. This migration stores entries; nothing activates one yet.
|
|
--
|
|
-- address is sealed at rest by db/secrets.go (AAD "proxy_pool.address"): it may
|
|
-- carry user:pass. Because sealing is randomized, uniqueness is enforced on
|
|
-- address_hash, an HMAC of the normalized address under a sub-key of the secret
|
|
-- key (db/proxy_pool.go), recomputed when the key is rotated.
|
|
--
|
|
-- At most one entry is active, and the active entry is enabled.
|
|
-- egress_ip, last_check_at and last_check_ok are written by the health check;
|
|
-- NULL means never checked.
|
|
CREATE TABLE IF NOT EXISTS proxy_pool (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
label TEXT NOT NULL CHECK (length(btrim(label)) > 0),
|
|
address TEXT NOT NULL,
|
|
address_hash TEXT NOT NULL,
|
|
enabled BOOLEAN NOT NULL DEFAULT true,
|
|
active BOOLEAN NOT NULL DEFAULT false,
|
|
egress_ip TEXT,
|
|
last_check_at TIMESTAMPTZ,
|
|
last_check_ok BOOLEAN,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
CONSTRAINT proxy_pool_address_hash_key UNIQUE (address_hash),
|
|
CONSTRAINT proxy_pool_active_enabled CHECK (NOT active OR enabled)
|
|
);
|
|
CREATE UNIQUE INDEX IF NOT EXISTS proxy_pool_one_active ON proxy_pool ((true)) WHERE active;
|
|
DROP TRIGGER IF EXISTS trg_proxy_pool_upd ON proxy_pool;
|
|
CREATE TRIGGER trg_proxy_pool_upd BEFORE UPDATE ON proxy_pool
|
|
FOR EACH ROW EXECUTE FUNCTION set_updated_at();
|