Open-source AI Security Operations Center: alert fusion, LLM-agent triage, MITRE ATT&CK investigation, and a replayable decision ledger for every agent step. Self-hostable, runs with no API keys, MIT licensed. Ships an MCP server for Claude, Cursor and Continue.
Python agentic-aiai-securityalert-triageblue-teamcybersecuritydetection-engineeringincident-responselanggraphllm-agentsmcpmitre-attackmodel-context-protocolpurple-teamsecurity-operationsself-hostedsiemsoarsocthreat-detectionthreat-intelligence
Merge PR #1307: depth 7.1 — reported phish from intake to purge
beenuar34531cb1495f
diff --cc .train_resolve.pyindex 000000000,000000000..a5b90640enew file mode 100644--- /dev/null+++ b/.train_resolve.py@@@ -1,0 -1,0 +1,54 @@@++#!/usr/bin/env python3++"""Train conflict resolver for the recurring tracker shapes (session tool, not shipped).++++Usage: python3 .train_resolve.py <file> <mode>++ modes:++ union -> ours + theirs for every hunk++ theirs -> theirs for every hunk++ roadmap -> theirs, deduping repeated 'claim-to-gate matrix stands at' paragraphs++Run from the worktree root. Refuses to leave markers behind.++"""++import re++import sys++import pathlib++++CONFLICT = re.compile(r"<<<<<<< [^\n]*\n(.*?)(?:\|\|\|\|\|\|\| [^\n]*\n.*?)?=======\n(.*?)>>>>>>> [^\n]*\n", re.DOTALL)++++++def dedupe_matrix_paragraph(text: str) -> str:++ paras = [p for p in text.split("\n\n") if p.strip()]++ firsts = [p for p in paras if p.lstrip().startswith("The claim-to-gate matrix stands at")]++ if len(firsts) > 1:++ return firsts[0] + "\n\n"++ return text++++++def main() -> None:++ path, mode = sys.argv[1], sys.argv[2]++ p = pathlib.Path(path)++ t = p.read_text()++ out, idx, n = [], 0, 0++ for m in CONFLICT.finditer(t):++ ours, theirs = m.group(1), m.group(2)++ if mode == "union":++ r = ours + theirs++ elif mode == "theirs":++ r = theirs++ elif mode == "roadmap":++ r = dedupe_matrix_paragraph(theirs)++ else:++ raise SystemExit(f"unknown mode {mode}")++ out.append(t[idx : m.start()])++ out.append(r)++ idx = m.end()++ n += 1++ out.append(t[idx:])++ res = "".join(out)++ if "<<<<<<<" in res or ">>>>>>>" in res:++ raise SystemExit(f"{path}: markers left behind")++ p.write_text(res)++ print(f"{path}: {n} hunks -> {mode}")++++++if __name__ == "__main__":++ main()diff --cc CHANGELOG.mdindex 25ed8634b,2235577c3..5c54eea96--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -231,66 -231,81 +231,141 @@@ and this project adheres to [Semantic V### Added+- **Endpoint discovery of the AI estate, with no new agent** (depth plan 6.2).+ `packs/aisoc-ai-estate.yaml` finds coding agents and MCP server processes,+ the configuration files the popular MCP clients read, AI IDE extensions and+ model-provider credential files, through the osquery agent a fleet already+ runs. `apps/docs/docs/concepts/ai-estate-discovery.md` records what each+ source can **and cannot** see, which is the half that makes an empty column+ readable: a device missing from a provider-audit row is not a finding,+ because no provider audit log has ever carried one.++ The finding that made this a fix as well as a feature: the endpoint branch+ of the recorder read `process.name` off the OCSF event, and the canonical+ OCSF profile carries `title`, `external_id` and the identity aliases and+ nothing else. `fleetdm`, `osctrl`, `auditd` and `windows_event` all put+ their process fields in the connector payload under `raw_data`, so that+ branch found `None` on every endpoint source this product has and could+ never have produced one row — while its own tests passed, because they+ built events in the shape the module expected. It now reconstructs the same+ flat namespace `DetectionEngine._raw_fields` does, and+ `scripts/check_ai_endpoint_discovery.py` makes reading it a rule.++ Recorded rather than implied: `crowdstrike`, `sentinelone` and+ `azure_defender` poll the vendor's own **detections**, not raw process+ telemetry, so they cannot supply a process start. An operator running an+ EDR and nothing else has a coverage gap here, not a quiet estate, and the+ documentation says so in a callout.++- **An AI-estate inventory built from observation rather than registration**+ (depth plan 6.1). `aisoc_ai_assets` (migration `110`, tenant-scoped with+ forced row-level security) holds every AI app, coding agent, MCP server,+ IDE extension, model-provider key and OAuth grant AiSOC has seen, with the+ person and device behind each. The gap it closes is that `aisoc_mcp_servers`+ records what an operator *declared*, and the row that matters in an AI+ governance review is the one present in observation and absent from the+ declaration.++ Measured the way the recurring defect here demands: the writer is in the+ fusion consumer's raw-events branch, the one path every normalized event+ already travels on the default profile, because a recorder behind a flag or+ in a service CORE does not start is a table nothing writes and a page that+ renders "no AI estate" to a tenant that has one.+ `scripts/check_ai_asset_inventory.py` makes that a rule rather than a+ comment — it requires the consumer to call the recorder *and* the service+ to construct it, since an unconstructed recorder is a `None` every call+ site skips in silence. `ai-estate-live.yml` writes a fixture estate of+ three kinds into a real PostgreSQL as the DML-only `aisoc_app` role, and+ two negative controls re-inject real defects: reverting `NULLS NOT+ DISTINCT` on the identity constraint turns one provider-key row into+ three, and a tenant policy of `USING (true)` lets one tenant read+ another's estate.++ Also: graph schema `v1.2 → v1.3` adds the `AIAsset` label with+ `(:User)-[:OPERATES]->(:AIAsset)` and `(:Endpoint)-[:HOSTS]->(:AIAsset)`,+ emitted by `services/ingest` as a post-pass rather than a connector case —+ AI telemetry arrives on three connector types and as plain process+ activity, so keying on the connector would have covered one of them and+ looked complete. A new `ai_estate:read` / `ai_estate:write` permission+ pair, held by real roles and mintable into an API key, because the+ inventory names which agent on which laptop holds which provider key and+ `hunts:read` already demonstrated what a permission no role holds is worth.++ - **A reported message's headers, URLs and attachments are analysed once and+ cited where an auditor looks (depth 7.2).** Nothing in the tree read an+ `Authentication-Results` header before this — `grep -rl+ "authentication-results" services/` returned no match — so a message whose+ SPF and DMARC had both failed at the receiving boundary produced a verdict+ that had never looked. The analysis is three components in one pass, and+ the rule it turns on is that **an unanalysed artefact must never read as a+ clean one**, which is the same rule the submit path already applied to+ attachments and which `services/api/app/services/phishing/headers.py` now+ applies to authentication. SPF, DKIM and DMARC each carry three values, and+ the third is the point: `not_evaluated` is published rather than folded+ into either of the others, and `neutral`, `none`, `permerror` and+ `temperror` are **not** passes — treating them as passes is how a domain+ with a broken SPF record reads as authenticated. A URL on a deployment with+ no provider configured says so per URL rather than vanishing from the+ output, and that specific defect was found by a negative control that at+ first failed to fail, because the tests built their own result list instead+ of driving the producer. `analysed` and `unanalysed` are counted separately+ and never summed — in the dataclass, the response model and migration+ `111`'s column comment — because the sum is the number this product must+ not publish: five artefacts nothing examined, rendered as "5 artefacts, 0+ findings", says the opposite of what happened. The verdict is only ever+ raised, and SPF **and** DMARC must both fail to raise it, because a+ forwarded message routinely breaks SPF and flagging that would alert on+ every mailing list in the estate. Citations go into the investigation+ ledger as `evidence_cited` rows, one per component, written even when a+ component found nothing — a ledger with no row for the URL check cannot be+ told from one where the check passed. The ledger suite has no teardown by+ design: deleting a run cascades to its events, migration `008`'s trigger+ refuses, and defeating an append-only control to tidy a test fixture would+ be the wrong fix.+ - **Reported phish now goes from intake to purge (depth 7.1).** The gap was+ not that phishing was unhandled — `POST /phishing/submit` has triaged+ artefacts since migration 015 — but that nothing in the product could+ *remove a message*. The live-action registry held 79 builtin arms and not+ one could touch a mailbox, so governed dispatch answered+ `executor_not_found` for `purge_email`: a response that could block the+ sender's domain at the firewall and could not take back the mail. Five+ verbs enter both halves of the capability vocabulary (`search_mailboxes`,+ `purge_email`, `restore_email`, `block_sender`, `unblock_sender`) with ten+ vendor arms over Microsoft Graph and the Gmail API. Only what the vendors+ document: purge is a move to `recoverableitemsdeletions` or to Trash, never+ a hard delete, and `restore_email` is a real reverse rather than a declared+ one. There is deliberately **no tenant-wide blocked-sender verb**, because+ neither vendor exposes its organisation-level block list through these+ APIs; the sender block is per mailbox and says so in the summary an analyst+ reads, not only in a docstring. Reported-message intake normalises three+ sources into one record — an M365 report mailbox over Graph, Workspace user+ reports, and the existing `email_inbox` connector — and the hard case is+ the common one: a user who reports by forwarding becomes the *sender*, so+ the adapter reads the original sender and recipients out of the preserved+ headers and leaves the sender empty rather than naming the victim as the+ attacker. Campaign grouping is a five-step ladder and `grouping_basis`+ records which step matched, because four are facts about the message and+ subject similarity is a judgement. The purge is **one proposal and one+ dispatch per mailbox**: handing a single executor twenty-five addresses+ would be one approval covering a list the approver never read.+ `scaled_impact` turns the recipient count into the tier — MODERATE at one,+ HIGH at five, SEVERE at twenty-five, where `NEVER_AUTONOMOUS` makes it+ mandatory-human at any confidence and any autonomy tier — and the proposal+ and every dispatch under it read the same function, so the approver and the+ executor cannot see different actions. Verification re-queries the mailbox,+ and that probe is the one in the service whose confirming answer is an+ *absence*. Everything ships **off**: `AISOC_FEATURE_MAILBOX_REMEDIATION`+ and `PHISHING_INTAKE_WORKER_ENABLED` both default false, and a disabled+ deployment answers FAILED naming the setting rather than simulating a purge+ — `NotifySlackExecutor` reporting `message_sent: true` for a message it+ never sent is the precedent. Migration `110`. Gates:+ `check_action_contract.py` (86 → 97 executors), `check_module_reachability.py`+ (981 → 986 reachable), `check_vendor_catalog_ids.py`,+ `test_mailbox_remediation.py` (60 cases through real `respx` HTTP) and+ `test_phishing_campaign_purge_live.py` (17 cases against a real Postgres+ with the full chain). **No Microsoft 365 or Google Workspace tenant was+ exercised**: every vendor claim rests on the documented request shape and a+ mock.- `services/api/app/models/detection_rule.py` maps the `author` column, whichhas existed since `001_init.sql` and was mapped by nothing — while fusion'stenant overlay reads it on every reload to say *who* silenced a rule when itdiff --cc DEPTH_PROGRESS.mdindex d2ab71a62,03630e6d7..c11663078--- a/DEPTH_PROGRESS.md+++ b/DEPTH_PROGRESS.md@@@ -77,19 -70,8 +77,21 @@@ is written. Next free at capture: migra| migration `113` | 8.1 — `113_entitlement_enforcement.sql` | claimed || ADR `0011` | 8.1 — truncating a hash-chained audit log | claimed |+| migration `104` | 5.4 stateful user/manager verification (verification requests, answers, tenant opt-in) | claimed |+| migration `105` | 5.6 plain-language playbook drafts (draft, preview, approval) | claimed |++Lane B claimed `102`/`103` and landed that claim on `main` first, so Lane C's+two moved to `104`/`105` and `102_playbook_verification.sql` was renamed with+it. Both lanes had claimed before writing, as the plan requires -- what the+rule cannot prevent is two lanes claiming the same free number before either+merges, so re-read `services/api/migrations/` **and** this table before+picking one.+| migration `110` | 6.1 — `110_ai_assets.sql` | claimed |+| migration `111` | 6.4 — `111_ai_agent_identities.sql` | claimed |+| ADR `0011` | 6.6 — AI containment arms off by default, and the rollback a kill-switch needs | claimed |+| — | 5.4 — `104_playbook_verification.sql` on `depth/5.4-5.6-lane-c`, and 7.1 — `104_phishing_campaigns.sql` on `depth/7.1-7.3-phishing` | **collision, unresolved here.** Both lanes wrote a `104` on a branch without a row in this table. Phase 9's `104` is the one with a claim, so these two need renumbering by their own lanes; recorded rather than renamed from outside, because renaming another lane's migration from here is how a branch comes back to a file that no longer exists |+ | migration `110` | 7.1 — `110_phishing_campaigns.sql` | claimed |+ | migration `111` | 7.2 — `111_phishing_message_analysis.sql` | claimed |Highest migration on `main` at claim time was `101_audit_immutable_nullify.sql`,so `095`--`101` were taken by sibling lanes between the capture above and this@@@ -113,14 -90,15 +115,23 @@@ sub-items that need no schema — the cinternationalisation and accessibility — claim no number. The same releaserule applies: an unused number is struck, not silently skipped.+**Phase 6 moved `105`/`106` to `110`/`111` on 2026-10-11**, because Phase 9's+claim for `104`--`109` reached this table on `main` first and a claim table+nobody defers to is not a coordination mechanism. The lesson is the one this+section already states and that three lanes still fell to: the table is+authoritative only for lanes that write to it **before** the file, and four+branches now carry a `104` or a `105` that was never claimed here. Reading+`main` is not enough; read `git ls-tree` over every `origin/*` branch as+well, which is what found this.+ Phase 7 claimed `104` and `105` on the same day and **lost the race**: Phase 9+ merged to `main` first, so Phase 7 renumbered to `110` and `111` rather than+ leaving two files with one number each. Both lanes re-read the directory+ before claiming and both read `101`, which is the shape a claim table cannot+ prevent on its own — the table is the tiebreak, and whoever lands second+ moves. Recorded because the next lane will hit it too: re-read+ `DEPTH_PROGRESS.md` on `origin/main`, not only the migrations directory, and+ expect to renumber if a sibling merged between the claim and the pull+ request.## Phase 0: Kickoffdiff --cc ROADMAP.mdindex 2218cdb8e,c55c8730d..16634b2af--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -45,8 -45,11 +45,8 @@@ A proof-first, security-first program t- **Phase D (breadth):** D1 eight connectors (QRadar/Exabeam/Securonix/Devo/Netskope/Windows-Sysmon/Zeek-Suricata/syslog-CEF) · D2 AI/LLM-usage audit connector + `llm-*` detections + hot/cold lake tiering · D3 live-vendor mock-server smoke.- **Phase E (prove it):** E1 CI-gated benchmark scoreboard tied to a deterministic live-agent MITRE-accuracy run.- The claim-to-gate matrix stands at **304 rows — 301 GATED / 3 PARTIAL / 0 NO GATE**. Two rows are PARTIAL. "The retention window a tenant chooses is the one the lake honours" stays PARTIAL until a live ClickHouse test watches a row survive past the old 90-day boundary. "Cloud-native collection" stays PARTIAL until a capture recorded from a live Event Hub replaces the fixture synthesised from the Avro specification. "SSO completes a sign-in" was the third, and depth 8.1 closed it by building the gate it named rather than by relabelling: `sso-live.yml` now stands up a containerised Keycloak and both legs have been observed to pass — `keycloak-oidc` takes a real `id_token` through `_verify_id_token` against the provider's published JWKS, and `keycloak-saml` walks the whole SP-initiated flow to the real ACS. Every other product claim is backed by a failing test, none is a named deferral either, and the ratchet (`MAX_NO_GATE=0`) forbids any regression. Every PARTIAL row was closed by building the gate it named, never by relabelling. The last two rested on the live-agent eval workflow, which this file said had simply never run: the real reason was that its live path imported a class that exists nowhere in `services/agents`, so its first dispatch failed in 92 seconds and every later one would have. With that fixed the workflow measures, and the groundedness floor is **0.40 over a deterministic 10-incident slice**, derived from ten runs across two environments rather than chosen — seven local runs returning 0.5561 to four decimal places, three GitHub-runner runs returning 0.5821, 0.5329 and 0.5933. Every one is a locally-served `qwen2.5:0.5b`; no hosted provider has been exercised and the floor describes none. Count the table rows with `python3 scripts/check_claim_gate_matrix.py` rather than trusting a figure quoted in prose — this line has gone stale before. The six lettered deferrals are scoped in [`docs/audit/DEFERRED_SUBPHASES.md`](docs/audit/DEFERRED_SUBPHASES.md).+ The claim-to-gate matrix stands at **304 rows — 301 GATED / 3 PARTIAL / 0 NO GATE**. Four rows are PARTIAL. "A reported phishing message can be grouped into a campaign and purged across its recipients" is PARTIAL because no Microsoft 365 or Google Workspace tenant is reachable from CI or from this maintainer, so every vendor claim in depth 7.1 rests on the documented request shape and a recorded mock; it returns to GATED when a live tenant is available. "The retention window a tenant chooses is the one the lake honours" stays PARTIAL until a live ClickHouse test watches a row survive past the old 90-day boundary. "Cloud-native collection" stays PARTIAL until a capture recorded from a live Event Hub replaces the fixture synthesised from the Avro specification. And "SSO completes a sign-in": fix pass 4.1 drove both handlers end to end against real Postgres and real signed assertions, and it stays PARTIAL until the containerised-IdP leg of `sso-live.yml` has been observed to pass, because the identity providers in that suite are trust material this repository authors. Every other product claim is backed by a failing test, none is a named deferral either, and the ratchet (`MAX_NO_GATE=0`) forbids any regression. Every PARTIAL row was closed by building the gate it named, never by relabelling. The last two rested on the live-agent eval workflow, which this file said had simply never run: the real reason was that its live path imported a class that exists nowhere in `services/agents`, so its first dispatch failed in 92 seconds and every later one would have. With that fixed the workflow measures, and the groundedness floor is **0.40 over a deterministic 10-incident slice**, derived from ten runs across two environments rather than chosen — seven local runs returning 0.5561 to four decimal places, three GitHub-runner runs returning 0.5821, 0.5329 and 0.5933. Every one is a locally-served `qwen2.5:0.5b`; no hosted provider has been exercised and the floor describes none. Count the table rows with `python3 scripts/check_claim_gate_matrix.py` rather than trusting a figure quoted in prose — this line has gone stale before. The six lettered deferrals are scoped in [`docs/audit/DEFERRED_SUBPHASES.md`](docs/audit/DEFERRED_SUBPHASES.md).-The claim-to-gate matrix stands at **304 rows — 301 GATED / 3 PARTIAL / 0 NO GATE**. Two rows are PARTIAL. "The retention window a tenant chooses is the one the lake honours" stays PARTIAL until a live ClickHouse test watches a row survive past the old 90-day boundary. "Cloud-native collection" stays PARTIAL until a capture recorded from a live Event Hub replaces the fixture synthesised from the Avro specification. "SSO completes a sign-in" was the third, and depth 8.1 closed it by building the gate it named rather than by relabelling: `sso-live.yml` now stands up a containerised Keycloak and both legs have been observed to pass — `keycloak-oidc` takes a real `id_token` through `_verify_id_token` against the provider's published JWKS, and `keycloak-saml` walks the whole SP-initiated flow to the real ACS. Every other product claim is backed by a failing test, none is a named deferral either, and the ratchet (`MAX_NO_GATE=0`) forbids any regression. Every PARTIAL row was closed by building the gate it named, never by relabelling. The last two rested on the live-agent eval workflow, which this file said had simply never run: the real reason was that its live path imported a class that exists nowhere in `services/agents`, so its first dispatch failed in 92 seconds and every later one would have. With that fixed the workflow measures, and the groundedness floor is **0.40 over a deterministic 10-incident slice**, derived from ten runs across two environments rather than chosen — seven local runs returning 0.5561 to four decimal places, three GitHub-runner runs returning 0.5821, 0.5329 and 0.5933. Every one is a locally-served `qwen2.5:0.5b`; no hosted provider has been exercised and the floor describes none. Count the table rows with `python3 scripts/check_claim_gate_matrix.py` rather than trusting a figure quoted in prose — this line has gone stale before. The six lettered deferrals are scoped in [`docs/audit/DEFERRED_SUBPHASES.md`](docs/audit/DEFERRED_SUBPHASES.md).--The claim-to-gate matrix stands at **304 rows — 301 GATED / 3 PARTIAL / 0 NO GATE**. Four rows are PARTIAL. "A reported phishing message can be grouped into a campaign and purged across its recipients" is PARTIAL because no Microsoft 365 or Google Workspace tenant is reachable from CI or from this maintainer, so every vendor claim in depth 7.1 rests on the documented request shape and a recorded mock; it returns to GATED when a live tenant is available. "The retention window a tenant chooses is the one the lake honours" stays PARTIAL until a live ClickHouse test watches a row survive past the old 90-day boundary. "Cloud-native collection" stays PARTIAL until a capture recorded from a live Event Hub replaces the fixture synthesised from the Avro specification. And "SSO completes a sign-in": fix pass 4.1 drove both handlers end to end against real Postgres and real signed assertions, and it stays PARTIAL until the containerised-IdP leg of `sso-live.yml` has been observed to pass, because the identity providers in that suite are trust material this repository authors. Every other product claim is backed by a failing test, none is a named deferral either, and the ratchet (`MAX_NO_GATE=0`) forbids any regression. Every PARTIAL row was closed by building the gate it named, never by relabelling. The last two rested on the live-agent eval workflow, which this file said had simply never run: the real reason was that its live path imported a class that exists nowhere in `services/agents`, so its first dispatch failed in 92 seconds and every later one would have. With that fixed the workflow measures, and the groundedness floor is **0.40 over a deterministic 10-incident slice**, derived from ten runs across two environments rather than chosen — seven local runs returning 0.5561 to four decimal places, three GitHub-runner runs returning 0.5821, 0.5329 and 0.5933. Every one is a locally-served `qwen2.5:0.5b`; no hosted provider has been exercised and the floor describes none. Count the table rows with `python3 scripts/check_claim_gate_matrix.py` rather than trusting a figure quoted in prose — this line has gone stale before. The six lettered deferrals are scoped in [`docs/audit/DEFERRED_SUBPHASES.md`](docs/audit/DEFERRED_SUBPHASES.md).## v4.0 — Shipped