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.

feat(graph): AIAsset node with OPERATES and HOSTS edges, emitted at ingest

Beenu Arora0ca4989060d9
diff --git a/apps/docs/docs/architecture/graph-schema.md b/apps/docs/docs/architecture/graph-schema.md
index 78e6d9ea8..5be29505b 100644
--- a/apps/docs/docs/architecture/graph-schema.md
+++ b/apps/docs/docs/architecture/graph-schema.md
@@ -31,7 +31,7 @@ Each of those questions is a graph traversal. Doing the traversal on raw events
Just as important, the graph is the **shared substrate** the agent uses to build context. When the agent investigates an alert, it doesn't search logs — it walks the graph from the alert's `:OCCURRED_ON` anchor outward through `:ACCESSES`, `:HAS_PERMISSION`, `:PEER_OF`, and `:MEMBER_OF` edges, and the result is bounded, audit-able, and reproducible. The graph is what makes the L0–L4 autonomy claim defensible.
-The schema is intentionally small — 17 node labels, 14 relationship types — and intentionally split into **structural edges** (what *is*, from configuration snapshots) and **event edges** (what *happened*, from observed events). Every event edge carries `ts`, `source_event_id`, and `snapshot_id` so any state can be reconstructed at any point in time.
+The schema is intentionally small, and the authoritative counts are the ones `scripts/export_graph_schema.py --check` prints from [`schemas/graph-schema.yaml`](https://github.com/beenuar/AiSOC/blob/main/schemas/graph-schema.yaml) rather than a number written here, which would go stale on the next additive change and did. It is intentionally split into **structural edges** (what *is*, from configuration snapshots) and **event edges** (what *happened*, from observed events). Every event edge carries `ts`, `source_event_id`, and `snapshot_id` so any state can be reconstructed at any point in time.
## Schema at a glance
@@ -206,6 +206,15 @@ A detection rule — Sigma, custom YAML, hunt-as-code. Connected to the Alerts i
- **Created when**: a detection rule is published (DAC pipeline) or hot-loaded.
- **Properties**: `id` (required), `name` (required), `source` (required), `severity`, `updated_at`.
+### `AIAsset`
+
+One observed AI asset: an AI application, a coding agent, an MCP server, an IDE extension, a model-provider key, or an OAuth grant to an AI application. One label carrying a `kind` property rather than six labels, for the same reason `Identity` superclasses `User` and `ServiceAccount` — every question asked of this data is asked *across* the kinds ("what does this person run", "what runs on this laptop"), so six labels would make each of those a six-way union and would give the vocabulary six places to drift.
+
+This is the graph projection. The durable record is the `aisoc_ai_assets` table, written by the fusion recorder; the node exists so an investigation can traverse from a person or a device to what AI they run without leaving the graph.
+
+- **Created when**: `ai-runtime` or `ai-finding` telemetry arrives from the SDK or a gateway, or process activity names a known coding-agent binary.
+- **Properties**: `id` (required), `tenant_id` (required), `kind` (required), `external_id` (required), `display_name`, `vendor`, `model`.
+
## Relationships
Relationships are split into two classes:
@@ -341,6 +350,18 @@ not per event.
- **Required edge properties**: `ts`, `source_event_id`, `snapshot_id`.
- **Additional properties**: `bytes_in`, `object_path`.
+### `:OPERATES` — `User` → `AIAsset`
+
+**Event edge.** The person an AI asset acted for. Absent rather than guessed when the telemetry did not say: an AI asset nobody is accountable for is the finding, and writing a placeholder would hide it.
+
+- **Required edge properties**: `ts`, `source_event_id`, `snapshot_id`.
+
+### `:HOSTS` — `Endpoint` → `AIAsset`
+
+**Event edge.** The device an AI asset ran on. This is the edge containment reads — without it a kill-switch has nowhere to act, which is why the inventory scores an AI asset with no device as exposed rather than as merely unknown.
+
+- **Required edge properties**: `ts`, `source_event_id`, `snapshot_id`.
+
## Versioning
The schema carries a `SchemaVersion` value at the top of [`schemas/graph-schema.yaml`](https://github.com/beenuar/AiSOC/blob/main/schemas/graph-schema.yaml):
diff --git a/schemas/graph-schema.yaml b/schemas/graph-schema.yaml
index 5a1729726..445155f6c 100644
--- a/schemas/graph-schema.yaml
+++ b/schemas/graph-schema.yaml
@@ -20,7 +20,7 @@
# are reconciled from configuration snapshots and carry `snapshot_id` and a
# `valid_from`/`valid_to` window instead.
-version: v1.2
+version: v1.3
# ---------------------------------------------------------------------------
# Node labels
@@ -358,6 +358,28 @@ node_labels:
- { name: last_rotated, type: datetime, required: false }
- { name: rotation_days, type: int, required: false }
+ # ── v1.3: the AI estate ────────────────────────────────────────────────────
+ - label: AIAsset
+ description: >-
+ One observed AI asset: an AI application, a coding agent, an MCP server,
+ an IDE extension, a model-provider key or an OAuth grant to an AI app.
+ One label with a `kind` property rather than six labels, because every
+ question asked of this data is asked across the kinds — what does this
+ person run, what runs on this laptop — and six labels would make each
+ of those a six-way union. Tenant-scoped: an agent is somebody's.
+ Written by `extractAIEstate` from `ai-runtime` / `ai-finding` telemetry
+ and from process activity naming a known agent binary. The durable
+ record is `aisoc_ai_assets` in Postgres; this is the projection an
+ investigation traverses.
+ properties:
+ - { name: id, type: string, required: true }
+ - { name: tenant_id, type: string, required: true }
+ - { name: kind, type: string, required: true }
+ - { name: external_id, type: string, required: true }
+ - { name: display_name, type: string, required: false }
+ - { name: vendor, type: string, required: false }
+ - { name: model, type: string, required: false }
+
# ── v1.1: threat depth ─────────────────────────────────────────────────────
# Malware, Campaign, ThreatActor, Technique and Tactic are *global*
# reference entities: they carry no tenant_id, tenant-scoped reads must
@@ -717,6 +739,35 @@ relationships:
- { name: snapshot_id, type: string, required: true }
- { name: role, type: string, required: false }
+ # ── v1.3: the AI estate ────────────────────────────────────────────────────
+ # Two new types rather than a second pair of endpoints on OWNED_BY and
+ # RUNS: each relationship here declares one source label and one target
+ # label, so reusing them would make this file assert something untrue of
+ # the edges the extractor actually writes.
+ - name: OPERATES
+ source_label: User
+ target_label: AIAsset
+ event_edge: true
+ description: >-
+ The person an AI asset acted for. Absent rather than guessed when the
+ source did not say: an unlinked agent is the finding, not a blank.
+ properties:
+ - { name: ts, type: datetime, required: true }
+ - { name: source_event_id, type: string, required: true }
+ - { name: snapshot_id, type: string, required: true }
+
+ - name: HOSTS
+ source_label: Endpoint
+ target_label: AIAsset
+ event_edge: true
+ description: >-
+ The device an AI asset ran on. This is the edge containment reads:
+ without it a kill-switch has nowhere to act.
+ properties:
+ - { name: ts, type: datetime, required: true }
+ - { name: source_event_id, type: string, required: true }
+ - { name: snapshot_id, type: string, required: true }
+
# ── v1.1: threat depth ─────────────────────────────────────────────────────
- name: OBSERVED_IOC
source_label: Alert
diff --git a/services/ingest/internal/graph/extractor.go b/services/ingest/internal/graph/extractor.go
index 29ea51e97..db9cc6bc3 100644
--- a/services/ingest/internal/graph/extractor.go
+++ b/services/ingest/internal/graph/extractor.go
@@ -83,6 +83,11 @@ func ExtractFromOCSF(eventID, tenantID, connectorType string, ocsf map[string]in
// connector since it's pulled from the OCSF mitre_attck enrichment.
extractMITRE(ev, ocsf)
+ // Depth 6.1 — the AI estate, also a post-pass and for the same reason:
+ // AI telemetry arrives on three different connector types and as plain
+ // process activity, so a connector case would cover one of them.
+ extractAIEstate(ev, ocsf)
+
// The activity projection, applied to whichever nodes the extractors
// above produced. A post-pass rather than a line in each of the five
// extractors: the projection is on the event, not on the connector, and
@@ -702,3 +707,150 @@ func parseTime(s string) time.Time {
}
return time.Time{}
}
+
+// aiAgentProcesses maps a coding agent's executable base name to its vendor.
+//
+// Deliberately a small named table rather than a substring heuristic: the
+// word "agent" matches half an EDR estate, and a false positive here puts
+// somebody's antivirus on an AI inventory. Mirrors
+// CODING_AGENT_PROCESSES in services/fusion/app/services/ai_asset_recorder.py;
+// the two services cannot import each other, and
+// TestAIEstateVocabularyMatchesRecorder reads both files and compares them.
+var aiAgentProcesses = map[string]string{
+ "claude": "Anthropic",
+ "codex": "OpenAI",
+ "aider": "Aider",
+ "goose": "Block",
+ "continue": "Continue",
+ "opencode": "OpenCode",
+ "gemini": "Google",
+ "copilot": "GitHub",
+ "copilot-language-server": "GitHub",
+ "amazonq": "Amazon",
+ "cline": "Cline",
+}
+
+// extractAIEstate projects AI-estate telemetry onto the graph (depth 6.1).
+//
+// A post-pass rather than a connector case, for the same reason extractMITRE
+// is one: AI telemetry arrives through the `ai-runtime` / `ai-finding` inbox
+// templates, through a gateway connector, and as ordinary process activity
+// from any EDR — so keying on connectorType would cover one of the three and
+// look complete.
+//
+// Two edges, both existing relationship types rather than new ones:
+//
+// (:User)-[:OPERATES]->(:AIAsset) who runs it
+// (:Endpoint)-[:HOSTS]->(:AIAsset) where it ran
+//
+// Those are the two links depth 6.1 asks for: a person and a device.
+func extractAIEstate(ev *Event, ocsf map[string]interface{}) {
+ sourceType := strings.ToLower(getString(ocsf, "source_type"))
+ kind, externalID, displayName, vendor := "", "", "", ""
+
+ switch sourceType {
+ case "ai-runtime", "ai-finding":
+ // The SDK and gateway path: actor.process.name is the agent id.
+ externalID = getString(ocsf, "actor.process.name")
+ displayName = getString(ocsf, "actor.process.path")
+ base := processBaseName(displayName)
+ if base == "" {
+ base = processBaseName(externalID)
+ }
+ if v, ok := aiAgentProcesses[base]; ok {
+ kind, vendor = "coding_agent", v
+ } else {
+ kind = "ai_app"
+ vendor = getString(ocsf, "cloud.provider")
+ }
+ default:
+ // Endpoint discovery: a known agent binary in process activity.
+ // Only class 1007 carries one; anything else is a different event
+ // that happens to name a process.
+ if classUID, ok := ocsf["class_uid"].(float64); !ok || int(classUID) != 1007 {
+ return
+ }
+ name := getString(ocsf, "process.name")
+ if name == "" {
+ name = getString(ocsf, "actor.process.name")
+ }
+ base := processBaseName(name)
+ v, ok := aiAgentProcesses[base]
+ if !ok {
+ return
+ }
+ kind, vendor, externalID, displayName = "coding_agent", v, base, name
+ }
+
+ if externalID == "" {
+ return
+ }
+
+ device := getString(ocsf, "src_endpoint.hostname")
+ if device == "" {
+ device = getString(ocsf, "device.name")
+ }
+ assetKey := fmt.Sprintf("aiasset:%s:%s:%s:%s", ev.TenantID, kind, externalID, device)
+
+ props := map[string]interface{}{
+ "kind": kind,
+ "external_id": externalID,
+ }
+ if displayName != "" {
+ props["display_name"] = displayName
+ }
+ if vendor != "" {
+ props["vendor"] = vendor
+ }
+ if model := getString(ocsf, "metadata.product.feature.name"); model != "" {
+ props["model"] = model
+ }
+ ev.Nodes = append(ev.Nodes, Node{
+ Label: NodeAIAsset,
+ NaturalKey: assetKey,
+ TenantID: ev.TenantID,
+ Properties: props,
+ })
+
+ if user := getString(ocsf, "actor.user.name"); user != "" {
+ userKey := fmt.Sprintf("user:%s:%s", ev.TenantID, user)
+ ev.Nodes = append(ev.Nodes, Node{
+ Label: NodeUser,
+ NaturalKey: userKey,
+ TenantID: ev.TenantID,
+ Properties: map[string]interface{}{"name": user},
+ })
+ ev.Edges = append(ev.Edges, Edge{
+ Type: RelOperates,
+ FromLabel: NodeUser, FromKey: userKey,
+ ToLabel: NodeAIAsset, ToKey: assetKey,
+ })
+ }
+
+ if device != "" {
+ endpointKey := fmt.Sprintf("endpoint:%s:%s", ev.TenantID, device)
+ ev.Nodes = append(ev.Nodes, Node{
+ Label: NodeEndpoint,
+ NaturalKey: endpointKey,
+ TenantID: ev.TenantID,
+ Properties: map[string]interface{}{"hostname": device},
+ })
+ ev.Edges = append(ev.Edges, Edge{
+ Type: RelHosts,
+ FromLabel: NodeEndpoint, FromKey: endpointKey,
+ ToLabel: NodeAIAsset, ToKey: assetKey,
+ })
+ }
+}
+
+// processBaseName strips a directory prefix and a .exe suffix, lowercased.
+func processBaseName(path string) string {
+ if path == "" {
+ return ""
+ }
+ p := strings.ToLower(strings.ReplaceAll(path, "\\", "/"))
+ if idx := strings.LastIndex(p, "/"); idx >= 0 {
+ p = p[idx+1:]
+ }
+ return strings.TrimSuffix(p, ".exe")
+}
diff --git a/services/ingest/internal/graph/schema.go b/services/ingest/internal/graph/schema.go
index ed0b8c436..322aa2a4e 100644
--- a/services/ingest/internal/graph/schema.go
+++ b/services/ingest/internal/graph/schema.go
@@ -48,7 +48,7 @@ package graph
// the nodes it already writes, so a traversal can ask "which of these
// accounts is a person" without leaving the graph. See ActivityNodeProperties
// below for exactly which keys land where.
-const SchemaVersion = "v1.2"
+const SchemaVersion = "v1.3"
// ActivityNodeProperties names the properties the activity projection adds,
// per label. Declared here rather than only written in the extractor so the
@@ -130,6 +130,18 @@ const (
// The graph must be safe to hand to an agent.
NodeSecret NodeLabel = "Secret"
+ // ── v1.3: the AI estate ───────────────────────────────────────────
+ // One label with a `kind` property rather than six labels for app,
+ // coding agent, MCP server, IDE extension, provider key and OAuth
+ // grant. Same reasoning as Identity superclassing User and
+ // ServiceAccount: every question asked of this data is asked across the
+ // kinds ("what does this person run", "what runs on this laptop"), so
+ // six labels would make each a six-way union and would give the
+ // vocabulary six places to drift.
+ //
+ // Tenant-scoped, unlike the threat labels below: an agent is somebody's.
+ NodeAIAsset NodeLabel = "AIAsset"
+
// ── v1.1: threat depth ────────────────────────────────────────────
// These are the global reference labels. They are deliberately not
// tenant-scoped, and tenant_deletion.py exempts them from an
@@ -169,6 +181,7 @@ var AllNodeLabels = []NodeLabel{
NodeApplication,
NodeCloudAccount,
NodeSecret,
+ NodeAIAsset,
NodeIOC,
NodeMalware,
NodeCampaign,
@@ -239,6 +252,15 @@ const (
// is who an escalation actually goes to.
RelOwnedBy RelType = "OWNED_BY"
+ // ── v1.3: the AI estate ───────────────────────────────────────────
+ // Two new types rather than reusing OWNED_BY and RUNS. Those two are
+ // declared in the YAML with one source label and one target label each
+ // (Application -> Employee, Resource -> Application), and a second pair
+ // of endpoints cannot be expressed on them without making the schema
+ // file say something that is not true of the edges actually written.
+ RelOperates RelType = "OPERATES" // User -> AIAsset: who runs it
+ RelHosts RelType = "HOSTS" // Endpoint -> AIAsset: where it ran
+
// ── v1.1: threat depth ────────────────────────────────────────────
RelObservedIOC RelType = "OBSERVED_IOC" // Alert -> IOC
RelIndicates RelType = "INDICATES" // IOC -> Malware
@@ -274,6 +296,8 @@ var AllRelTypes = []RelType{
RelInAccount,
RelStores,
RelOwnedBy,
+ RelOperates,
+ RelHosts,
RelObservedIOC,
RelIndicates,
RelPartOf,