AISOCin‑a‑box

Detection Rules

Detection in this repository is a contract with a working transport, not a rule engine. The alert-push path — edge event → ECS-normalized doc → AlertMetadataPush → dedupe → triage — is implemented end-to-end in the reference stack. The box-side detection machinery the spec designs (a Sigma-compiled custom ruleset, the scheduled ES|QL poller, signed detection content delivery) is spec-only: it is WBS 1.5 (docs/spec/LWL-32-architecture-spec.md §6, Phase 1, weeks 4–5) and does not exist in the tree yet. This page documents exactly the boundary.

1. What actually fires alerts today

1.1 Edge leg — deploy/compose/edge/vector.toml

The only detection-adjacent pipeline in the repo is the Vector manifest, derived verbatim from spec §2.1 with two marked [DEPLOY] substitutions (compose endpoints, env-injected tenant). Pinned image: timberio/vector:0.47.0-debian (SOC_VECTOR_IMAGE).

Stage What it does Note
sources.syslog_514 TCP socket, in-container :5140 (the box maps 514 → 5140) Not port-published by compose — unreachable from the host in the reference stack
sources.edr_webhook HTTP JSON server, in-container :8080 Published at 127.0.0.1:8120 — the reference stack's only raw-event entry point
transforms.ecs_normalize VRL: JSON-merge message, default event.kind=event, event.category=["file"], host.hostname, user.name, rule.name, event.severity The "pinned ECS" behavior in the reference
transforms.redact_pii VRL, gdpr-standard profile: static guards on user.email, client.nat.ip, dns.question.name → [REDACTED:*], records redaction.profile/fields_redacted Vector 0.47 VRL has no dynamic array paths, hence the static per-field guards (commented in the manifest)
transforms.alert_tap Filter .event.kind == "alert" The split point: raw events keep flowing to ES; alert-kind events additionally spool
sinks.edge_elasticsearch Per-tenant index soc-box-ecs-${SOC_TENANT}-%Y.%m.%d, create action, gzip, 256 MiB disk buffer (outage tolerance) This is the index the triage graph's ESQL context hunter queries
sinks.agent_alert_queue ndjson file /var/lib/soc-box/spool/alerts/alerts.%Y-%m-%d-%H.ndjson The Edge Agent's inbox in the spec; in the reference stack nothing consumes it (there is no edge agent)

The seeder (db/seed/seed_demo.py) and the portal's /seed page both drive the webhook: POST http://vector:8080/ (host: 127.0.0.1:8120) with {"message": "<json>"} — ecs_normalize parses and defaults the message, so the event lands in the tenant's ES index with ECS fields the triage graph can match on.

1.2 Cloud leg — apps/control-plane-api/src/soc_api/routers/ingest.py

POST /api/alerts/ingest (top-level alert fields, not nested under "alert" — a nested body silently loses the ecs block). Order of operations, all under SET LOCAL app.tenant_id:

  1. Dedupe first, before any triage side effect (§1.4 step 2: spool replay must never start a second run or write a second audit trail). The idempotency key is (tenant_id, local_alert_id), unique-indexed in PG. A racing replay blocks on the unique index, rolls back, and re-reads up to 10 × 200 ms (kept under the 5 s statement timeout).
  2. Severity: trigger.numeric_severity if present (else 422 VALIDATION if it isn't an integer), else string map critical/high/medium/low/info → 5/4/3/2/1, default 3.
  3. Landing row in the alerts table (see §1.3), committed before triage — the row is the durable dedupe marker. Unknown edge_id falls back to NULL rather than FK-failing the push (fleet reconciliation sees it later).
  4. Bus publish, then a synchronous POST {orchestrator}/v1/triage (timeout 180 s). If the orchestrator is down, the alert is still durably landed and the response says triage: "deferred: orchestrator unreachable …" — the alert is not lost.
  5. Projection (_persist_projection): upsert into cases (state derived from the triage view: interrupt → awaiting_approval, remediated → contained, escalated_to_analyst → escalated, else triaging), link alerts.case_id, open the hitl_approvals row when the run interrupted.

1.3 The two PG tables that carry detection state

db/rls/01-schema.sql (both RLS-enforced — see multi-tenancy.md):

alerts (the AlertMetadataPush landing table, §1.2.4.a):

Column Notes
local_alert_id edge-assigned idempotency key, UNIQUE (tenant_id, local_alert_id)
trigger_type CHECK IN ('edr_rule','sigma','network','identity'); ingest writes trigger.type, defaulting to edr_rule
severity 1–5 smallint (see §1.2 step 2)
ecs JSONB, ECS-normalized metadata (redacted at the edge)
context_pointers index + window — never raw logs (see §2)
redaction JSONB, the push's redaction block
raw the full push envelope (what GET /api/cases/{id}/evidence shows)
case_id set when a triage run opened/attached a case

cases:

Column Notes
state new / triaging / awaiting_context / awaiting_approval / contained / monitoring / resolved / fp_confirmed / escalated
number human ref TGT-#### (last 4 of the orchestrator case id, uppercase)
detection_source hard-coded agent:triage-v1/phaseb in the reference projection (ingest.py line 145) — the column exists for the spec's rule_id / agent run ref, but nothing yet writes a rule id into it
mitre_techniques text[], from the triage verdict

1.4 The demo "rules"

There is no rule engine, so the demo path fakes one with markers. seed_demo.py::_alert_payload (and the portal's /seed) stamp each alert with meta.rule_id = "seed-{kind}" and meta.hitl = "1"|"0". The reference orchestrator's stub LLM lane reads exactly that marker (triage_graph.node_verdict_attack_mapping):

  • hitl = "0" (token-revoke shape) → autonomous lane, verdict token_revoke, MITRE T1078, confidence 0.88 → contained without a human.
  • hitl = "1" and the prompt text carries HIGHBLAST (the seeder/portal use ransomware-staging / lateral-movement shapes) → high-blast-radius lane, host_isolate + ioc_enrichment_push, T1489/T1021, confidence 0.93 → awaiting_approval interrupt.

These are test doubles for the verdict node, not detections: the "rule" that fired is simulated by whatever body you POST to ingest. See llm-triage.md for the verdict internals and the stub lanes' full table.

2. The contract a rule must emit — AlertMetadataPush (spec §1.2.4.a)

Spec line 403. Canonical form is the protobuf AlertMetadataPush inside a TunnelFrame; the JSON view below is what the reference stack speaks (reference deviation: plain HTTP to :8117, no tunnel, no protobuf — see §5). A box-side rule engine (when built, WBS 1.5) must produce:

{
  "local_alert_id": "edge-7f3a:2026.11.21:000123",   // edge-assigned idempotency key — the dedupe identity
  "trigger": {
    "type": "es_rule",                                // edr_rule | sigma | network | identity (PG CHECK)
    "rule_id": "crowdstrike_credential_access_t1558", // rule identity; spec §4.5.9 carries detection_rule_id
    "rule_name": "Kerberoasting burst",
    "severity": "high",                               // or numeric_severity (1-5) — ingest maps both
    "risk_score": 78
  },
  "ecs": { /* ECS field names only — validated against the pinned ECS package on the edge before send */ },
  "redaction": {                                      // MANDATORY: an alert failing the redaction profile is
    "profile": "gdpr-standard",                       // dropped at the edge and counted in
    "fields_redacted": ["user.email","client.nat.ip"] // soc_edge_redaction_drops_total — never silently sent
  },
  "context_pointers": {                               // replaces raw-log exfiltration; the cloud
    "index": "soc-box-ecs-tnt_acme_01-*",             // agent follows up with a federated ES|QL
    "window_start": "2026-11-21T09:58:55Z",           // query scoped to this index/window
    "window_end": "2026-11-21T10:08:55Z",
    "doc_ids": []
  },
  "asset": { "criticality": "high", "owner_group": "finance-it", "tags": ["pci-scope"] }
}

Contract rules (spec §1.2.4.a): batch ≤ 500 alerts or 1 MB; ECS field names only; context_pointers is the only sanctioned path by which event context reaches the cloud.

Hard requirement discovered live: window_start / window_end must be present ISO-8601 strings. The orchestrator's triage_graph.window_params (line 392) binds the context hunter's ?ts_start / ?ts_end parameters from them; a context_pointers dict without them 500s the triage run (KeyError). The portal's _seed_alert carries an explicit comment about this.

3. How detection is designed to work (spec-only, not in the repo)

Spec location What it says
§1.1 (line 234) Detection triggers are custom edge rules evaluated locally on the customer's box. [LIC?] prebuilt SIEM detection content is assumed Platinum/Enterprise-only and is deliberately not load-bearing; the fallback is our own Sigma-compiled custom ruleset in edge/config plus scheduled ES|QL queries run by the Edge Agent poller.
WBS 1.5 (Phase 1, weeks 4–5, 6 dev-days) "Box-side detection → enriched alert envelope → tunnel-gateway → PostgreSQL alerts table (partitioned by tenant, month)." This is the work item the reference stack's ingest endpoint stands in for.
§1.4 (line 737) Happy path: edge rule fires → alert doc → Edge Agent builds the redaction-checked AlertMetadataPush → cloud within RTT + 1 s. Tunnel down → 24 h spool ring on disk, replay on reconnect, dedupe by local_alert_id.
§2.4 (lines 1030–1031) Delivery: config bundles (Vector manifests, detection rules, redaction profiles, OPA policy bundles) ship as signed OCI application/vnd.soc.config+tar.zst with hot-reload and a policy_digest echo in heartbeats; detection content (Sigma → ES-detection-rules, compiled) ships as a signed tar.zst artifact on a daily cadence with a customer-visible changelog.
§5 tree (line 5022) ecs-mapping/ = ECS field catalog pin + Sigma→ES-rule compiler + redaction-profile DSL. edge/config/ holds the compiled ruleset.
§3.5 (line 3379) The cloud-side half that does exist: the ES|QL pre-flight validator re-checks signature, index allow-list, caps, and risk tier on every federated query (implementation: esql_validator.py, 5 rules — see llm-triage.md).

So the designed pipeline is: Sigma source → (compiler, ecs-mapping/) → ES detection rules + edge ruleset → local evaluation → AlertMetadataPush (redaction-checked) → tunnel → alerts table → triage. The repo currently implements everything from AlertMetadataPush rightward, plus the Vector edge that produces the ECS docs and spool.

4. Authoring a detection today (what you can actually do)

Until WBS 1.5 lands, "a detection" in the reference stack is a well-formed alert pushed through the real path. Two entry points, both verified:

(a) Push a raw event to the edge — it lands in the tenant's ES index through the real Vector pipeline (ECS defaults + PII redaction applied):

curl -s http://127.0.0.1:8120/ \
  -H 'Content-Type: application/json' \
  -d '{"message": "{\"event\": {\"kind\": \"event\", \"category\": [\"process\"]}, \"host\": {\"hostname\": \"WS-ACME-0117\"}, \"user\": {\"name\": \"corp-j.doe\"}, \"timestamp\": \"'$(date -Iseconds)'\"}"}'

(Events with event.kind: "alert" additionally hit the alert_tap spool; they also land in ES either way.)

(b) Push an alert to the cloud — the full path, dedupe → triage → case. Body is the alert's fields at top level:

curl -s http://127.0.0.1:8117/api/alerts/ingest \
  -H 'Content-Type: application/json' \
  -H 'X-Tenant-Id: tnt_acme_01' \
  -H 'X-Actor-Subject: edge-agent' \
  -d @alert.json

alert.json (minimal shape that opens a case and runs the triage graph):

{
  "edge_id": "edge-acme-01",
  "local_alert_id": "myrule-2026-11-25-0001",
  "trigger": {"type": "edr_rule", "severity": 4, "rule_id": "myrule-c2-beacon"},
  "title": "C2 beacon from WS-ACME-0117",
  "ecs": {
    "@timestamp": "2026-11-25T10:03:55.9Z",
    "event": {"kind": "alert", "category": "network", "severity": 4},
    "host": {"hostname": "WS-ACME-0117"},
    "user": {"name": "corp-j.doe"}
  },
  "asset": {"hostname": "WS-ACME-0117", "os": "windows", "criticality": "high"},
  "context_pointers": {
    "index": "soc-box-ecs-tnt_acme_01-*",
    "window_start": "2026-11-25T09:58:55Z",
    "window_end": "2026-11-25T10:08:55Z",
    "doc_ids": []
  },
  "redaction": {"profile": "gdpr-standard", "fields_redacted": 0}
}

Notes:

  • Re-pushing the same local_alert_id returns the original {alert_id, case_id, "deduped": true} — the §1.4 step-2 guarantee.
  • The response carries case_id plus the full synchronous triage view (state, verdict, interrupt if HITL was requested, outcome).
  • meta.rule_id + meta.hitl are what the stub verdict lane keys on (§1.4); a real ruleset would instead be evaluated on the box and the trigger block would carry the real rule identity.
  • To query what a "detection" already produced, use the investigation side: POST /api/esql (tenant-scoped ES|QL, allow-listed indices, 5-rule validator — llm-triage.md §ES|QL) and GET /api/cases / GET /api/cases/{id}/timeline (this page's §1.3).

5. Honest gap list

Item Status
Sigma → ES-rule compiler (ecs-mapping/, spec §5 line 5022) Not in repo. Spec-only. (The ES|QL parser is separately a TODO(no-named-library) open item — spec §3.8.)
Box-side rule engine + edge/config ruleset Not in repo. WBS 1.5, Phase 1 weeks 4–5.
Scheduled ES|QL poller (the [LIC?] fallback for prebuilt SIEM content) Not in repo. Spec-only (§1.1).
Tunnel (TunnelFrame over mTLS/WireGuard, §1.2.4) Not in the reference stack. Edge→cloud is plain HTTP to :8117; the seeder/portal speak JSON directly. WBS 1.1–1.3.
cases.detection_source carrying a rule id Hard-coded agent:triage-v1/phaseb in _persist_projection; the column and the spec's rule_id / agent run ref semantics are ready, the writer is not.
alerts.trigger_type = 'sigma' Accepted by the CHECK constraint; nothing in the repo emits sigma-typed alerts.
agent_alert_queue spool consumer The spec's Edge Agent would drain it; the reference stack has no edge agent, so the spool is write-only.
Signed detection content delivery (§2.4, daily artifact + changelog) Spec-only; nothing ships or verifies detection artifacts yet.
Prebuilt SIEM detection content Deliberately out of scope ([LIC?] — licensing review spans Phase 1–2); the spec never assumes a paid tier as load-bearing.

Bottom line: you can end-to-end test everything a detection does after it fires (ingest, dedupe, triage, HITL, audit, tenancy) against the reference stack today; you cannot yet test the act of firing, because the rule engine is the WBS 1.5 deliverable. Marketing/docs must not claim otherwise (repo convention: never advertise a capability the gates don't test).