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(api,agents): close console QA gaps — detection compat, MITRE shape, langgraph, INC-### cases

Beenu Arora2533fb487e55
diff --git a/services/agents/Dockerfile b/services/agents/Dockerfile
index 18fae86f2..d73975d9f 100644
--- a/services/agents/Dockerfile
+++ b/services/agents/Dockerfile
@@ -29,11 +29,11 @@ RUN set -eux; \
"uvicorn[standard]>=0.27,<0.28" \
"pydantic>=2.5,<3" \
"pydantic-settings>=2.1,<3" \
- "langchain>=0.1,<0.2" \
- "langchain-core>=0.1,<0.2" \
- "langchain-openai>=0.0.5,<0.1" \
- "langchain-community>=0.0.20,<0.1" \
- "langgraph>=0.0.30,<0.1" \
+ "langchain>=0.3,<0.4" \
+ "langchain-core>=0.3,<0.4" \
+ "langchain-openai>=0.2,<0.3" \
+ "langchain-community>=0.3,<0.4" \
+ "langgraph>=0.2.40,<0.4" \
"openai>=1.12,<2" \
"redis[hiredis]>=5.0,<6" \
"httpx>=0.26,<0.27" \
@@ -54,7 +54,10 @@ RUN set -eux; \
# Smoke-import the modules the orchestrator pulls in at module load time.
# Catches "image built but broken" cases at build time instead of runtime.
-RUN python -c "import opentelemetry, langgraph, fastapi, sqlalchemy, asyncpg, redis, httpx, structlog, apscheduler, yaml"
+# Also assert that the langgraph version on disk exposes the ``START``
+# sentinel — langgraph 0.0.x silently lacked it, which previously crashed the
+# agents service at boot with ``ImportError: cannot import name 'START'``.
+RUN python -c "import opentelemetry, langgraph, fastapi, sqlalchemy, asyncpg, redis, httpx, structlog, apscheduler, yaml; from langgraph.graph import END, START, StateGraph"
COPY app/ ./app/
diff --git a/services/agents/pyproject.toml b/services/agents/pyproject.toml
index 8326ca058..a1e8980b2 100644
--- a/services/agents/pyproject.toml
+++ b/services/agents/pyproject.toml
@@ -11,11 +11,14 @@ fastapi = "^0.109.0"
uvicorn = {extras = ["standard"], version = "^0.27.0"}
pydantic = "^2.5.0"
pydantic-settings = "^2.1.0"
-langchain = "^0.1.0"
-langchain-core = "^0.1.0"
-langchain-openai = "^0.0.5"
-langgraph = "^0.0.30"
-langchain-community = ">=0.0.20,<0.0.39"
+langchain = ">=0.3.0,<0.4.0"
+langchain-core = ">=0.3.0,<0.4.0"
+langchain-openai = ">=0.2.0,<0.3.0"
+# langgraph >=0.2 exposes the public ``START`` sentinel that
+# ``app.investigator.orchestrator`` imports. The previous ``^0.0.30`` pin
+# resolved to <0.1.0 which silently broke the import at runtime.
+langgraph = ">=0.2.40,<0.4.0"
+langchain-community = ">=0.3.0,<0.4.0"
openai = "^1.12.0"
redis = {extras = ["hiredis"], version = "^5.0.1"}
httpx = "^0.26.0"
diff --git a/services/api/app/api/v1/endpoints/cases.py b/services/api/app/api/v1/endpoints/cases.py
index 5c0f9df2c..befe31560 100644
--- a/services/api/app/api/v1/endpoints/cases.py
+++ b/services/api/app/api/v1/endpoints/cases.py
@@ -117,6 +117,7 @@ class AddCommentRequest(BaseModel):
class CaseResponse(BaseModel):
id: uuid.UUID
+ case_number: str | None = None
title: str
description: str | None
severity: str
@@ -257,6 +258,7 @@ def _coerce_tags(value: Any) -> dict[str, Any]:
def _row_to_case(row: Any) -> CaseResponse:
return CaseResponse(
id=row.id,
+ case_number=getattr(row, "case_number", None),
title=row.title,
description=row.description,
severity=row.severity,
@@ -279,6 +281,40 @@ def _row_to_case(row: Any) -> CaseResponse:
)
+async def _resolve_case_id(case_id: str, db: Any) -> uuid.UUID:
+ """Resolve a case identifier (UUID **or** human-readable case_number) to a UUID.
+
+ The web console and demo deeplinks use short identifiers like ``INC-001``,
+ while the database primary key is a UUID. Accepting both forms here keeps
+ the API ergonomic without forcing the front end to do a separate lookup.
+
+ Raises ``404`` if the identifier doesn't match either form.
+ """
+ case_id = (case_id or "").strip()
+ if not case_id:
+ raise HTTPException(status_code=404, detail="Case not found.")
+
+ # Try UUID first — that's the canonical form.
+ try:
+ return uuid.UUID(case_id)
+ except (ValueError, AttributeError):
+ pass
+
+ # Fall back to case_number lookup. Use a parameterized query — never
+ # interpolate the raw string into SQL.
+ row = (
+ await db.execute(
+ text(
+ "SELECT id FROM aisoc_cases WHERE case_number = :case_number "
+ "ORDER BY created_at DESC LIMIT 1"
+ ).bindparams(case_number=case_id)
+ )
+ ).fetchone()
+ if not row:
+ raise HTTPException(status_code=404, detail="Case not found.")
+ return row.id
+
+
# ────────────────────────────────────────────────────────────────────────────
# Endpoints
# ────────────────────────────────────────────────────────────────────────────
@@ -359,18 +395,20 @@ async def create_case(body: CreateCaseRequest, db: DBSession, user: AuthUser) ->
@router.get("/{case_id}", response_model=CaseResponse, summary="Get case")
-async def get_case(case_id: uuid.UUID, db: DBSession, user: AuthUser) -> CaseResponse:
- row = (await db.execute(text("SELECT * FROM aisoc_cases WHERE id = :id").bindparams(id=case_id))).fetchone()
+async def get_case(case_id: str, db: DBSession, user: AuthUser) -> CaseResponse:
+ cid = await _resolve_case_id(case_id, db)
+ row = (await db.execute(text("SELECT * FROM aisoc_cases WHERE id = :id").bindparams(id=cid))).fetchone()
if not row:
raise HTTPException(status_code=404, detail="Case not found.")
return _row_to_case(row)
@router.patch("/{case_id}", response_model=CaseResponse, summary="Update case")
-async def update_case(case_id: uuid.UUID, body: UpdateCaseRequest, db: DBSession, user: AuthUser) -> CaseResponse:
+async def update_case(case_id: str, body: UpdateCaseRequest, db: DBSession, user: AuthUser) -> CaseResponse:
import json as _json
- existing = (await db.execute(text("SELECT status FROM aisoc_cases WHERE id = :id").bindparams(id=case_id))).fetchone()
+ cid = await _resolve_case_id(case_id, db)
+ existing = (await db.execute(text("SELECT status FROM aisoc_cases WHERE id = :id").bindparams(id=cid))).fetchone()
if not existing:
raise HTTPException(status_code=404, detail="Case not found.")
@@ -384,7 +422,7 @@ async def update_case(case_id: uuid.UUID, body: UpdateCaseRequest, db: DBSession
now = datetime.now(UTC)
sets = ["updated_at = :now"]
- params: dict[str, Any] = {"id": case_id, "now": now}
+ params: dict[str, Any] = {"id": cid, "now": now}
if body.title is not None:
sets.append("title = :title"); params["title"] = body.title
@@ -420,7 +458,8 @@ async def update_case(case_id: uuid.UUID, body: UpdateCaseRequest, db: DBSession
@router.post("/{case_id}/alerts", response_model=CaseResponse, summary="Link alerts to a case")
-async def add_alerts(case_id: uuid.UUID, body: AddAlertsRequest, db: DBSession, user: AuthUser) -> CaseResponse:
+async def add_alerts(case_id: str, body: AddAlertsRequest, db: DBSession, user: AuthUser) -> CaseResponse:
+ cid = await _resolve_case_id(case_id, db)
ids_str = [str(a) for a in body.alert_ids]
q = text("""
UPDATE aisoc_cases
@@ -428,7 +467,7 @@ async def add_alerts(case_id: uuid.UUID, body: AddAlertsRequest, db: DBSession,
updated_at = now()
WHERE id = :id
RETURNING *
- """).bindparams(id=case_id, new_ids=ids_str)
+ """).bindparams(id=cid, new_ids=ids_str)
try:
row = (await db.execute(q)).fetchone()
if not row:
@@ -443,10 +482,11 @@ async def add_alerts(case_id: uuid.UUID, body: AddAlertsRequest, db: DBSession,
@router.post("/{case_id}/observables", response_model=CaseResponse, summary="Update observable graph")
-async def update_observables(case_id: uuid.UUID, body: UpdateObservablesRequest, db: DBSession, user: AuthUser) -> CaseResponse:
+async def update_observables(case_id: str, body: UpdateObservablesRequest, db: DBSession, user: AuthUser) -> CaseResponse:
import json as _json
- existing = (await db.execute(text("SELECT observable_graph FROM aisoc_cases WHERE id = :id").bindparams(id=case_id))).fetchone()
+ cid = await _resolve_case_id(case_id, db)
+ existing = (await db.execute(text("SELECT observable_graph FROM aisoc_cases WHERE id = :id").bindparams(id=cid))).fetchone()
if not existing:
raise HTTPException(status_code=404, detail="Case not found.")
@@ -469,7 +509,7 @@ async def update_observables(case_id: uuid.UUID, body: UpdateObservablesRequest,
graph = {"nodes": nodes, "edges": edges}
q = text("""
UPDATE aisoc_cases SET observable_graph = :g::jsonb, updated_at = now() WHERE id = :id RETURNING *
- """).bindparams(id=case_id, g=_json.dumps(graph))
+ """).bindparams(id=cid, g=_json.dumps(graph))
try:
row = (await db.execute(q)).fetchone()
await db.commit()
@@ -480,8 +520,9 @@ async def update_observables(case_id: uuid.UUID, body: UpdateObservablesRequest,
@router.post("/{case_id}/comments", response_model=CommentResponse, status_code=201, summary="Add comment")
-async def add_comment(case_id: uuid.UUID, body: AddCommentRequest, db: DBSession, user: AuthUser) -> CommentResponse:
- exists = (await db.execute(text("SELECT 1 FROM aisoc_cases WHERE id = :id").bindparams(id=case_id))).fetchone()
+async def add_comment(case_id: str, body: AddCommentRequest, db: DBSession, user: AuthUser) -> CommentResponse:
+ cid = await _resolve_case_id(case_id, db)
+ exists = (await db.execute(text("SELECT 1 FROM aisoc_cases WHERE id = :id").bindparams(id=cid))).fetchone()
if not exists:
raise HTTPException(status_code=404, detail="Case not found.")
@@ -490,7 +531,7 @@ async def add_comment(case_id: uuid.UUID, body: AddCommentRequest, db: DBSession
q = text("""
INSERT INTO aisoc_case_comments (id, case_id, author, body, is_system, created_at)
VALUES (:id, :case_id, :author, :body, :sys, :now) RETURNING *
- """).bindparams(id=comment_id, case_id=case_id, author=str(user) if user else "system", body=body.body, sys=body.is_system, now=now)
+ """).bindparams(id=comment_id, case_id=cid, author=str(user) if user else "system", body=body.body, sys=body.is_system, now=now)
try:
row = (await db.execute(q)).fetchone()
await db.commit()
@@ -504,14 +545,30 @@ async def add_comment(case_id: uuid.UUID, body: AddCommentRequest, db: DBSession
@router.get("/{case_id}/comments", response_model=list[CommentResponse], summary="List case comments")
-async def list_comments(case_id: uuid.UUID, db: DBSession, user: AuthUser) -> list[CommentResponse]:
- rows = (await db.execute(text("SELECT * FROM aisoc_case_comments WHERE case_id = :id ORDER BY created_at").bindparams(id=case_id))).fetchall()
+async def list_comments(case_id: str, db: DBSession, user: AuthUser) -> list[CommentResponse]:
+ cid = await _resolve_case_id(case_id, db)
+ rows = (await db.execute(text("SELECT * FROM aisoc_case_comments WHERE case_id = :id ORDER BY created_at").bindparams(id=cid))).fetchall()
return [CommentResponse(id=r.id, case_id=r.case_id, author=r.author, body=r.body, is_system=r.is_system, created_at=r.created_at) for r in rows]
+# Alias `/notes` → `/comments` so the web console (which calls `/notes` for the
+# "Add Note" affordance) hits the same backing store. Keeping both routes
+# avoids a behavior change for any existing integration that already speaks
+# `/comments`.
[email protected]("/{case_id}/notes", response_model=list[CommentResponse], summary="List case notes (alias of /comments)")
+async def list_notes(case_id: str, db: DBSession, user: AuthUser) -> list[CommentResponse]:
+ return await list_comments(case_id, db, user)
+
+
[email protected]("/{case_id}/notes", response_model=CommentResponse, status_code=201, summary="Add case note (alias of /comments)")
+async def add_note(case_id: str, body: AddCommentRequest, db: DBSession, user: AuthUser) -> CommentResponse:
+ return await add_comment(case_id, body, db, user)
+
+
@router.get("/{case_id}/evidence", response_model=EvidenceReport, summary="Export evidence chain report")
-async def evidence_report(case_id: uuid.UUID, db: DBSession, user: AuthUser) -> EvidenceReport:
- row = (await db.execute(text("SELECT * FROM aisoc_cases WHERE id = :id").bindparams(id=case_id))).fetchone()
+async def evidence_report(case_id: str, db: DBSession, user: AuthUser) -> EvidenceReport:
+ cid = await _resolve_case_id(case_id, db)
+ row = (await db.execute(text("SELECT * FROM aisoc_cases WHERE id = :id").bindparams(id=cid))).fetchone()
if not row:
raise HTTPException(status_code=404, detail="Case not found.")
return EvidenceReport(
@@ -538,9 +595,10 @@ async def evidence_report(case_id: uuid.UUID, db: DBSession, user: AuthUser) ->
@router.get("/{case_id}/timeline", response_model=TimelineResponse, summary="Case activity timeline")
-async def case_timeline(case_id: uuid.UUID, db: DBSession, user: AuthUser) -> TimelineResponse:
+async def case_timeline(case_id: str, db: DBSession, user: AuthUser) -> TimelineResponse:
+ cid = await _resolve_case_id(case_id, db)
case_row = (
- await db.execute(text("SELECT * FROM aisoc_cases WHERE id = :id").bindparams(id=case_id))
+ await db.execute(text("SELECT * FROM aisoc_cases WHERE id = :id").bindparams(id=cid))
).fetchone()
if not case_row:
raise HTTPException(status_code=404, detail="Case not found.")
@@ -579,7 +637,7 @@ async def case_timeline(case_id: uuid.UUID, db: DBSession, user: AuthUser) -> Ti
text(
"SELECT id, author, body, is_system, created_at "
"FROM aisoc_case_comments WHERE case_id = :id ORDER BY created_at"
- ).bindparams(id=case_id)
+ ).bindparams(id=cid)
)
).fetchall()
for c in comment_rows:
@@ -625,7 +683,7 @@ async def case_timeline(case_id: uuid.UUID, db: DBSession, user: AuthUser) -> Ti
text(
"SELECT id, title, status, assignee, created_at "
"FROM aisoc_case_tasks WHERE case_id = :id ORDER BY created_at"
- ).bindparams(id=case_id)
+ ).bindparams(id=cid)
)
).fetchall()
for t in task_rows:
@@ -652,9 +710,10 @@ async def case_timeline(case_id: uuid.UUID, db: DBSession, user: AuthUser) -> Ti
@router.get("/{case_id}/tasks", response_model=list[TaskResponse], summary="List case tasks")
-async def list_tasks(case_id: uuid.UUID, db: DBSession, user: AuthUser) -> list[TaskResponse]:
+async def list_tasks(case_id: str, db: DBSession, user: AuthUser) -> list[TaskResponse]:
+ cid = await _resolve_case_id(case_id, db)
exists = (
- await db.execute(text("SELECT 1 FROM aisoc_cases WHERE id = :id").bindparams(id=case_id))
+ await db.execute(text("SELECT 1 FROM aisoc_cases WHERE id = :id").bindparams(id=cid))
).fetchone()
if not exists:
raise HTTPException(status_code=404, detail="Case not found.")
@@ -663,7 +722,7 @@ async def list_tasks(case_id: uuid.UUID, db: DBSession, user: AuthUser) -> list[
text(
"SELECT id, title, status, assignee, due_at, created_at "
"FROM aisoc_case_tasks WHERE case_id = :id ORDER BY created_at"
- ).bindparams(id=case_id)
+ ).bindparams(id=cid)
)
).fetchall()
return [_row_to_task(r) for r in rows]
@@ -671,13 +730,14 @@ async def list_tasks(case_id: uuid.UUID, db: DBSession, user: AuthUser) -> list[
@router.post("/{case_id}/tasks", response_model=TaskResponse, status_code=201, summary="Create task")
async def create_task(
- case_id: uuid.UUID,
+ case_id: str,
body: CreateTaskRequest,
db: DBSession,
user: AuthUser,
) -> TaskResponse:
+ cid = await _resolve_case_id(case_id, db)
exists = (
- await db.execute(text("SELECT 1 FROM aisoc_cases WHERE id = :id").bindparams(id=case_id))
+ await db.execute(text("SELECT 1 FROM aisoc_cases WHERE id = :id").bindparams(id=cid))
).fetchone()
if not exists:
raise HTTPException(status_code=404, detail="Case not found.")
@@ -697,7 +757,7 @@ async def create_task(
"""
).bindparams(
id=task_id,
- case_id=case_id,
+ case_id=cid,
title=body.title,
status=body.status,
assignee=body.assignee,
@@ -716,14 +776,15 @@ async def create_task(
@router.patch("/{case_id}/tasks/{task_id}", response_model=TaskResponse, summary="Update task")
async def update_task(
- case_id: uuid.UUID,
+ case_id: str,
task_id: uuid.UUID,
body: UpdateTaskRequest,
db: DBSession,
user: AuthUser,
) -> TaskResponse:
+ cid = await _resolve_case_id(case_id, db)
sets: list[str] = []
- params: dict[str, Any] = {"id": task_id, "case_id": case_id, "now": datetime.now(UTC)}
+ params: dict[str, Any] = {"id": task_id, "case_id": cid, "now": datetime.now(UTC)}
if body.title is not None:
sets.append("title = :title")
params["title"] = body.title
@@ -789,20 +850,21 @@ async def _agents_proxy(method: str, path: str, **kwargs: Any) -> httpx.Response
@router.post("/{case_id}/investigate", summary="Launch investigation for case")
async def case_investigate(
- case_id: uuid.UUID,
+ case_id: str,
body: InvestigateRequest,
db: DBSession,
user: AuthUser,
) -> dict[str, Any]:
+ cid = await _resolve_case_id(case_id, db)
exists = (
- await db.execute(text("SELECT 1 FROM aisoc_cases WHERE id = :id").bindparams(id=case_id))
+ await db.execute(text("SELECT 1 FROM aisoc_cases WHERE id = :id").bindparams(id=cid))
).fetchone()
if not exists:
raise HTTPException(status_code=404, detail="Case not found.")
resp = await _agents_proxy(
"POST",
- f"/api/v1/cases/{case_id}/investigate",
+ f"/api/v1/cases/{cid}/investigate",
json={"alert_summary": body.alert_summary or ""},
)
if resp.status_code >= 400:
@@ -810,9 +872,33 @@ async def case_investigate(
return resp.json()
[email protected]("/{case_id}/investigations", summary="List investigation runs for a case")
+async def list_case_investigations(
+ case_id: str,
+ db: DBSession,
+ user: AuthUser,
+) -> dict[str, Any]:
+ """List all investigation runs for a case.
+
+ The agents service is the source of truth. When it's unreachable we return
+ an empty list rather than 503 so the case detail page still renders.
+ """
+ cid = await _resolve_case_id(case_id, db)
+ try:
+ resp = await _agents_proxy("GET", f"/api/v1/cases/{cid}/investigations")
+ if resp.status_code == 404:
+ return {"runs": []}
+ if resp.status_code >= 400:
+ return {"runs": []}
+ return resp.json()
+ except HTTPException:
+ # Agents service unavailable — render a soft-empty list instead of 503.
+ return {"runs": []}
+
+
@router.get("/{case_id}/investigations/{run_id}", summary="Get investigation run")
async def case_investigation_run(
- case_id: uuid.UUID,
+ case_id: str,
run_id: str,
user: AuthUser,
) -> dict[str, Any]:
@@ -827,7 +913,7 @@ async def case_investigation_run(
summary="Download investigation PDF report",
)
async def case_investigation_pdf(
- case_id: uuid.UUID,
+ case_id: str,
run_id: str,
user: AuthUser,
) -> Response:
@@ -844,3 +930,60 @@ async def case_investigation_pdf(
),
},
)
+
+
[email protected]("/{case_id}/related", summary="List related cases (by alert/observable overlap)")
+async def list_related_cases(
+ case_id: str,
+ db: DBSession,
+ user: AuthUser,
+) -> dict[str, Any]:
+ """Return other cases that share alerts or observables with this case.
+
+ This is intentionally a lightweight heuristic — we look for cases that
+ overlap on `alert_ids` or share an observable IP/host. It's the smallest
+ thing the case detail page needs to stop 404'ing.
+ """
+ cid = await _resolve_case_id(case_id, db)
+ row = (
+ await db.execute(
+ text(
+ "SELECT alert_ids, observable_graph FROM aisoc_cases WHERE id = :id"
+ ).bindparams(id=cid)
+ )
+ ).fetchone()
+ if not row:
+ raise HTTPException(status_code=404, detail="Case not found.")
+
+ alert_ids = list(row.alert_ids or [])
+ related: list[dict[str, Any]] = []
+
+ if alert_ids:
+ rows = (
+ await db.execute(
+ text(
+ """
+ SELECT id, case_number, title, severity, status, created_at
+ FROM aisoc_cases
+ WHERE id <> :id
+ AND alert_ids && CAST(:alerts AS UUID[])
+ ORDER BY created_at DESC
+ LIMIT 20
+ """
+ ).bindparams(id=cid, alerts=[str(a) for a in alert_ids])
+ )
+ ).fetchall()
+ for r in rows:
+ related.append(
+ {
+ "id": str(r.id),
+ "case_number": r.case_number,
+ "title": r.title,
+ "severity": r.severity or "medium",
+ "status": r.status or "new",
+ "created_at": r.created_at.isoformat() if r.created_at else None,
+ "reason": "shared_alerts",
+ }
+ )
+
+ return {"related": related}
diff --git a/services/api/app/api/v1/endpoints/connectors.py b/services/api/app/api/v1/endpoints/connectors.py
index 24c8383c1..4e155e924 100644
--- a/services/api/app/api/v1/endpoints/connectors.py
+++ b/services/api/app/api/v1/endpoints/connectors.py
@@ -33,10 +33,12 @@ Tenant scoping invariants enforced here:
from __future__ import annotations
+import json
import logging
import re
import uuid
from datetime import UTC, datetime
+from pathlib import Path
from typing import Annotated, Any
# Connector type IDs are restricted to alphanumeric, hyphens, and underscores.
@@ -192,21 +194,64 @@ def _connectors_service_url(path: str) -> str:
return f"{base}/api/v1{suffix}"
-async def _fetch_catalog() -> list[dict[str, Any]]:
- """Pull the connector catalog from the connectors microservice.
+# Fallback catalog shipped with the API image. Generated from the connectors
+# microservice's registry and committed alongside the API source. Used when
+# the connectors microservice is not deployed (single-tenant / demo) or
+# temporarily unreachable so the AddConnector wizard still renders. Refresh:
+#
+# cd services/connectors && python -c "import json; \\
+# from app.connectors import list_connector_schemas as l; \\
+# print(json.dumps(l(), indent=2))" \\
+# > ../api/app/data/connector_catalog_fallback.json
+_FALLBACK_CATALOG_PATH = (
+ Path(__file__).resolve().parents[3] / "data" / "connector_catalog_fallback.json"
+)
+
+
+def _load_fallback_catalog() -> list[dict[str, Any]]:
+ """Return the bundled connector catalog, or an empty list if missing."""
+ try:
+ with _FALLBACK_CATALOG_PATH.open("r", encoding="utf-8") as fh:
+ data = json.load(fh)
+ except (OSError, ValueError) as exc:
+ logger.warning(
+ "connectors_service.catalog.fallback_unavailable path=%s error=%s",
+ _FALLBACK_CATALOG_PATH,
+ type(exc).__name__,
+ )
+ return []
+ return data if isinstance(data, list) else []
+
- Raises a clear 503 if the microservice is unreachable. We don't cache
- here on purpose: catalog lookups are infrequent (a wizard open per
- operator), and a stale cache would make the "I just added a connector
- class and redeployed" feedback loop confusing.
+async def _fetch_catalog() -> list[dict[str, Any]]:
+ """Pull the connector catalog from the connectors microservice, with fallback.
+
+ Resolution order:
+ 1. If ``CONNECTORS_SERVICE_URL`` is set and reachable, use it (live source
+ of truth — supports newly-added connectors without an API redeploy).
+ 2. Otherwise, fall back to the catalog bundled with the API image. This
+ is what keeps demo / single-tenant deploys functional even when the
+ dedicated connectors microservice is not deployed.
"""
+ base_url = (getattr(settings, "CONNECTORS_SERVICE_URL", "") or "").strip()
+ if not base_url:
+ logger.info("connectors_service.catalog.using_fallback reason=no_url_configured")
+ return _load_fallback_catalog()
+
url = _connectors_service_url("/connectors/schemas")
try:
async with httpx.AsyncClient(timeout=_CATALOG_TIMEOUT) as client:
resp = await client.get(url)
resp.raise_for_status()
except httpx.HTTPError as exc:
- logger.warning("connectors_service.catalog.unreachable url=%s error_type=%s", url, type(exc).__name__)
+ logger.warning(
+ "connectors_service.catalog.unreachable url=%s error_type=%s falling_back=true",
+ url,
+ type(exc).__name__,
+ )
+ fallback = _load_fallback_catalog()
+ if fallback:
+ return fallback
raise HTTPException(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
detail="connectors service is unavailable; cannot list connector catalog",
diff --git a/services/api/app/api/v1/endpoints/detection_compat.py b/services/api/app/api/v1/endpoints/detection_compat.py
new file mode 100644
index 000000000..7bd9d4cc8
--- /dev/null
+++ b/services/api/app/api/v1/endpoints/detection_compat.py
@@ -0,0 +1,381 @@
+"""Frontend-compat detection rule endpoints under /api/v1/detection.
+
+The analyst console (`apps/web/src/lib/api.ts → detectionApi`) talks to
+``/api/v1/detection/rules`` and ``/api/v1/detection/test`` with a camelCase,
+``enabled``-flag payload shape that pre-dates the v1 ``/api/v1/rules`` router
+defined in :mod:`detection_rules`.
+
+Rather than break the canonical backend contract (which other internal
+callers, including the MCP server in ``services/mcp``, already rely on) we
+publish a thin façade here that:
+
+* GET /api/v1/detection/rules → list rules ``{ rules, total }``
+* POST /api/v1/detection/rules → create with frontend shape
+* GET /api/v1/detection/rules/{id} → single rule frontend shape
+* PATCH /api/v1/detection/rules/{id} → update with frontend shape
+* DELETE /api/v1/detection/rules/{id} → delete tenant-owned rule
+* POST /api/v1/detection/test → execute body+language vs sample
+
+The shim re-uses the SQLAlchemy ORM model and rule-engine helpers so storage,
+permissions, and execution semantics stay identical to the canonical router.
+"""
+
+from __future__ import annotations
+
+import json
+import uuid
+from datetime import UTC, datetime
+from typing import Annotated, Any
+
+from fastapi import APIRouter, Depends, HTTPException, status
+from pydantic import BaseModel, Field
+from sqlalchemy import and_, or_, select, update
+
+from app.api.v1.deps import AuthUser, DBSession, require_permission
+from app.models.detection_rule import DetectionRule
+from app.services.rule_engine import execute_rule
+
+router = APIRouter(prefix="/detection", tags=["detection_rules"])
+
+
+# ─── Frontend wire models ────────────────────────────────────────────────────
+
+
+class FrontendDetectionRule(BaseModel):
+ """Mirrors `DetectionRule` in apps/web/src/lib/api.ts."""
+
+ id: str
+ name: str
+ description: str | None = None
+ language: str
+ body: str
+ enabled: bool = True
+ tags: list[str] = Field(default_factory=list)
+ mitre: list[str] = Field(default_factory=list)
+ severity: str = "medium"
+ createdAt: str
+ updatedAt: str
+ lastTriggeredAt: str | None = None
+ hitCount: int = 0
+
+
+class ListResponse(BaseModel):
+ rules: list[FrontendDetectionRule]
+ total: int
+
+
+class CreateBody(BaseModel):
+ name: str
+ description: str | None = None
+ language: str
+ body: str
+ enabled: bool = True
+ tags: list[str] = Field(default_factory=list)
+ mitre: list[str] = Field(default_factory=list)
+ severity: str = "medium"
+ category: str = "custom"
+
+
+class UpdateBody(BaseModel):
+ name: str | None = None
+ description: str | None = None
+ language: str | None = None
+ body: str | None = None
+ enabled: bool | None = None
+ tags: list[str] | None = None
+ mitre: list[str] | None = None
+ severity: str | None = None
+
+
+class TestBody(BaseModel):
+ language: str
+ body: str
+ sample: str | None = None
+
+
+class HuntPreviewItem(BaseModel):
+ id: str
+ timestamp: str
+ source: str
+ severity: str | None = None
+ fields: dict[str, Any] = Field(default_factory=dict)
+
+
+class TestResponse(BaseModel):
+ matches: int
+ preview: list[HuntPreviewItem]
+
+
+# ─── Helpers ─────────────────────────────────────────────────────────────────
+
+
+def _to_frontend(rule: DetectionRule) -> FrontendDetectionRule:
+ """Map ORM row → frontend shape."""
+ mitre: list[str] = []
+ if rule.mitre_techniques:
+ mitre.extend(str(t) for t in rule.mitre_techniques)
+ if rule.mitre_tactics:
+ mitre.extend(str(t) for t in rule.mitre_tactics)
+
+ return FrontendDetectionRule(
+ id=str(rule.id),
+ name=rule.name,
+ description=rule.description,
+ language=rule.rule_language,
+ body=rule.rule_body,
+ enabled=(rule.status == "active"),
+ tags=list(rule.tags or []),
+ mitre=mitre,
+ severity=rule.severity,
+ createdAt=rule.created_at.isoformat() if rule.created_at else datetime.now(UTC).isoformat(),
+ updatedAt=rule.updated_at.isoformat() if rule.updated_at else datetime.now(UTC).isoformat(),
+ lastTriggeredAt=rule.last_triggered.isoformat() if rule.last_triggered else None,
+ hitCount=rule.total_hits or 0,
+ )
+
+
+def _parse_sample_events(sample: str | None) -> list[dict[str, Any]]:
+ """Best-effort parse of the optional sample blob into events.
+
+ Accepts JSON arrays, NDJSON, or plain text (treated as a single event).
+ The detection engine just needs a list of dicts; missing fields are fine.
+ """
+ if not sample:
+ return [{}]
+
+ text = sample.strip()
+ if not text:
+ return [{}]
+
+ # Try JSON array first.
+ if text.startswith("["):
+ try:
+ data = json.loads(text)
+ if isinstance(data, list):
+ return [d if isinstance(d, dict) else {"_raw": d} for d in data]
+ except Exception:
+ pass
+
+ # Try NDJSON (one JSON object per line).
+ events: list[dict[str, Any]] = []
+ parsed_any = False
+ for line in text.splitlines():
+ line = line.strip()
+ if not line:
+ continue
+ try:
+ obj = json.loads(line)
+ parsed_any = True
+ events.append(obj if isinstance(obj, dict) else {"_raw": obj})
+ except Exception:
+ events.append({"message": line})
+
+ if not parsed_any and not events:
+ events = [{"message": text}]
+
+ return events or [{}]
+
+
+# ─── Routes ──────────────────────────────────────────────────────────────────
+
+
[email protected]("/rules", response_model=ListResponse)
+async def list_rules_compat(
+ current_user: Annotated[AuthUser, Depends(require_permission("rules:read"))],
+ db: DBSession,
+) -> ListResponse:
+ """List detection rules visible to the current tenant (built-ins + tenant-owned)."""
+ tid = current_user.tenant_id
+ stmt = (
+ select(DetectionRule)
+ .where(
+ or_(
+ DetectionRule.tenant_id == tid,
+ and_(DetectionRule.tenant_id.is_(None), DetectionRule.is_builtin.is_(True)),
+ )
+ )
+ .order_by(DetectionRule.name)
+ )
+ result = await db.execute(stmt)
+ rules = result.scalars().all()
+ items = [_to_frontend(r) for r in rules]
+ return ListResponse(rules=items, total=len(items))
+
+
[email protected]("/rules", response_model=FrontendDetectionRule, status_code=status.HTTP_201_CREATED)
+async def create_rule_compat(
+ body: CreateBody,
+ current_user: Annotated[AuthUser, Depends(require_permission("rules:write"))],
+ db: DBSession,
+) -> FrontendDetectionRule:
+ """Create a tenant-owned detection rule using the frontend shape."""
+ rule = DetectionRule(
+ tenant_id=current_user.tenant_id,
+ name=body.name,
+ description=body.description,
+ rule_language=body.language,
+ rule_body=body.body,
+ category=body.category or "custom",
+ severity=body.severity or "medium",
+ confidence=50,
+ mitre_tactics=[],
+ mitre_techniques=list(body.mitre or []),
+ tags=list(body.tags or []),
+ status="active" if body.enabled else "inactive",
+ created_by_id=current_user.user_id,
+ )
+ db.add(rule)
+ await db.commit()
+ await db.refresh(rule)
+ return _to_frontend(rule)
+
+
[email protected]("/rules/{rule_id}", response_model=FrontendDetectionRule)
+async def get_rule_compat(
+ rule_id: uuid.UUID,
+ current_user: Annotated[AuthUser, Depends(require_permission("rules:read"))],
+ db: DBSession,
+) -> FrontendDetectionRule:
+ """Fetch a single rule by ID in the frontend shape."""
+ stmt = select(DetectionRule).where(
+ DetectionRule.id == rule_id,
+ or_(
+ DetectionRule.tenant_id == current_user.tenant_id,
+ DetectionRule.tenant_id.is_(None),
+ ),
+ )
+ rule = (await db.execute(stmt)).scalar_one_or_none()
+ if rule is None:
+ raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Rule not found")
+ return _to_frontend(rule)
+
+
[email protected]("/rules/{rule_id}", response_model=FrontendDetectionRule)
+async def update_rule_compat(
+ rule_id: uuid.UUID,
+ body: UpdateBody,
+ current_user: Annotated[AuthUser, Depends(require_permission("rules:write"))],
+ db: DBSession,
+) -> FrontendDetectionRule:
+ """Update a tenant-owned rule using the frontend shape."""
+ stmt = select(DetectionRule).where(
+ DetectionRule.id == rule_id,
+ DetectionRule.tenant_id == current_user.tenant_id,
+ )
+ rule = (await db.execute(stmt)).scalar_one_or_none()
+ if rule is None:
+ raise HTTPException(
+ status_code=status.HTTP_404_NOT_FOUND,
+ detail="Rule not found or cannot be modified",
+ )
+
+ updates: dict[str, Any] = {}
+ if body.name is not None:
+ updates["name"] = body.name
+ if body.description is not None:
+ updates["description"] = body.description
+ if body.language is not None:
+ updates["rule_language"] = body.language
+ if body.body is not None:
+ updates["rule_body"] = body.body
+ if body.severity is not None:
+ updates["severity"] = body.severity
+ if body.tags is not None:
+ updates["tags"] = list(body.tags)
+ if body.mitre is not None:
+ updates["mitre_techniques"] = list(body.mitre)
+ if body.enabled is not None:
+ updates["status"] = "active" if body.enabled else "inactive"
+
+ if updates:
+ updates["updated_at"] = datetime.now(UTC)
+ updates["version"] = (rule.version or 1) + 1
+ await db.execute(update(DetectionRule).where(DetectionRule.id == rule_id).values(**updates))
+ await db.commit()
+ await db.refresh(rule)
+
+ return _to_frontend(rule)
+
+
+ "/rules/{rule_id}",
+ status_code=status.HTTP_204_NO_CONTENT,
+ response_model=None,
+)
+async def delete_rule_compat(
+ rule_id: uuid.UUID,
+ current_user: Annotated[AuthUser, Depends(require_permission("rules:write"))],
+ db: DBSession,
+) -> None:
+ """Delete a tenant-owned rule."""
+ stmt = select(DetectionRule).where(
+ DetectionRule.id == rule_id,
+ DetectionRule.tenant_id == current_user.tenant_id,
+ )
+ rule = (await db.execute(stmt)).scalar_one_or_none()
+ if rule is None:
+ raise HTTPException(
+ status_code=status.HTTP_404_NOT_FOUND,
+ detail="Rule not found or cannot be deleted",
+ )
+ await db.delete(rule)
+ await db.commit()
+
+
[email protected]("/test", response_model=TestResponse)
+async def test_rule_compat(
+ body: TestBody,
+ current_user: Annotated[AuthUser, Depends(require_permission("rules:read"))],
+) -> TestResponse:
+ """Run an ad-hoc rule body against an optional sample event blob.
+
+ The detection IDE in the analyst console hits this with the rule body
+ the user is actively editing, which has not been persisted yet, so the
+ rule never needs to live in the database.
+ """
+ events = _parse_sample_events(body.sample)
+ rid = f"adhoc-{uuid.uuid4()}"
+
+ match = execute_rule(
+ rule_id=rid,
+ rule_name="ad-hoc",
+ rule_language=body.language or "sigma",
+ rule_body=body.body or "",
+ severity="medium",
+ events=events,
+ )
+
+ matched_events: list[dict[str, Any]] = match.match_details.get("matched_events", []) or []
+
+ preview: list[HuntPreviewItem] = []
+ now_iso = datetime.now(UTC).isoformat()
+ for idx, evt in enumerate(matched_events[:25]):
+ if not isinstance(evt, dict):
+ evt = {"_raw": evt}
+ ts = evt.get("@timestamp") or evt.get("timestamp") or now_iso
+ src = evt.get("source") or evt.get("event", {}).get("module") or "sample"
+ sev = evt.get("severity") or evt.get("event", {}).get("severity") or "medium"
+ preview.append(
+ HuntPreviewItem(
+ id=str(evt.get("id") or evt.get("_id") or f"sample-{idx}"),
+ timestamp=str(ts),
+ source=str(src),
+ severity=str(sev),
+ fields=evt,
+ )
+ )
+
+ if match.error and not preview:
+ # Surface parser errors as a synthetic preview row so the IDE
+ # tells the analyst something useful instead of "0 matches".
+ preview.append(
+ HuntPreviewItem(
+ id="rule-error",
+ timestamp=now_iso,
+ source="rule-engine",
+ severity="info",
+ fields={"error": match.error, "engine_ms": match.execution_time_ms},
+ )
+ )
+
+ return TestResponse(matches=len(matched_events), preview=preview)
diff --git a/services/api/app/api/v1/endpoints/easm.py b/services/api/app/api/v1/endpoints/easm.py
index 48c10688b..d7d32fc6f 100644
--- a/services/api/app/api/v1/endpoints/easm.py
+++ b/services/api/app/api/v1/endpoints/easm.py
@@ -11,6 +11,7 @@ from pydantic import BaseModel
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
+from app.api.v1.deps import CurrentUser, get_current_user
from app.core.config import get_settings
from app.db.database import get_db
from app.models.easm import ExternalAsset, ExternalAssetDrift, ExternalAssetType
@@ -91,15 +92,21 @@ async def trigger_easm_scan(
@router.get("/assets")
async def list_external_assets(
- tenant_id: UUID,
+ tenant_id: UUID | None = Query(None),
asset_type: Optional[ExternalAssetType] = Query(None),
limit: int = Query(50, le=200),
db: AsyncSession = Depends(get_db),
+ current_user: CurrentUser = Depends(get_current_user),
) -> List[Dict[str, Any]]:
- """List externally discovered assets for a tenant."""
+ """List externally discovered assets for a tenant.
+
+ ``tenant_id`` defaults to the authenticated user's tenant, so the analyst
+ console can hit ``/easm/assets`` without explicit tenant scoping.
+ """
+ effective_tenant = tenant_id or current_user.tenant_id
stmt = (
select(ExternalAsset)
- .where(ExternalAsset.tenant_id == tenant_id)
+ .where(ExternalAsset.tenant_id == effective_tenant)
.order_by(ExternalAsset.last_seen.desc())
.limit(limit)
)
@@ -123,15 +130,17 @@ async def list_external_assets(
@router.get("/drift")
async def list_external_asset_drift(
- tenant_id: UUID,
+ tenant_id: UUID | None = Query(None),
external_asset_id: Optional[UUID] = Query(None),
limit: int = Query(50, le=200),
db: AsyncSession = Depends(get_db),
+ current_user: CurrentUser = Depends(get_current_user),
) -> List[Dict[str, Any]]:
"""List drift events (new ports, certs, sub-domains, etc.)."""
+ effective_tenant = tenant_id or current_user.tenant_id
stmt = (
select(ExternalAssetDrift)
- .where(ExternalAssetDrift.tenant_id == tenant_id)
+ .where(ExternalAssetDrift.tenant_id == effective_tenant)
.order_by(ExternalAssetDrift.detected_at.desc())
.limit(limit)
)
diff --git a/services/api/app/api/v1/endpoints/graph.py b/services/api/app/api/v1/endpoints/graph.py
index 04f6de42b..83c5445cd 100644
--- a/services/api/app/api/v1/endpoints/graph.py
+++ b/services/api/app/api/v1/endpoints/graph.py
@@ -98,6 +98,27 @@ class MitreCoverageItem(BaseModel):
alert_count: int
+# ── Frontend-shape coverage payload ─────────────────────────────────────────
+# Matches `MitreCoverage` in apps/web/src/lib/api.ts so the analyst console's
+# /api/v1/graph/mitre/coverage call hydrates without a 404 + client-side
+# remap. Intensity is normalized to [0, 1] across the returned cell set.
+
+
+class MitreCoverageCell(BaseModel):
+ techniqueId: str
+ techniqueName: str
+ tactic: str
+ detections: int
+ alerts: int
+ intensity: float
+
+
+class MitreCoverageResponse(BaseModel):
+ tactics: list[str]
+ cells: list[MitreCoverageCell]
+ generatedAt: str
+
+
class UpsertHostRequest(BaseModel):
host_id: str
hostname: str
@@ -378,6 +399,80 @@ async def get_mitre_coverage(
]
+ "/mitre/coverage",
+ response_model=MitreCoverageResponse,
+ summary="MITRE ATT&CK coverage (frontend shape)",
+)
+async def get_mitre_coverage_compat(
+ current_user: CurrentUser = Depends(get_current_user),
+) -> MitreCoverageResponse:
+ """Aggregated MITRE coverage in the shape the analyst console expects.
+
+ The console's :code:`graph.getMitreCoverage()` call hits this URL and
+ expects ``{ tactics, cells, generatedAt }``. We aggregate the
+ per-technique records returned by the same Neo4j-backed service used by
+ ``/graph/mitre-coverage`` and degrade gracefully (empty set) when the
+ knowledge graph is offline, mirroring that endpoint's behaviour.
+ """
+ from datetime import UTC as _UTC, datetime as _dt
+
+ try:
+ records = await graph_service.get_mitre_coverage(
+ tenant_id=str(current_user.tenant_id),
+ )
+ except Exception as exc:
+ if _is_graph_unavailable(exc):
+ logger.info(
+ "MITRE coverage (compat): graph backend unavailable; empty",
+ exc_info=False,
+ )
+ return MitreCoverageResponse(
+ tactics=[],
+ cells=[],
+ generatedAt=_dt.now(_UTC).isoformat(),
+ )
+ raise HTTPException(
+ status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
+ detail=f"Graph query failed: {exc}",
+ ) from exc
+
+ cells: list[MitreCoverageCell] = []
+ tactics: set[str] = set()
+ max_alerts = 1
+ for r in records:
+ max_alerts = max(max_alerts, int(r.get("alert_count", 0) or 0))
+
+ for r in records:
+ technique_id = r.get("technique_id") or ""
+ tactic = r.get("tactic") or "unknown"
+ alerts = int(r.get("alert_count", 0) or 0)
+ # detections per technique aren't tracked in the graph schema yet;
+ # treat coverage as a 1:1 proxy of alert evidence so the heatmap has
+ # something to shade. When richer data lands, swap in a separate
+ # aggregation here.
+ detections = 1 if alerts > 0 else 0
+ intensity = round(alerts / max_alerts, 4) if max_alerts else 0.0
+
+ tactics.add(tactic)
+ cells.append(
+ MitreCoverageCell(
+ techniqueId=technique_id,
+ techniqueName=r.get("name") or technique_id,
+ tactic=tactic,
+ detections=detections,
+ alerts=alerts,
+ intensity=intensity,
+ )
+ )
+
+ return MitreCoverageResponse(
+ tactics=sorted(tactics),
+ cells=cells,
+ generatedAt=_dt.now(_UTC).isoformat(),
+ )
+
+
# ─── Write Endpoints ──────────────────────────────────────────────────────────
diff --git a/services/api/app/api/v1/router.py b/services/api/app/api/v1/router.py
index ada1200e1..fc8358854 100644
--- a/services/api/app/api/v1/router.py
+++ b/services/api/app/api/v1/router.py
@@ -16,6 +16,7 @@ from app.api.v1.endpoints import (
compliance,
connectors,
deployment,
+ detection_compat,
detection_loop,
detection_proposals,
detection_rules,
@@ -62,6 +63,8 @@ api_router.include_router(cases.router)
api_router.include_router(connectors.router)
api_router.include_router(tenants.router)
api_router.include_router(detection_rules.router)
+# Frontend-shape facade: /api/v1/detection/rules + /api/v1/detection/test
+api_router.include_router(detection_compat.router)
api_router.include_router(detection_proposals.router)
api_router.include_router(federated.router)
api_router.include_router(graph.router)
diff --git a/services/api/app/data/connector_catalog_fallback.json b/services/api/app/data/connector_catalog_fallback.json
new file mode 100644
index 000000000..72e2cf54a
--- /dev/null
+++ b/services/api/app/data/connector_catalog_fallback.json
@@ -0,0 +1,852 @@
+[
+ {
+ "connector_id": "aws_security_hub",
+ "connector_name": "AWS Security Hub",
+ "category": "cloud",
+ "description": "AWS Security Hub findings (GuardDuty, Inspector, Macie, third-party).",
+ "fields": [
+ {
+ "name": "region",
+ "type": "string",
+ "label": "AWS Region",
+ "required": true,
+ "default": "us-east-1"
+ },
+ {
+ "name": "access_key",
+ "type": "string",
+ "label": "Access Key ID",
+ "required": false,
+ "help_text": "Leave blank to use the runtime IAM role / instance profile."
+ },
+ {
+ "name": "secret_key",
+ "type": "secret",
+ "label": "Secret Access Key",
+ "required": false,
+ "help_text": "Required only when supplying a static access key above."
+ }
+ ],
+ "docs_url": "/docs/connectors/aws-security-hub"
+ },
+ {
+ "connector_id": "azure_activity",
+ "connector_name": "Azure Activity Logs",
+ "category": "cloud",
+ "description": "Azure subscription Activity Log \u2014 every control-plane operation (resource CRUD, RBAC changes, policy changes). Requires Reader role on the subscription.",
+ "fields": [
+ {
+ "name": "tenant_id",
+ "type": "string",
+ "label": "Tenant ID",
+ "required": true
+ },
+ {
+ "name": "client_id",
+ "type": "string",
+ "label": "Application (Client) ID",
+ "required": true
+ },
+ {
+ "name": "client_secret",
+ "type": "secret",
+ "label": "Client Secret",
+ "required": true
+ },
+ {
+ "name": "subscription_id",
+ "type": "string",
+ "label": "Subscription ID",
+ "required": true,
+ "placeholder": "00000000-0000-0000-0000-000000000000"
+ }
+ ],
+ "docs_url": "/docs/connectors/azure-activity",
+ "oauth": {
+ "supported_in_hosted": true,
+ "authorize_url": "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
+ "token_url": "https://login.microsoftonline.com/common/oauth2/v2.0/token",
+ "scopes": [
+ "https://management.azure.com/user_impersonation"
+ ]
+ }
+ },
+ {
+ "connector_id": "azure_defender",
+ "connector_name": "Microsoft Defender",
+ "category": "edr",
+ "description": "Microsoft 365 Defender unified alerts feed (Defender for Cloud, Endpoint, Identity, Office 365, Cloud Apps) via Microsoft Graph. Requires SecurityAlert.Read.All.",
+ "fields": [
+ {
+ "name": "tenant_id",
+ "type": "string",
+ "label": "Tenant ID",
+ "required": true
+ },
+ {
+ "name": "client_id",
+ "type": "string",
+ "label": "Application (Client) ID",
+ "required": true
+ },
+ {
+ "name": "client_secret",
+ "type": "secret",
+ "label": "Client Secret",
+ "required": true
+ }
+ ],
+ "docs_url": "/docs/connectors/azure-defender",
+ "oauth": {
+ "supported_in_hosted": true,
+ "authorize_url": "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
+ "token_url": "https://login.microsoftonline.com/common/oauth2/v2.0/token",
+ "scopes": [
+ "https://graph.microsoft.com/SecurityAlert.Read.All"
+ ]
+ }
+ },
+ {
+ "connector_id": "azure_entra",
+ "connector_name": "Microsoft Entra ID",
+ "category": "iam",
+ "description": "Microsoft Entra ID (Azure AD) directory audits and risky sign-ins via Microsoft Graph. Requires AuditLog.Read.All and Directory.Read.All application permissions.",
+ "fields": [
+ {
+ "name": "tenant_id",
+ "type": "string",
+ "label": "Tenant ID",
+ "required": true,
+ "placeholder": "00000000-0000-0000-0000-000000000000"
+ },
+ {
+ "name": "client_id",
+ "type": "string",
+ "label": "Application (Client) ID",
+ "required": true
+ },
+ {
+ "name": "client_secret",
+ "type": "secret",
+ "label": "Client Secret",
+ "required": true
+ }
+ ],
+ "docs_url": "/docs/connectors/azure-entra",
+ "oauth": {
+ "supported_in_hosted": true,
+ "authorize_url": "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
+ "token_url": "https://login.microsoftonline.com/common/oauth2/v2.0/token",
+ "scopes": [
+ "https://graph.microsoft.com/AuditLog.Read.All",
+ "https://graph.microsoft.com/Directory.Read.All"
+ ]
+ }
+ },
+ {
+ "connector_id": "cloudflare",
+ "connector_name": "Cloudflare",
+ "category": "saas",
+ "description": "Cloudflare account audit logs (zone changes, API token grants, member adds, WAF/firewall edits) via the v4 API. Requires an API token scoped to Account: Audit Logs: Read.",
+ "fields": [
+ {
+ "name": "account_id",
+ "type": "string",
+ "label": "Account ID",
+ "required": true,
+ "placeholder": "abc123def456...",
+ "help_text": "Found in the Cloudflare dashboard under any zone's Overview, lower-right pane (\"Account ID\")."
+ },
+ {
+ "name": "api_token",
+ "type": "secret",
+ "label": "API Token",
+ "required": true,
+ "help_text": "Account-scoped API token with the Audit Logs: Read permission. Avoid using the legacy Global API Key."
+ }
+ ],
+ "docs_url": "/docs/connectors/cloudflare",
+ "oauth": {
+ "supported_in_hosted": false
+ }
+ },
+ {
+ "connector_id": "cortex_xdr",
+ "connector_name": "Cortex XDR",
+ "category": "edr",
+ "description": "Palo Alto Cortex XDR incidents via the public REST API.",
+ "fields": [
+ {
+ "name": "api_key_id",
+ "type": "string",
+ "label": "API Key ID",
+ "required": true
+ },
+ {
+ "name": "api_key",
+ "type": "secret",
+ "label": "API Key",
+ "required": true
+ },
+ {
+ "name": "fqdn",
+ "type": "string",
+ "label": "FQDN",
+ "required": true,
+ "placeholder": "api-example.xdr.us.paloaltonetworks.com",
+ "help_text": "Fully qualified domain name of your Cortex XDR tenant."
+ }
+ ],
+ "docs_url": "/docs/connectors/cortex-xdr"
+ },
+ {
+ "connector_id": "crowdstrike",
+ "connector_name": "CrowdStrike Falcon",
+ "category": "edr",
+ "description": "CrowdStrike Falcon detections via the Falcon REST API.",
+ "fields": [
+ {
+ "name": "client_id",
+ "type": "string",
+ "label": "Client ID",
+ "required": true
+ },
+ {
+ "name": "client_secret",
+ "type": "secret",
+ "label": "Client Secret",
+ "required": true
+ },
+ {
+ "name": "base_url",
+ "type": "string",
+ "label": "Base URL",
+ "required": false,
+ "default": "https://api.crowdstrike.com",
+ "help_text": "Override only if your tenant lives in a non-US cloud (e.g. api.eu-1.crowdstrike.com)."
+ }
+ ],
+ "docs_url": "/docs/connectors/crowdstrike"
+ },
+ {
+ "connector_id": "duo_security",
+ "connector_name": "Duo Security",
+ "category": "iam",
+ "description": "Duo Security authentication logs via the Admin API (HMAC-SHA1 signed).",
+ "fields": [
+ {
+ "name": "integration_key",
+ "type": "string",
+ "label": "Integration Key",
+ "required": true
+ },
+ {
+ "name": "secret_key",
+ "type": "secret",
+ "label": "Secret Key",
+ "required": true
+ },
+ {
+ "name": "api_hostname",
+ "type": "string",
+ "label": "API Hostname",
+ "required": true,
+ "placeholder": "api-XXXXXXXX.duosecurity.com"
+ }
+ ],
+ "docs_url": "/docs/connectors/duo-security"
+ },
+ {
+ "connector_id": "elastic",
+ "connector_name": "Elastic SIEM",
+ "category": "siem",
+ "description": "Elastic Security via the ES|QL search API. Federated-search ready.",
+ "fields": [
+ {
+ "name": "base_url",
+ "type": "string",
+ "label": "Elasticsearch URL",
+ "required": true,
+ "placeholder": "https://elastic.example.com:9200",
+ "help_text": "Cluster endpoint, not Kibana."
+ },
+ {
+ "name": "api_key",
+ "type": "secret",
+ "label": "API Key",
+ "required": false
+ },
+ {
+ "name": "username",
+ "type": "string",
+ "label": "Username",
+ "required": false
+ },
+ {
+ "name": "password",
+ "type": "secret",
+ "label": "Password",
+ "required": false
+ },
+ {
+ "name": "index",
+ "type": "string",
+ "label": "Default Index Pattern",
+ "required": false,
+ "default": "logs-*"
+ },
+ {
+ "name": "ssl_verify",
+ "type": "boolean",
+ "label": "Verify SSL certificate",
+ "required": false,
+ "default": true,
+ "help_text": "Disable only for self-signed certificates in private deployments."
+ }
+ ],
+ "docs_url": "/docs/connectors/elastic"
+ },
+ {
+ "connector_id": "gcp_cloud_audit",
+ "connector_name": "GCP Cloud Audit Logs",
+ "category": "cloud",
+ "description": "Google Cloud Audit Logs (Admin Activity, Data Access, System Event) via Cloud Logging. Requires a service account with roles/logging.viewer (and roles/logging.privateLogViewer for Data Access logs).",
+ "fields": [
+ {
+ "name": "project_id",
+ "type": "string",
+ "label": "Project ID",
+ "required": true,
+ "placeholder": "my-prod-project",
+ "help_text": "The GCP project to read audit logs from. Use a log-sink aggregator project if you've consolidated."
+ },
+ {
+ "name": "service_account_json",
+ "type": "secret",
+ "label": "Service account JSON key",
+ "required": true,
+ "help_text": "Paste the full JSON key file. It will be encrypted at rest by the credential vault."
+ }
+ ],
+ "docs_url": "/docs/connectors/gcp-cloud-audit",
+ "oauth": {
+ "supported_in_hosted": false,
+ "token_url": "https://oauth2.googleapis.com/token",
+ "scopes": [
+ "https://www.googleapis.com/auth/logging.read"
+ ]
+ }
+ },
+ {
+ "connector_id": "gcp_scc",
+ "connector_name": "GCP Security Command Center",
+ "category": "cloud",
+ "description": "Google Cloud Security Command Center findings. Requires a service account with roles/securitycenter.findingsViewer at the organization or folder level.",
+ "fields": [
+ {
+ "name": "organization_id",
+ "type": "string",
+ "label": "Organization ID",
+ "required": true,
+ "placeholder": "1234567890",
+ "help_text": "Numeric GCP organization ID. SCC is org-scoped; the service account must have findingsViewer at this level (or on a parent folder/source)."
+ },
+ {
+ "name": "service_account_json",
+ "type": "secret",
+ "label": "Service account JSON key",
+ "required": true,
+ "help_text": "Paste the full JSON key file. It will be encrypted at rest by the credential vault."
+ }
+ ],
+ "docs_url": "/docs/connectors/gcp-scc",
+ "oauth": {
+ "supported_in_hosted": false,
+ "token_url": "https://oauth2.googleapis.com/token",
+ "scopes": [
+ "https://www.googleapis.com/auth/cloud-platform"
+ ]
+ }
+ },
+ {
+ "connector_id": "github",
+ "connector_name": "GitHub",
+ "category": "vcs",
+ "description": "GitHub organization audit log and Code Scanning alerts. Requires a token with read:audit_log and security_events scopes (fine-grained PAT or GitHub App installation token).",
+ "fields": [
+ {
+ "name": "organization",
+ "type": "string",
+ "label": "Organization slug",
+ "required": true,
+ "placeholder": "my-org"
+ },
+ {
+ "name": "token",
+ "type": "secret",
+ "label": "Personal Access Token or App Installation Token",
+ "required": true,
+ "help_text": "Fine-grained PAT recommended. Required scopes: read:audit_log, security_events. For GitHub App auth, paste a fresh installation token."
+ }
+ ],
+ "docs_url": "/docs/connectors/github",
+ "oauth": {
+ "supported_in_hosted": false,
+ "authorize_url": "https://github.com/login/oauth/authorize",
+ "token_url": "https://github.com/login/oauth/access_token",
+ "scopes": [
+ "read:audit_log",
+ "security_events"
+ ]
+ }
+ },
+ {
+ "connector_id": "google_workspace",
+ "connector_name": "Google Workspace",
+ "category": "saas",
+ "description": "Google Workspace audit logs (login, admin, drive, token, mobile) via the Admin SDK Reports API. Requires a service account with domain-wide delegation and an admin email to impersonate.",
+ "fields": [
+ {
+ "name": "admin_email",
+ "type": "string",
+ "label": "Super-admin email",
+ "required": true,
+ "placeholder": "[email protected]",
+ "help_text": "The Google Workspace super-admin to impersonate via domain-wide delegation. The service account's client_id must be authorized in the Admin Console with the admin.reports.audit.readonly scope."
+ },
+ {
+ "name": "service_account_json",
+ "type": "secret",
+ "label": "Service account JSON key",
+ "required": true,
+ "help_text": "Paste the full JSON key file. Encrypted at rest by the credential vault."
+ }
+ ],
+ "docs_url": "/docs/connectors/google-workspace",
+ "oauth": {
+ "supported_in_hosted": false,
+ "token_url": "https://oauth2.googleapis.com/token",
+ "scopes": [
+ "https://www.googleapis.com/auth/admin.reports.audit.readonly"
+ ]
+ }
+ },
+ {
+ "connector_id": "jira",
+ "connector_name": "Jira",
+ "category": "saas",
+ "description": "Jira Cloud issues via the REST API v3.",
+ "fields": [
+ {
+ "name": "base_url",
+ "type": "string",
+ "label": "Jira Base URL",
+ "required": true,
+ "placeholder": "https://yourorg.atlassian.net"
+ },
+ {
+ "name": "email",
+ "type": "string",
+ "label": "Email",
+ "required": true
+ },
+ {
+ "name": "api_token",
+ "type": "secret",
+ "label": "API Token",
+ "required": true
+ }
+ ],
+ "docs_url": "/docs/connectors/jira"
+ },
+ {
+ "connector_id": "m365_audit",
+ "connector_name": "Microsoft 365 Audit",
+ "category": "saas",
+ "description": "Microsoft 365 unified audit log (Azure AD, Exchange, SharePoint/OneDrive, Teams, Power BI) via the Office 365 Management Activity API. Requires ActivityFeed.Read on an Azure AD app registration.",
+ "fields": [
+ {
+ "name": "tenant_id",
+ "type": "string",
+ "label": "Tenant ID",
+ "required": true,
+ "placeholder": "00000000-0000-0000-0000-000000000000"
+ },
+ {
+ "name": "client_id",
+ "type": "string",
+ "label": "Application (Client) ID",
+ "required": true
+ },
+ {
+ "name": "client_secret",
+ "type": "secret",
+ "label": "Client Secret",
+ "required": true
+ }
+ ],
+ "docs_url": "/docs/connectors/m365-audit",
+ "oauth": {
+ "supported_in_hosted": true,
+ "authorize_url": "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
+ "token_url": "https://login.microsoftonline.com/common/oauth2/v2.0/token",
+ "scopes": [
+ "https://manage.office.com/ActivityFeed.Read"
+ ]
+ }
+ },
+ {
+ "connector_id": "microsoft_sentinel",
+ "connector_name": "Microsoft Sentinel",
+ "category": "siem",
+ "description": "Microsoft Sentinel incidents via the Azure Security Insights REST API.",
+ "fields": [
+ {
+ "name": "tenant_id",
+ "type": "string",
+ "label": "Tenant ID",
+ "required": true
+ },
+ {
+ "name": "client_id",
+ "type": "string",
+ "label": "Client ID",
+ "required": true
+ },
+ {
+ "name": "client_secret",
+ "type": "secret",
+ "label": "Client Secret",
+ "required": true
+ },
+ {
+ "name": "subscription_id",
+ "type": "string",
+ "label": "Subscription ID",
+ "required": true
+ },
+ {
+ "name": "resource_group",
+ "type": "string",
+ "label": "Resource Group",
+ "required": true
+ },
+ {
+ "name": "workspace",
+ "type": "string",
+ "label": "Workspace Name",
+ "required": true
+ }
+ ],
+ "docs_url": "/docs/connectors/microsoft-sentinel"
+ },
+ {
+ "connector_id": "okta",
+ "connector_name": "Okta Identity",
+ "category": "iam",
+ "description": "Okta system log events (auth, MFA, account locks, blocked requests).",
+ "fields": [
+ {
+ "name": "domain",
+ "type": "string",
+ "label": "Okta Domain",
+ "required": true,
+ "placeholder": "https://yourorg.okta.com"
+ },
+ {
+ "name": "api_token",
+ "type": "secret",
+ "label": "API Token",
+ "required": true
+ }
+ ],
+ "docs_url": "/docs/connectors/okta"
+ },
+ {
+ "connector_id": "onepassword",
+ "connector_name": "1Password Events",
+ "category": "iam",
+ "description": "1Password sign-in attempts via the Events Reporting API.",
+ "fields": [
+ {
+ "name": "api_token",
+ "type": "secret",
+ "label": "API Token (Bearer)",
+ "required": true
+ },
+ {
+ "name": "base_url",
+ "type": "string",
+ "label": "Events API Base URL",
+ "required": false,
+ "default": "https://events.1password.com",
+ "help_text": "Override only for 1Password Business accounts on a non-default region."
+ }
+ ],
+ "docs_url": "/docs/connectors/onepassword"
+ },
+ {
+ "connector_id": "proofpoint",
+ "connector_name": "Proofpoint TAP",
+ "category": "saas",
+ "description": "Proofpoint Targeted Attack Protection \u2014 blocked messages via the SIEM API.",
+ "fields": [
+ {
+ "name": "service_principal",
+ "type": "string",
+ "label": "Service Principal",
+ "required": true
+ },
+ {
+ "name": "service_secret",
+ "type": "secret",
+ "label": "Service Secret",
+ "required": true
+ }
+ ],
+ "docs_url": "/docs/connectors/proofpoint"
+ },
+ {
+ "connector_id": "sentinelone",
+ "connector_name": "SentinelOne",
+ "category": "edr",
+ "description": "SentinelOne threat detections via the Management Console API.",
+ "fields": [
+ {
+ "name": "api_token",
+ "type": "secret",
+ "label": "API Token",
+ "required": true
+ },
+ {
+ "name": "base_url",
+ "type": "string",
+ "label": "Base URL",
+ "required": true,
+ "placeholder": "https://usea1-partners.sentinelone.net"
+ },
+ {
+ "name": "site_id",
+ "type": "string",
+ "label": "Site ID",
+ "required": false,
+ "help_text": "Optional. Limits results to a single site."
+ }
+ ],
+ "docs_url": "/docs/connectors/sentinelone"
+ },
+ {
+ "connector_id": "servicenow",
+ "connector_name": "ServiceNow",
+ "category": "saas",
+ "description": "ServiceNow incidents via the Table API.",
+ "fields": [
+ {
+ "name": "instance_url",
+ "type": "string",
+ "label": "Instance URL",
+ "required": true,
+ "placeholder": "https://yourinstance.service-now.com"
+ },
+ {
+ "name": "username",
+ "type": "string",
+ "label": "Username",
+ "required": true
+ },
+ {
+ "name": "password",
+ "type": "secret",
+ "label": "Password",
+ "required": true
+ }
+ ],
+ "docs_url": "/docs/connectors/servicenow"
+ },
+ {
+ "connector_id": "snyk",
+ "connector_name": "Snyk",
+ "category": "vcs",
+ "description": "Snyk vulnerability issues via the REST API.",
+ "fields": [
+ {
+ "name": "api_token",
+ "type": "secret",
+ "label": "API Token",
+ "required": true
+ },
+ {
+ "name": "org_id",
+ "type": "string",
+ "label": "Organization ID",
+ "required": true,
+ "help_text": "Snyk organization UUID (Settings \u2192 General \u2192 Organization ID)."
+ },
+ {
+ "name": "base_url",
+ "type": "string",
+ "label": "Base URL",
+ "required": false,
+ "default": "https://api.snyk.io",
+ "help_text": "Override for Snyk Enterprise on-prem or EU tenants."
+ }
+ ],
+ "docs_url": "/docs/connectors/snyk"
+ },
+ {
+ "connector_id": "splunk",
+ "connector_name": "Splunk SIEM",
+ "category": "siem",
+ "description": "Splunk Enterprise / Cloud notable events via the REST API.",
+ "fields": [
+ {
+ "name": "base_url",
+ "type": "string",
+ "label": "Splunk URL",
+ "required": true,
+ "placeholder": "https://splunk.example.com:8089",
+ "help_text": "Management port (default 8089), not the web UI port."
+ },
+ {
+ "name": "token",
+ "type": "secret",
+ "label": "HEC / API Token",
+ "required": true
+ },
+ {
+ "name": "saved_search",
+ "type": "string",
+ "label": "Saved Search Name",
+ "required": false,
+ "default": "AiSOC_Alerts"
+ },
+ {
+ "name": "ssl_verify",
+ "type": "boolean",
+ "label": "Verify SSL certificate",
+ "required": false,
+ "default": true,
+ "help_text": "Disable only for self-signed certificates in private deployments."
+ }
+ ],
+ "docs_url": "/docs/connectors/splunk"
+ },
+ {
+ "connector_id": "tailscale",
+ "connector_name": "Tailscale",
+ "category": "network",
+ "description": "Tailscale zero-trust network audit logs. Captures every ACL change, device approval / removal, key rotation, user role change, and admin configuration mutation in your tailnet.",
+ "fields": [
+ {
+ "name": "tailnet",
+ "type": "string",
+ "label": "Tailnet",
+ "required": true,
+ "placeholder": "example.com or -",
+ "help_text": "Your tailnet name (the organisation slug shown in the Tailscale admin console, e.g. 'example.com'). Use '-' to use the default tailnet associated with the API key / OAuth token."
+ },
+ {
+ "name": "api_key",
+ "type": "secret",
+ "label": "API Key (optional if using OAuth)",
+ "required": false,
+ "help_text": "Tailscale API key (starts with 'tskey-api-'). Use either this *or* the OAuth client credentials below \u2014 not both."
+ },
+ {
+ "name": "client_id",
+ "type": "string",
+ "label": "OAuth Client ID (optional)",
+ "required": false,
+ "help_text": "OAuth 2.0 client ID from the Tailscale admin console. Required scope: 'audit:read'."
+ },
+ {
+ "name": "client_secret",
+ "type": "secret",
+ "label": "OAuth Client Secret (optional)",
+ "required": false,
+ "help_text": "OAuth 2.0 client secret. Only needed when using client-credential flow instead of an API key."
+ }
+ ],
+ "docs_url": "/docs/connectors/tailscale",
+ "oauth": {
+ "supported_in_hosted": false,
+ "authorize_url": "https://login.tailscale.com/admin/settings/oauth",
+ "token_url": "https://api.tailscale.com/api/v2/oauth/token",
+ "scopes": [
+ "audit:read"
+ ]
+ }
+ },
+ {
+ "connector_id": "wiz",
+ "connector_name": "Wiz",
+ "category": "cloud",
+ "description": "Wiz cloud security issues via the GraphQL API.",
+ "fields": [
+ {
+ "name": "client_id",
+ "type": "string",
+ "label": "Client ID",
+ "required": true
+ },
+ {
+ "name": "client_secret",
+ "type": "secret",
+ "label": "Client Secret",
+ "required": true
+ },
+ {
+ "name": "api_endpoint_url",
+ "type": "string",
+ "label": "API Endpoint URL",
+ "required": true,
+ "placeholder": "https://api.us20.app.wiz.io/graphql",
+ "help_text": "Your tenant's GraphQL API endpoint."
+ },
+ {
+ "name": "auth_url",
+ "type": "string",
+ "label": "Auth URL",
+ "required": false,
+ "default": "https://auth.app.wiz.io/oauth/token",
+ "help_text": "OAuth2 token endpoint. Override only for gov-cloud tenants."
+ }
+ ],
+ "docs_url": "/docs/connectors/wiz"
+ },
+ {
+ "connector_id": "zscaler",
+ "connector_name": "Zscaler Internet Access",
+ "category": "network",
+ "description": "Zscaler Internet Access web security logs via the ZIA API.",
+ "fields": [
+ {
+ "name": "api_key",
+ "type": "secret",
+ "label": "API Key",
+ "required": true
+ },
+ {
+ "name": "cloud",
+ "type": "string",
+ "label": "ZIA Cloud",
+ "required": false,
+ "default": "zscloud.net",
+ "help_text": "ZIA cloud domain (e.g. zscloud.net, zscaler.net)."
+ },
+ {
+ "name": "username",
+ "type": "string",
+ "label": "Admin Username",
+ "required": true
+ },
+ {
+ "name": "password",
+ "type": "secret",
+ "label": "Admin Password",
+ "required": true
+ }
+ ],
+ "docs_url": "/docs/connectors/zscaler"
+ }
+]
\ No newline at end of file
diff --git a/services/api/app/scripts/seed_demo.py b/services/api/app/scripts/seed_demo.py
index 9ce00b0c9..b4e2803eb 100644
--- a/services/api/app/scripts/seed_demo.py
+++ b/services/api/app/scripts/seed_demo.py
@@ -319,9 +319,11 @@ def _make_case(tenant_id: uuid.UUID, idx: int, when: datetime, alert_ids: list[u
weights=[30, 35, 10, 15, 10],
)[0]
techniques = _pick_techniques(2)
+ # Human-readable identifier — keep in sync with the demo deeplinks the
+ # marketing site and product walkthroughs use (e.g. /cases/INC-001).
return Case(
tenant_id=tenant_id,
- case_number=f"CASE-{1000 + idx:04d}",
+ case_number=f"INC-{idx + 1:03d}",
title=_rng.choice(
[
"Coordinated brute-force campaign across SaaS apps",
@@ -597,6 +599,7 @@ async def _mirror_cases_to_aisoc(session, tenant: Tenant) -> int:
params = {
"id": str(c.id),
"tenant_id": str(c.tenant_id),
+ "case_number": c.case_number,
"title": c.title,
"description": c.description or c.summary or "",
"severity": _AISOC_SEVERITY_MAP.get(c.severity, "medium"),
@@ -616,12 +619,13 @@ async def _mirror_cases_to_aisoc(session, tenant: Tenant) -> int:
text(
"""
INSERT INTO aisoc_cases (
- id, tenant_id, title, description, severity, status,
+ id, tenant_id, case_number,
+ title, description, severity, status,
assignee, mitre_techniques, alert_ids,
opened_at, resolved_at, closed_at,
created_at, updated_at, created_by, tags
) VALUES (
- CAST(:id AS UUID), CAST(:tenant_id AS UUID),
+ CAST(:id AS UUID), CAST(:tenant_id AS UUID), :case_number,
:title, :description, :severity, :status,
:assignee, CAST(:mitre_techniques AS JSONB),
CAST(:alert_ids AS UUID[]),
@@ -629,7 +633,7 @@ async def _mirror_cases_to_aisoc(session, tenant: Tenant) -> int:
:created_at, :updated_at, :created_by,
CAST(:tags AS JSONB)
)
- ON CONFLICT (id) DO NOTHING
+ ON CONFLICT (id) DO UPDATE SET case_number = EXCLUDED.case_number
"""
).bindparams(**params)
)
diff --git a/services/api/migrations/028_aisoc_cases_case_number.sql b/services/api/migrations/028_aisoc_cases_case_number.sql
new file mode 100644
index 000000000..f16993d11
--- /dev/null
+++ b/services/api/migrations/028_aisoc_cases_case_number.sql
@@ -0,0 +1,21 @@
+-- Migration 028: Human-readable case identifiers on aisoc_cases
+--
+-- The web console (and a number of demo deeplinks like /cases/INC-001) needs to
+-- look up a case by a stable, short, human-readable identifier — not a UUID.
+-- The ORM `cases` table already has a `case_number` column (e.g. CASE-1042),
+-- but the canonical demo table `aisoc_cases` does not. Adding it here lets
+-- the API resolve `/api/v1/cases/INC-001` against `case_number` while still
+-- accepting raw UUIDs, without breaking any existing rows.
+
+ALTER TABLE aisoc_cases
+ ADD COLUMN IF NOT EXISTS case_number TEXT;
+
+-- Backfill any pre-existing rows so the column is never NULL going forward.
+-- Use the row's own UUID prefix as a fallback so we don't violate UNIQUE.
+UPDATE aisoc_cases
+SET case_number = 'CASE-' || substr(id::text, 1, 8)
+WHERE case_number IS NULL;
+
+-- Now enforce uniqueness + an index for fast lookup by external id.
+CREATE UNIQUE INDEX IF NOT EXISTS idx_aisoc_cases_case_number
+ ON aisoc_cases (case_number);