Files
Beenu Arora 296c92926e feat(siem): content inventory, rule health, outbound translation and the governed tuning arm (WS1.2–1.6) (#2014)
## What

WS1.2–1.6 of the gap-closure program: detection engineering on the
customer's SIEM. The rule-health/proposal machinery existed for
AiSOC-native rules only; this PR grows the SIEM-facing counterpart Phase
0 recorded as missing.

## WS1.2 — The content inventory (migration 180)

- **Connectors side**: `POST /connectors/{id}/content` beside `/query`,
same trust boundary (vault-decrypted upstream, instance lives per
request), 501 refusal for unopted connectors. Splunk lists
scheduled/correlation saved searches from the documented
`/services/saved/searches` collection (ad-hoc searches filtered out —
pinned); Elastic lists Security rules from Kibana's documented `_find`,
carrying the rule's own ATT&CK mapping where set and empty where not
(pinned). Both bounded and paged per the vendor contract.
- **API side**: one row per (tenant, connector, vendor rule) with a
SHA-256 over the behaviour-defining fields. **Drift is a fact**: an
unchanged hash advances `last_seen`; a changed hash bumps `version` and
keeps `previous_hash` — the upsert's own CASE, proven live both ways
(negative control: disabling the CASE fails the drift case). RLS
isolation proven under the NOBYPASSRLS role.
- **Refresh**: a scheduled sweep (6h default — the vendor admin APIs are
rate-limited surfaces) through the leader-guarded worker wrapper, plus
on-demand from the console. One SIEM's failure is a per-source verdict,
never the sweep's.

## WS1.3 — Rule health from outcomes

Alerts join the inventory on their own `rule_id`/`rule_name` provenance.
**Every rate carries its denominator**: FP rate is `fp / DISPOSED` (the
live test pins 1-of-2 with the open alert excluded), and zero disposed
reads **"not measured" — never 0.0** (pinned on a never-fired rule).
Vendor execution state only where the listing exposed it;
`could_not_check` otherwise (pinned).

## WS1.5 — Outbound translation, provably paired with inbound

`packages/aisoc-migrate/outbound.py`, bound by one contract: **outbound
then inbound must reproduce the same rule.** The carryable subset is
exactly what `inbound.translate` parses back (eq/neq/gt/gte/lt/lte over
scalars); every fixture roundtrips through the REAL inbound with
`match_when` equality asserted, across SPL, KQL and EQL. Operators a
dialect could technically express but inbound cannot read back
(contains-as-wildcard, lists, regex) **refuse with the roundtrip
reason**; one refused clause refuses the whole rule (a partial rendering
matches MORE than the original); windowed rules refuse citing inbound's
own PARTIAL-on-aggregation; SPL routing fields refuse because inbound
drops them (and the same rule roundtrips via KQL where `index` is an
ordinary field — pinned). **AQL is render-only and says so**:
'translated' and 'translated and provable' are different claims.

## WS1.6 — The governed tuning arm

`POST /siem-content/tuning-proposals`:
exclusion/threshold/severity/disable/new-rule changes land as DRAFTs on
the same `detection_rule_proposals` path native rules use
(author-is-not-approver is that path's own rule). A proposal citing a
rule not in the inventory is refused — proposals cite content that
exists. Applying an approved change rides the fixed per-vendor
`sync_detection_rule` verb with WS1.1's content read-back verification
and prior-content rollback.

## Console

A **SIEM content** tab under /detection: inventory + health in one view,
honest states throughout (unreachable API shows the error; empty
inventory explains the refresh path; a rate with no denominator renders
"not measured"). `tsc --noEmit` clean.

## Recorded follow-ups (seams named, not silently absent)

- Sentinel and QRadar inventory legs — the `/content` route and
`sweep_tenant` take new vendors without schema changes.
- WS1.4 silent sources — per-source policy + budgeted count queries; a
workstream of its own.
- The federated-search backtest on tuning proposals.

## Testing

- **3 live-Postgres cases** (new `integration.yml` step):
versioning/touch/drift with the prior hash kept; RLS isolation; health
denominators incl. both not-measured shapes. Negative control on the
drift CASE (applied, failed, restored).
- **3 mock-vendor cases** (connectors) from the published response
schemas + the 501 refusal.
- **7 roundtrip/refusal cases** (migrate) through the real inbound.
- Full API suite **5,593 passed** post-rebase (the WS4.4 merge landed
mid-work; conflicts resolved with counters re-derived against post-merge
main: matrix 409+3=412/403, predicate ratchet 82+1=83).

## Gates

tenant_query_predicates OK (ratchet → **83**, the sweep's enumeration
recorded) · route_auth OK · migration_numbering OK (180, allocated) ·
mypy baseline OK · ruff clean · claim matrix **+3 GATED rows** ·
readme_gates OK · merge-markers OK · OpenAPI regenerated.

## Could not verify

- The Splunk/Elastic legs against live vendor tenants (no credentials
here): the clients speak the documented admin APIs and the mock-vendor
fixtures are shaped from the published schemas.
- The scheduled sweep's leader lease under multi-replica contention: it
rides the same `_run_guarded_scheduler_worker` wrapper every other API
worker uses.
2026-11-23 16:27:25 -08:00
..