feat(api): deterministic scan worker + AUD0 wire + tenant binding
CI (SIAX Cloud) / security (pull_request) Successful in 14s
CI (SIAX Cloud) / security (push) Successful in 14s
CI (SIAX Cloud) / contracts (pull_request) Successful in 15s
CI (SIAX Cloud) / contracts (push) Successful in 17s
CI (SIAX Cloud) / quality (push) Successful in 1m9s
CI (SIAX Cloud) / quality (pull_request) Successful in 1m10s

- scan worker: atomic claim (FOR UPDATE SKIP LOCKED), Playwright-core + system
  chromium capture → typed EvidenceRecords (runtime-html/dom/computed-style/
  stylesheet/asset/network-request/screenshot), confidence=measured
- AUD0 emitter (fire-and-forget, advisory): c0py.registry_created/.scan_created/
  .scan_completed/.scan_failed, tenant_id = Zitadel resourceowner (org)
- tenant binding: resourceowner claim from introspection (deny-by-default 403),
  migration 002 tenant_id on registries+scans, all queries tenant+owner scoped
- evidence gaps stay explicit (screenshot miss → no screenshot record)
- 30/30 tests, canonical validator OK
This commit is contained in:
2026-09-16 22:53:55 +02:00
parent 7fb6043e34
commit 12f6a65b80
13 changed files with 757 additions and 52 deletions
+62
View File
@@ -0,0 +1,62 @@
import type { FastifyBaseLogger } from "fastify";
export interface Aud0Event {
event_type: string;
tenant_id: string;
project_id?: string;
actor_id?: string;
app_id: string;
capability_id: string;
resource_type: string;
resource_id: string;
risk_level: "L0" | "L1" | "L2" | "L3" | "L4" | "L5";
payload?: Record<string, unknown>;
source?: Record<string, unknown>;
}
export interface Aud0Emitter {
(event: Aud0Event): void;
}
export function createAud0Emitter(deps: {
baseUrl?: string;
authToken?: string;
logger?: FastifyBaseLogger;
fetchImpl?: typeof fetch;
}): Aud0Emitter {
const fetchImpl = deps.fetchImpl ?? fetch;
// Fire-and-forget per AUD0 doctrine: an AUD0 outage must never block the
// caller's real work. Failures are logged and dropped (advisory).
return (event) => {
if (!deps.baseUrl || !deps.authToken) {
deps.logger?.debug({ event_type: event.event_type }, "AUD0 not configured — event dropped");
return;
}
const url = `${deps.baseUrl.replace(/\/$/, "")}/v1/aud0/events`;
void fetchImpl(url, {
method: "POST",
headers: {
Authorization: `Bearer ${deps.authToken}`,
"x-tenant-id": event.tenant_id,
"x-actor-id": event.actor_id ?? "",
"Content-Type": "application/json",
},
body: JSON.stringify(event),
signal: AbortSignal.timeout(5000),
})
.then((res) => {
if (!res.ok) {
deps.logger?.warn(
{ status: res.status, event_type: event.event_type },
"AUD0 ingest non-2xx (advisory)",
);
}
})
.catch((err) => {
deps.logger?.warn({ err, event_type: event.event_type }, "AUD0 ingest failed (advisory)");
});
};
}
export const noopAud0: Aud0Emitter = () => {};