mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-19 06:30:54 +08:00
Migration 0005 creates traffic_rewrite_rules. The matchers and actions columns are two JSON secret columns of db/secrets.go: InitSecrets, which runs after the migrations, checks the key against them and encrypts any plaintext row, as it does for the existing columns. The CRUD lists rules in execution order and enforces 100 rules, 50 of them enabled, under a table lock so concurrent writers cannot pass a limit. UpdateTrafficRewriteRule hands the stored rule to an edit callback inside the transaction, which is where a caller keeps a value it was not sent. InitSecrets also derives the sub-key that fingerprints sensitive values in the rewrite trace (HMAC-SHA256 of "artex-traffic-trace" under the secret key).
26 lines
1.2 KiB
SQL
26 lines
1.2 KiB
SQL
-- Rewrite rules of the capture proxy. Global configuration: the table is not
|
|
-- part of a task archive.
|
|
--
|
|
-- matchers and actions are sealed at rest by db/secrets.go (two JSON secret
|
|
-- columns): a row holds {"__artex_enc":"enc:v1:..."} in each, and an empty
|
|
-- object stays in clear. Migrations run before InitSecrets, which checks the
|
|
-- key against these columns and encrypts any plaintext row it finds.
|
|
--
|
|
-- Execution order is priority ascending, then id ascending: the highest
|
|
-- priority applies last. A rule is created disabled.
|
|
CREATE TABLE IF NOT EXISTS traffic_rewrite_rules (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
name TEXT NOT NULL,
|
|
enabled BOOLEAN NOT NULL DEFAULT false,
|
|
phase TEXT NOT NULL CHECK (phase IN ('request', 'response')),
|
|
priority INTEGER NOT NULL DEFAULT 0,
|
|
matchers JSONB NOT NULL,
|
|
actions JSONB NOT NULL,
|
|
note TEXT NOT NULL DEFAULT '',
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
);
|
|
DROP TRIGGER IF EXISTS trg_traffic_rewrite_rules_upd ON traffic_rewrite_rules;
|
|
CREATE TRIGGER trg_traffic_rewrite_rules_upd BEFORE UPDATE ON traffic_rewrite_rules
|
|
FOR EACH ROW EXECUTE FUNCTION set_updated_at();
|