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
feat(ueba): baseline non-human principals, and record every new gate in the matrix (#679)
Beenu Arora23219a5837fe
diff --git a/docs/audit/CLAIM_TO_GATE_MATRIX.md b/docs/audit/CLAIM_TO_GATE_MATRIX.mdindex 77c403f4a..9ccf40bce 100644--- a/docs/audit/CLAIM_TO_GATE_MATRIX.md+++ b/docs/audit/CLAIM_TO_GATE_MATRIX.md@@ -81,10 +81,21 @@ Statuses: `GATED` (a CI job fails when the claim stops being true) · `PARTIAL`| Analysts can hunt the events AiSOC itself ingested | README (hunt surface) | `ci.yml :: api tests` (`test_lake_hunt.py` — the translator IR compiles to parameterised ClickHouse SQL with the tenant predicate generated rather than rewritten in; no question text reaches the SQL string) | GATED | - || Business-context rules authored in the console affect triage | `apps/docs/docs/console/` (business context) | `ci.yml` agents tests (`test_business_context_per_tenant.py` — rules resolve per tenant from Postgres, one tenant's suppression cannot affect another, and an outage serves last-known rules rather than silently un-suppressing) | GATED | - || Seeded sample data never renders as a tenant's real state | Standing honesty rule (synthetic vs real) | `ci.yml :: python-lint` (`check_mock_data_gated.py` — fails the build on a `fallbackData` receiving sample data un-wrapped, or sample data assigned to state with no demo-mode check) | GATED | - |+| Published executable-detection count matches what the engine loads | `docs/detections/truth-table.md` | `validate-detections.yml` (`detection_truth_table.py --check` now derives `executable` from `detection_ruleset.json` membership rather than file path and body keys; the old heuristic published 947 while the engine loaded 825, counted 77 Sigma rules with no evaluator, and would have certified a bulk un-quarantine as a no-op) | GATED | - |+| A detection rule matches on fields that exist in telemetry | (implied by the detection corpus) | `validate-detections.yml` (`check_detection_fields.py` — ratchets rules depending on computed fields such as sliding-window counters and allowlist booleans, which no connector can supply; fixture replay cannot catch these because fixtures are synthesized from the rule under test) | GATED (ratchet) | ratchet to 0 |+| Vendor fields nested under `raw_event` are visible to detections | (implied by the detection corpus) | `ci.yml` fusion tests (`test_detection_field_namespace.py` — 663 of 825 loaded rules referenced an invisible field before this; both the stateless and windowed engines now merge the payload identically) | GATED | - |+| A connector's alerts are attributed to that connector, not to Splunk | `apps/docs/docs/connectors/` | `ci.yml` ingest tests (`TestUnknownConnectorFallbackIsVendorNeutralAndPromotable` — the lenient fallback borrowed the `splunk_enterprise` profile, mis-attributing 26 connectors and, being category 4 with an empty severity map, making their events unpromotable) | GATED | - |+| Customer AI estate: routine agent activity is not auto-promoted to an alert | README (AI estate), `packages/aisoc-ai-sdk/README.md` | `ci.yml` ingest tests (`TestAiRuntimeActivityIsNotAFinding` + `TestAiGuardrailFindingIsAlwaysPromotable` — asserts the 6003/2001 split in both directions, since all-2001 floods the queue with an agent's normal operation and all-6003 leaves a detected injection silent in the lake) | GATED | - |+| AI prompt content does not leave the customer's process by default | `packages/aisoc-ai-sdk/README.md` | `ai-sdk.yml` (`test_ai_sdk.py` — hashed capture asserts no content is transmitted while still reporting which secret shapes were present; masked/full are opt-in per client) | GATED | - |+| The AI SDK never breaks or blocks the host application | `packages/aisoc-ai-sdk/README.md` | `ai-sdk.yml` (transport failure, full queue and unconfigured endpoint all assert a dropped span rather than a raise; a zero-runtime-dependency check stops the package pulling a transport library into a customer's resolution) | GATED | - |+| Every MCP tool call is accounted for | `services/mcp/README.md` | `ci.yml` MCP vitest (`telemetry.test.ts` — records successes and refusals, transmits argument keys but never values, bounds its buffer, and never raises on an unreachable inbox; the README previously claimed an audit trail the server did not emit and the API's audit middleware does not cover for read tools) | GATED | - |+| Windowed detection rules are declarable without editing the engine | `detections/splunk-imports/_quarantine/README.md` | `validate-detections.yml` (`export_windowed_ruleset.py --check`) + `ci.yml` fusion tests (`test_windowed_ruleset_loader.py` — a malformed rule is skipped individually, a duplicate id cannot shadow a builtin threshold, and zero thresholds/windows are refused) | GATED | - |+| The agent's abstention rate and groundedness are published | `/metrics/funnel` | `ci.yml :: api tests` (`test_triage_quality_metrics.py` — asserts `mean_groundedness` averages only scored verdicts, so the deterministic path is not counted as zero, and that a missing column degrades rather than failing the funnel) | GATED | - |+| UEBA baselines non-human principals (service accounts, AI agents) | `apps/docs/docs/` (UEBA) | `ci.yml` ueba tests (`test_non_human_entities.py` — the entity-type list widened without becoming free text, and a zero-variance baseline returns None rather than a 0.0 that would read as permanently normal) | GATED | - |## Summary-- GATED: 62+- GATED: 73- PARTIAL: 11- NO GATE: 0 (**every claim is backed by a failing test.** The last NO GATE — the weekly benchmark scoreboard running live against `main` — closed in Phase E1: `scripts/check_scoreboard.py` ties the published scoreboard to a deterministic per-PR live-agent MITRE-accuracy run, while the funded weekly `wet-eval.yml` appends the LLM-tier rows. The remaining PARTIAL rows are honest, named deferrals — each states the specific gap and what closes it — not unproven claims.)diff --git a/services/ueba/app/api/routes.py b/services/ueba/app/api/routes.pyindex 00ad3b054..9d9809134 100644--- a/services/ueba/app/api/routes.py+++ b/services/ueba/app/api/routes.py@@ -38,9 +38,35 @@ DB = Annotated[AsyncSession, Depends(get_db)]# ---------------------------------------------------------------------------+#: Entity kinds UEBA will baseline.+#:+#: `service_account` and `ai_agent` are non-human principals, and they are the+#: ones most in need of behavioural baselining rather than least. A human's+#: activity is bounded by working hours and attention; a service account or an+#: agent runs continuously with standing credentials, which is exactly the+#: profile an attacker wants and exactly what nobody watches.+#:+#: Only this HTTP route constrained the value. The schema column is a plain+#: `String(32)` with no CHECK constraint, the Welford statistics never inspect+#: the type (it is an opaque partition key), and the Kafka path already+#: accepted any string — so the constraint was inconsistent as well as+#: unhelpfully narrow.+#:+#: The degenerate-variance handling added in v8.0 is what makes this safe.+#: `compute_z_score` returns None rather than 0.0 when a feature has no+#: variance, and its own docstring names the reason: "service accounts, batch+#: jobs and automation users converge on a constant stream, so their standard+#: deviation collapses to zero and every subsequent value, however extreme,+#: sits zero deviations from the mean." Without that fix, admitting these+#: entity types would have produced baselines that read every non-human+#: principal as permanently normal.+ENTITY_TYPES = ("user", "device", "ip", "service_account", "ai_agent", "mcp_server")+_ENTITY_TYPE_PATTERN = "^(" + "|".join(ENTITY_TYPES) + ")$"++class ScoreEventRequest(BaseModel):tenant_id: uuid.UUID- entity_type: str = Field(..., pattern="^(user|device|ip)$")+ entity_type: str = Field(..., pattern=_ENTITY_TYPE_PATTERN)entity_id: strevent_type: strfeatures: dict[str, float]diff --git a/services/ueba/app/models/ueba.py b/services/ueba/app/models/ueba.pyindex 381e4a012..498a3c2cf 100644--- a/services/ueba/app/models/ueba.py+++ b/services/ueba/app/models/ueba.py@@ -28,7 +28,12 @@ class EntityBaseline(Base):id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)tenant_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), nullable=False)- entity_type: Mapped[str] = mapped_column(String(32), nullable=False) # user | device | ip+ # See app.api.routes.ENTITY_TYPES. Non-human principals (service+ # accounts, AI agents, MCP servers) are included deliberately: they run+ # continuously with standing credentials, which is the profile most in+ # need of baselining and the one nobody watches. No CHECK constraint, so+ # a new kind needs no migration.+ entity_type: Mapped[str] = mapped_column(String(32), nullable=False)entity_id: Mapped[str] = mapped_column(String(256), nullable=False)# Feature statistics (JSON: {"feature": {"mean": X, "std": Y, "count": N}})diff --git a/services/ueba/tests/test_non_human_entities.py b/services/ueba/tests/test_non_human_entities.pynew file mode 100644index 000000000..886198e00--- /dev/null+++ b/services/ueba/tests/test_non_human_entities.py@@ -0,0 +1,98 @@+"""UEBA must baseline non-human principals, not just people.++A service account or an AI agent runs continuously with standing credentials.+That is exactly the profile an attacker wants and exactly what nobody watches,+so these are the entities most in need of behavioural baselining rather than+least.++Only the HTTP scoring route constrained the value, to `^(user|device|ip)$`.+The constraint was also inconsistent with the rest of the service: the schema+column is a plain `String(32)` with no CHECK constraint, the Welford+statistics never inspect the type (it is an opaque partition key), and the+Kafka path already accepted any string — so an agent baseline could be created+by publishing to Kafka but not by calling the API.++The degenerate-variance handling added in v8.0 is what makes admitting them+safe, and its absence is why doing so earlier would have been actively+misleading. `compute_z_score` returns None rather than 0.0 when a feature has+no variance, and names the reason: a constant stream collapses the standard+deviation to zero, after which every subsequent value — however extreme — sits+zero deviations from the mean. Without that, every non-human principal would+have read as permanently normal.+"""++from __future__ import annotations++import uuid++import pytest+from app.api.routes import ENTITY_TYPES, ScoreEventRequest+from pydantic import ValidationError+++def _payload(entity_type: str) -> dict:+ return {+ "tenant_id": str(uuid.uuid4()),+ "entity_type": entity_type,+ "entity_id": "svc-nightly-backup",+ "event_type": "authentication",+ "features": {"hour_of_day": 3.0},+ }+++# ── the regression ────────────────────────────────────────────────────────++[email protected]("entity_type", ["service_account", "ai_agent", "mcp_server"])+def test_non_human_principals_are_accepted(entity_type: str):+ assert ScoreEventRequest(**_payload(entity_type)).entity_type == entity_type++[email protected]("entity_type", ["user", "device", "ip"])+def test_the_original_types_still_work(entity_type: str):+ assert ScoreEventRequest(**_payload(entity_type)).entity_type == entity_type+++def test_an_unknown_entity_type_is_still_refused():+ """The list widened; it did not become a free-text field.++ An unconstrained type would let a typo create a parallel baseline that+ silently accumulates nothing useful, which is worse than a 422.+ """+ with pytest.raises(ValidationError):+ ScoreEventRequest(**_payload("kitchen_sink"))+++def test_the_pattern_is_derived_from_the_list():+ """So adding a kind to ENTITY_TYPES cannot forget to update the regex."""+ for entity_type in ENTITY_TYPES:+ assert ScoreEventRequest(**_payload(entity_type)).entity_type == entity_type+++# ── the statistics must actually hold up for these entities ───────────────+++def test_a_constant_stream_does_not_read_as_normal():+ """The property that makes non-human baselining meaningful at all.++ A service account authenticating at 03:00 every night has zero variance on+ `hour_of_day`. Returning 0.0 there would mean no observation could ever be+ anomalous; None means "unknown", which the caller excludes.+ """+ from app.services.baseline import compute_z_score++ # Enough samples to clear the minimum, but no variance at all.+ degenerate = {"hour_of_day": {"mean": 3.0, "std": 0.0, "count": 500}}+ assert compute_z_score(degenerate, "hour_of_day", 3.0) is None+ # And a wildly different value against the same degenerate baseline is+ # still unknown rather than confidently zero.+ assert compute_z_score(degenerate, "hour_of_day", 17.0) is None+++def test_a_real_deviation_is_still_scored():+ from app.services.baseline import compute_z_score++ stats = {"hour_of_day": {"mean": 3.0, "std": 1.0, "count": 500}}+ score = compute_z_score(stats, "hour_of_day", 17.0)+ assert score is not None+ assert score > 3.0