Skip to content

armgit / AiSOC

Public Imported from GitHub
0

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.

Merge PR #1310: depth 2.5 — posture snapshots

beenuar5fe103727876
diff --cc DEPTH_PROGRESS.md
index c11663078,85e76671c..e1a5b812a
--- a/DEPTH_PROGRESS.md
+++ b/DEPTH_PROGRESS.md
@@@ -458,47 -412,42 +458,83 @@@ Instead, every selector field, `group-b
against the emitted-field namespace with **no ceiling**, which caught three
invented fields on the first run of the gate.
+### D11 -- A durable `wait` suspended the run and then carried on
+
+Found while building 5.4 on 5.3's pause, and fixed here because 5.4 inherits
+it. `_control_wait` writes a pause row and returns `StepStatus.PENDING` with
+`paused: True`, and the run loop broke out only for `StepType.APPROVAL` --
+so a `wait` long enough to become durable, or any `wait` with
+`until: callback`, wrote its row and then ran every step after it. When the
+callback or the sweeper later resumed from `step_index + 1`, those steps ran
+a **second** time.
+
+Nothing caught it because the two tests that exercise the durable path assert
+on the pause row and on the resume, not on what the first half of the run did
+afterwards -- and the shipped packs contain no `wait`, so no replay exercised
+it either. The run loop now stops on any step that returns PENDING with a
+`pause_id`, keyed on the result rather than on the step type, because the same
+control step both sleeps in process (no pause) and suspends (a pause) and the
+type cannot tell those apart.
+
+Negative control: reverting that break fails
+`test_a_durable_pause_stops_the_run` plus two others, recorded in the pull
+request.
+
+### D12 -- The manager comes from SCIM only, and the lookup is three sources deep
+
+The plan says "from SCIM or IdP data". Implemented as the step's own
+`manager` parameter, then the run context (where identity enrichment puts one
+when the alert carried it), then `aisoc_scim_users.manager_ref` -- the
+enterprise extension's `manager.value`, which the column was missing
+entirely, so every sync delivered the attribute and every sync dropped it.
+
+**A live per-request lookup against Entra or Okta is not implemented**, and
+is named here rather than left to be inferred: it needs a vendor credential
+in the agents service, which today holds none, and the escalation runs on a
+sweeper with no tenant session. A tenant that provisions through SCIM has the
+data; a tenant that does not will see `no_manager` and the run resumes with
+that outcome rather than hanging.
+
+`context_import.py` writes a `manager_id` edge into Neo4j, which would be a
+fourth source. Not used: the agents service has an asyncpg pool and no Neo4j
+driver, and adding one for an escalation is a dependency the item does not
+justify.
+ ### D11 -- The plan says `valid_to`; this schema says `valid_until`
+
+ Item 2.5 asks for versioned snapshots with `valid_from` / `valid_to`. The one
+ existing table in this database that bounds a fact in time is `identity_edges`
+ (migration 018), and it spells the closing column `valid_until`. Adopting the
+ plan's spelling would put two names for one concept in one schema, and the
+ next person to write a point-in-time query would have to know which table
+ they were in before they could write a `WHERE`. The existing spelling wins;
+ `posture_snapshots` uses `valid_from` / `valid_until`, and the deviation is
+ recorded here rather than made silently.
+
+ ### D12 -- Eleven API tests are already failing on `main`, and nothing grades them
+
+ The full `services/api` suite run for 2.5 reported 4,774 passed and 11 failed.
+ All eleven are in `test_alert_list_priority_sort.py` and
+ `test_alert_tiles_cover_the_whole_result_set.py`, neither of which this branch
+ touches, and all eleven fail identically on a clean `git archive origin/main`
+ export with the same error: `list_alerts() missing 1 required positional
+ argument: 'http_request'`. The handler grew a `Request` parameter; the two
+ test files call it directly and were not updated.
+
+ What makes this worth a deviation rather than a footnote is why it is still
+ open on a branch-protected `main` with twenty-eight required checks. Both
+ files open with "Run against live Postgres: the defect is an `ORDER BY`, and a
+ fake session that answers any query cannot tell one ordering from another" --
+ and their fixture skips when no database answers. The only job that runs them
+ is `Python — Tests`, which sets `DATABASE_URL` to a host with no Postgres
+ behind it, so the fixture skips and the job is green. Neither file is named by
+ any workflow in `.github/workflows/`, so no live-Postgres job runs them
+ either. The suite that exists to prove the priority ordering has therefore
+ never graded it, and the signature break has been invisible since it landed.
+
+ Fixing them belongs to item 2.6, which wires the priority score and the queue
+ ordering these very tests cover; the fix lands there together with a workflow
+ that actually runs them against a database, because repairing the assertions
+ without that would restore a test nothing executes.
## Phase 1: Verdict quality you can publish
@@@ -617,13 -566,10 +653,15 @@@ endpoint produces once triage falls thr
- [x] **2.1** OCSF classes beyond five
- [x] **2.2** Activity projection on every event
- [x] **2.3** Event classification catalogue
+- [x] **2.4** Sessions per principal — one producer in the activity
+ projection, three consumers (Postgres, ClickHouse, Neo4j), held by
+ `check_session_projection.py`
+- [ ] **2.5** `__posture_snapshot__` collectors (AWS, Azure, GCP, Workspace, GitHub)
+ - [ ] **2.4** Sessions per principal
+ - [x] **2.5** `__posture_snapshot__` collectors (AWS, Azure, GCP, Workspace, GitHub)
- [ ] **2.6** Use the posture everywhere
-- [ ] **2.7** Entity context in CORE (ADR first)
+- [x] **2.7** Entity context in CORE (ADR first) — ADR-0010 accepted;
+ Postgres in CORE, Neo4j stays in `full`
## Phase 3: Detection depth for cloud, identity and SaaS
@@@ -968,28 -769,4 +1006,29 @@@
| 2026-10-11 | 8.1 | axe extended to the case list and case workspace, the two of parity 4.7's five views that were left out. Four real defects found and fixed: two `<select>` controls with no accessible name (one of them the control that writes a case's status), two indistinguishable `<aside>` landmarks, and panel headings at `h3` directly under the page's `h1`. |
+| 2026-10-11 | 7.1 | Reproduced: against the unmodified tree, `registry.list_vendors_for_capability` returned `[]` for all five mailbox verbs and `dispatcher.dispatch` answered `executor_not_found` for `purge_email` over 79 registered builtin arms -- a phishing response that could block the sender's domain at the firewall and could not remove the message it arrived in. Added the five verbs to both halves of the vocabulary, two mail clients (Graph, Gmail with per-mailbox domain-wide delegation), ten vendor arms, migration `104`, three intake adapters, campaign grouping, the governed fan-out and a report-mailbox worker. Only documented vendor APIs: purge is a soft delete on both and `restore_email` is a real reverse; there is no tenant-wide sender block because neither vendor exposes one through these APIs, and the per-mailbox scope is in the summary an analyst reads rather than only in a docstring. Everything ships off. Negative controls recorded in the PR: defaulting the feature flag on reds four tests, inverting the verification probe's polarity reds two, reading the envelope sender instead of the preserved headers reds four adapter tests including the one asserting the report mailbox is not proposed for purge, incrementing `recipient_count` instead of recomputing it reds the grouping test, and dropping `recipient_count` from the per-mailbox dispatch reds the fan-out test -- which is the quiet way a SEVERE action becomes a MODERATE one. Gates: `check_action_contract` 86 -> 97 executors, `check_module_reachability` 981 -> 986 of 1014, `check_route_authz` 262 -> 265 authorizing with both ceilings unmoved, matrix 302 -> 303 rows. Actions suite 1158 -> 1228; api 44 new cases, 17 of them against a real Postgres with the full chain. Recorded as **PARTIAL**, not GATED: no Microsoft 365 or Google Workspace tenant was exercised (D-7.1). |
+| 2026-10-11 | 7.2 | Reproduced: `grep -rl "authentication-results" services/` returned no match on the unmodified tree, so nothing in the product read a sender-authentication header and a message whose SPF and DMARC had both failed produced a verdict that had never looked. Built header analysis with a three-valued result, URL submission through the existing sandbox contract, the attachment hash lookup the submit path already had, and `evidence_cited` citations into the investigation ledger. Migration `111` stores the headers on the submission so a retriage replays them rather than re-fetching a message the purge has usually removed. `analysed` and `unanalysed` are counted separately in three places and summed in none. Negative controls: treating `none`/`neutral` as passes reds two tests; silently skipping an unanalysable URL reds three. **That second control is the finding worth keeping** -- it failed to fail on the first attempt, because every test built its own `ArtefactResult` list and never ran the producer, so five cases were added that drive `analyse_message` with the registry patched empty. A second finding came from the ledger suite's teardown: deleting a run cascades to its events and migration 008's trigger refuses, so the fixture was dropped rather than the append-only control defeated. Gates: matrix 303 -> 304 rows (300 GATED), `check_text_bind_casts` and `check_raw_sql_columns` clean over 6 new columns, `check_route_authz` unmoved. 45 new api cases, 6 of them against a real Postgres with the full chain. |
+
+### D-7.1 -- No Microsoft 365 or Google Workspace tenant was exercised
+
+Every mailbox verb in 7.1 is built against the vendors' documented request
+shapes and asserted with a recorded `respx` mock: the Graph `$filter` on a
+bracketed `internetMessageId`, the `move` to `recoverableitemsdeletions`, the
+inbox `messageRules` body, Gmail's `rfc822msgid:` operator, `trash`/`untrash`
+and the settings filter. **Nobody has watched either vendor accept any of
+them.** The maintainer-only list already carries "provide cloud and SaaS test
+tenants"; this is the same block, named here so the claim row's PARTIAL has a
+reason a reader can find.
+
+Two specific consequences, stated rather than implied. A decoder and a fixture
+that share an author share a misreading, so a field Graph spells differently
+from the reference would pass every test here. And the Gmail filter body and
+the Graph inbox-rule body were written from the API reference rather than
+taken from a working call, which is the half of `block_sender` least likely
+to be right first time.
+
+The claim row returns to GATED when a live tenant is available. Nothing was
+weakened to accommodate this: the row says PARTIAL, the operations page says
+"treat the first run against your own tenant as the first run", and the
+CHANGELOG entry says it too.
+ | 2026-10-11 | 2.5 | Reproduced: `test_posture_snapshot_coverage.py` on the unmodified tree asserted the *gap* — every resolver in `effective_permissions/` was pure and the only production snapshot source returned `{}`, so every live call 412'd and the subsystem had never answered a question about a real estate. Five collectors now exist under `services/connectors/app/connectors/posture/`, reached by a `__posture_snapshot__` sentinel through each connector's `get_resource_config`, and the coverage test is inverted: it now fails when a registered resolver has no declared collector. Building it found three things worth recording. (a) `BaseConnector.get_resource_config` declares `at_ts: str | None = None` while AWS, Okta and GitHub each required a positional `ts`, so a caller written against the base class raised `TypeError` on three of the connectors — standardised, with `test_every_implementation_matches_the_base_signature` holding it. (b) Google Workspace's directory read needs scopes the audit-log credential is not consented for, so the JWT is now built per scope: asking for both in one assertion would have broken alert polling on every tenant that had not pre-consented the new ones. (c) A snapshot is only an answer if you know *when* it was true — an alert is triaged minutes to days after the event, and a single mutable "current posture" row answers "what can this identity do now" while appearing to answer "what could it do when it acted", which is the worse failure because the number looks right. Migration 103 therefore versions snapshots on `valid_from`/`valid_until` (`valid_to` in the plan; `valid_from`/`valid_until` is the existing spelling in migration 018 and two spellings of one concept in one schema is worse than a recorded deviation — D11). Negative controls, both run against live Postgres and both restored: dropping `posture_snapshots_live_idx` leaves `test_a_second_live_row_is_refused_by_the_database` reporting `DID NOT RAISE IntegrityError`, and defeating the content-hash comparison in `save_snapshot` fails `test_unchanged_recollection_does_not_open_a_version` with two distinct row ids — without that comparison an unchanged estate re-collected hourly writes a version an hour and "when did this posture last change" becomes unanswerable because every row is a change. Evidence: 12 posture-store tests against live Postgres with the migration chain applied, 65 across the posture and effective-permission suites, 1,145 connector tests, 4,774 API tests. Eleven API failures are pre-existing on `main` and unrelated — recorded as D12. |