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
"""
AiSOC Action Execution Service entry point.
Wires the legacy ``ActionType``-keyed router and the new ``(vendor_id,
capability)``-keyed live-actions router under ``/api/v1``. The two
layers coexist by design: the legacy router still backs the established
human-in-the-loop UI (approvals, blast-radius gates, ChatOps callbacks),
while the live-actions router exposes the generic interface that the
agent loop and plugin SDK consume.
Builtin executor adapters are registered at import time via FastAPI's
startup hook so they're available before the first request lands. We
use the startup hook (rather than module-level execution) so that test
fixtures can reset the registry between tests with
``app.live_actions.reset_for_tests()`` and re-trigger registration
without restarting the process.
"""
from __future__ import annotations
import os
import structlog
from fastapi import FastAPI
from app._health import install_health_routes, register_dependency
from app.api.live_actions_router import router as live_actions_router
from app.api.replay_history_router import router as replay_history_router
from app.api.router import router as legacy_router
from app.api.shadow_reconcile_router import router as shadow_reconcile_router
from app.live_actions import register_builtin_executors
logger = structlog.get_logger(__name__)
app = FastAPI(
title="AiSOC Action Execution Service",
description=(
"Blast-radius gated response action execution with human-in-the-loop "
"approvals (legacy router) and the generic (vendor_id, capability) "
"live-actions interface used by the agent loop and plugin SDK."
),
version="0.2.0",
)
# Phase 2.6 — k8s liveness + readiness probes (see app/_health.py).
# /readyz flips to 200 once the builtin executor registration is
# complete (in the startup hook below).
_mark_ready, _mark_not_ready = install_health_routes(app, service_name="aisoc-actions")
app.state.mark_ready = _mark_ready
app.state.mark_not_ready = _mark_not_ready
async def _database_ready() -> bool:
import asyncpg
dsn = (os.getenv("DATABASE_DSN") or os.getenv("DATABASE_URL") or "").strip()
if not dsn:
return False
for prefix in ("postgresql+asyncpg://", "postgres+asyncpg://"):
if dsn.startswith(prefix):
dsn = "postgresql://" + dsn[len(prefix) :]
break
conn = await asyncpg.connect(dsn, timeout=1.4)
await conn.close()
return True
register_dependency(app, "database", _database_ready)
app.include_router(legacy_router, prefix="/api/v1")
app.include_router(live_actions_router, prefix="/api/v1")
# Gap-closure Phase 1.4: the read half of the SIEM relationship. Phase 1.1 put
# five closed-finding readers on the clients here and nothing called them.
app.include_router(replay_history_router, prefix="/api/v1")
# Gap-closure Phase 2.1 (D15): the same five readers, driven on a schedule by
# the sweep in services/api, with the matcher that was previously a library
# nothing called.
app.include_router(shadow_reconcile_router, prefix="/api/v1")
@app.on_event("startup")
async def _register_builtin_live_actions() -> None:
"""Register in-tree adapters with the live-action registry on boot.
``overwrite=True`` so a hot-reload (uvicorn --reload) doesn't crash
on duplicate-registration errors. The registry's normal default of
``overwrite=False`` still protects plugins from clobbering each
other.
"""
count = register_builtin_executors(overwrite=True)
logger.info("live_actions.bootstrap_complete", builtin_count=count)
# Phase 2.6 — the registry is now populated, so flip /readyz on.
app.state.mark_ready()
@app.on_event("shutdown")
async def _drain_readyz() -> None:
"""Phase 2.6 — drain /readyz at the start of shutdown so the
orchestrator stops sending new requests while in-flight ones
finish.
"""
app.state.mark_not_ready()
@app.get("/health")
async def health() -> dict[str, str]:
return {"status": "healthy", "service": "aisoc-actions"}