feat(drift): add noisy neighbor protection, RBAC forgery prevention, remediation locks
Some checks failed
CI — P2 Drift (Go + Node) / agent (push) Successful in 37s
CI — P2 Drift (Go + Node) / saas (push) Successful in 26s
CI — P2 Drift (Go + Node) / build-push (push) Failing after 45s

- Fair-share tenant processing: weighted round-robin, per-tenant queue depth tracking
- API key → stack ownership validation on all ingestion routes
- Enhanced replay attack prevention (timestamp + nonce + report_id dedup)
- Remediation lock: Redis-based mutex prevents scan/remediation race conditions
- Reports during active remediation tagged and excluded from scoring
- 006_noisy_neighbor.sql migration
This commit is contained in:
Max
2026-03-03 13:42:34 +00:00
parent f133ca8ff6
commit ffe2b63877
7 changed files with 408 additions and 23 deletions

View File

@@ -0,0 +1,29 @@
-- 006: Noisy neighbor protection, remediation locks, fair-share processing
-- Add during_remediation flag to drift_reports
ALTER TABLE drift_reports ADD COLUMN IF NOT EXISTS during_remediation BOOLEAN NOT NULL DEFAULT false;
-- Add processing_priority to stacks (tracked via drift_reports for now)
-- We use a dedicated lightweight table so we can set priority per-stack without a full stacks table
CREATE TABLE IF NOT EXISTS stack_settings (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
stack_name TEXT NOT NULL,
processing_priority TEXT NOT NULL DEFAULT 'normal' CHECK (processing_priority IN ('low', 'normal', 'high')),
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
UNIQUE(tenant_id, stack_name)
);
ALTER TABLE stack_settings ENABLE ROW LEVEL SECURITY;
CREATE POLICY tenant_iso_stack_settings ON stack_settings
USING (tenant_id::text = current_setting('app.tenant_id', true));
-- Index for fair-share queue queries: find reports per tenant ordered by time
CREATE INDEX IF NOT EXISTS idx_drift_reports_tenant_created
ON drift_reports(tenant_id, created_at);
-- Index for remediation lock lookups
CREATE INDEX IF NOT EXISTS idx_remediations_active
ON remediations(tenant_id, stack_name, status)
WHERE status IN ('pending', 'in_progress');