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.

fix(ci): authenticate the spine test and demo producer against /v1/ingest

Beenu Arora84c10758d106
diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml
index 37237ced3..9050957e0 100644
--- a/.github/workflows/integration.yml
+++ b/.github/workflows/integration.yml
@@ -193,6 +193,21 @@ jobs:
AISOC_GRAPH_ENABLED: "true"
run: docker compose --profile full up -d
+ # /v1/ingest is authenticated and the tenant comes from the
+ # credential, so the spine test holds one like any other pusher.
+ # Minted through the shipped command rather than inserted into
+ # Postgres, so this also covers the path an operator follows.
+ - name: Mint the ingest credential the spine test needs
+ run: |
+ set -euo pipefail
+ token="$(docker compose run --rm -T api python -m app.scripts.mint_ingest_token --quiet)"
+ if [ -z "$token" ]; then
+ echo "::error::mint_ingest_token printed nothing"
+ exit 1
+ fi
+ echo "::add-mask::$token"
+ echo "AISOC_INGEST_TOKEN=$token" >> "$GITHUB_ENV"
+
- name: Run spine test
run: python3 scripts/integration/spine_test.py
diff --git a/scripts/check_inbox_templates.py b/scripts/check_inbox_templates.py
index 873141330..b9a317661 100644
--- a/scripts/check_inbox_templates.py
+++ b/scripts/check_inbox_templates.py
@@ -105,7 +105,13 @@ def declared_catalog_ids() -> set[str]:
"""
tree = ast.parse(INBOX_ENDPOINT.read_text(encoding="utf-8"))
for node in ast.walk(tree):
- targets = list(node.targets) if isinstance(node, ast.Assign) else ([node.target] if isinstance(node, ast.AnnAssign) else [])
+ targets: list[ast.expr] = []
+ if isinstance(node, ast.Assign):
+ targets = list(node.targets)
+ elif isinstance(node, ast.AnnAssign):
+ targets = [node.target]
+ else:
+ continue
for target in targets:
if isinstance(target, ast.Name) and target.id == "_TEMPLATE_CATALOG":
value = node.value
diff --git a/scripts/integration/spine_test.py b/scripts/integration/spine_test.py
index e14569b40..b8f425ff6 100644
--- a/scripts/integration/spine_test.py
+++ b/scripts/integration/spine_test.py
@@ -33,6 +33,7 @@ from __future__ import annotations
import argparse
import asyncio
import json
+import os
import sys
import time
import uuid
@@ -47,6 +48,14 @@ REALTIME_HTTP = "http://localhost:8086"
REALTIME_WS = "ws://localhost:8086"
TENANT = "00000000-0000-0000-0000-000000000001"
+#: /v1/ingest is authenticated and the tenant is derived from the
+#: credential, so this test has to hold one like any other pusher. The
+#: workflow mints it with `python -m app.scripts.mint_ingest_token` and
+#: exports it here. Required rather than optional: an unauthenticated
+#: fallback would mean the spine test stopped exercising the path a real
+#: push takes.
+INGEST_TOKEN = os.environ.get("AISOC_INGEST_TOKEN", "").strip()
+
HEALTH_BUDGET_S = 300
SPINE_BUDGET_S = 180
REPOST_INTERVAL_S = 20
@@ -56,6 +65,24 @@ def log(msg: str) -> None:
print(f"[{time.strftime('%H:%M:%S')}] {msg}", flush=True)
+def ingest_headers() -> dict[str, str]:
+ """Credential plus the tenant the credential is expected to cover.
+
+ The tenant header is not authority — the ingest service intersects it
+ with the token's own scope — but sending it keeps this test honest
+ about which tenant it believes it is writing for.
+ """
+ if not INGEST_TOKEN:
+ raise SystemExit(
+ "AISOC_INGEST_TOKEN is unset. /v1/ingest requires a credential; mint one with\n"
+ " docker compose run --rm -T api python -m app.scripts.mint_ingest_token --quiet"
+ )
+ return {
+ "X-Tenant-ID": TENANT,
+ "Authorization": f"Bearer {INGEST_TOKEN}",
+ }
+
+
async def wait_healthy(client: httpx.AsyncClient) -> None:
"""Block until every spine service answers its health probe."""
probes = {
@@ -107,7 +134,7 @@ async def post_event(client: httpx.AsyncClient, title: str) -> None:
r = await client.post(
f"{INGEST}/v1/ingest/batch",
json=event_payload(title),
- headers={"X-Tenant-ID": TENANT},
+ headers=ingest_headers(),
timeout=10,
)
r.raise_for_status()
@@ -142,7 +169,7 @@ async def post_detection_event(client: httpx.AsyncClient) -> None:
r = await client.post(
f"{INGEST}/v1/ingest/batch",
json=payload,
- headers={"X-Tenant-ID": TENANT},
+ headers=ingest_headers(),
timeout=10,
)
r.raise_for_status()
diff --git a/services/demo-producer/main.go b/services/demo-producer/main.go
index 1ccd71782..5b6114627 100644
--- a/services/demo-producer/main.go
+++ b/services/demo-producer/main.go
@@ -244,6 +244,12 @@ func runProducer(ctx context.Context, wg *sync.WaitGroup, profile connectorProfi
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Tenant-ID", opts.tenant)
+ // /v1/ingest derives the tenant from the credential and only
+ // intersects the header above with it, so without a token every
+ // batch is refused with 401.
+ if opts.token != "" {
+ req.Header.Set("Authorization", "Bearer "+opts.token)
+ }
resp, err := client.Do(req)
if err != nil {
if ctx.Err() == nil {
@@ -260,6 +266,7 @@ func runProducer(ctx context.Context, wg *sync.WaitGroup, profile connectorProfi
type options struct {
ingestURL string
tenant string
+ token string
rate int
batch int
duration time.Duration
@@ -269,6 +276,7 @@ func main() {
var opts options
flag.StringVar(&opts.ingestURL, "ingest-url", envDefault("INGEST_URL", "http://localhost:8001/v1/ingest"), "Ingest service ingest endpoint")
flag.StringVar(&opts.tenant, "tenant", envDefault("TENANT_ID", "00000000-0000-0000-0000-000000000001"), "Tenant ID header")
+ flag.StringVar(&opts.token, "token", envDefault("AISOC_INGEST_TOKEN", ""), "Ingest credential (mint with `make ingest-token`); /v1/ingest refuses requests without one")
flag.IntVar(&opts.rate, "rate", 4, "Batches per second per connector")
flag.IntVar(&opts.batch, "batch", 5, "Events per batch")
flag.DurationVar(&opts.duration, "duration", 0, "How long to run (0 = forever)")