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.

docs(demo): align WS-A3 demo lifecycle docs + deeplink with seed_demo.py

beenu9eab7ed635cd
diff --git a/README.md b/README.md
index 0046a719a..7d8bb295a 100644
--- a/README.md
+++ b/README.md
@@ -377,7 +377,7 @@ The marketing landing lives at `/` and the console at `/dashboard`. Both share t
### One-shot demo
-To see AiSOC investigate a seeded case in your browser:
+To see AiSOC investigate an in-flight ransomware case in your browser:
```bash
git clone https://github.com/beenuar/AiSOC.git
@@ -385,19 +385,36 @@ cd AiSOC
pnpm aisoc:demo
```
-That command pulls prebuilt images from `ghcr.io/beenuar/*`, brings up the slim demo profile (postgres, redis, kafka, api, agents, realtime, web), seeds canonical demo data, runs an AI investigation against a seeded case, and opens your browser at `/cases/<uuid>`.
+That single command:
-Approximate timings on a warm Docker daemon:
+1. Pulls prebuilt images from `ghcr.io/beenuar/*` (api, agents, web, realtime).
+2. Brings up the slim demo profile — Postgres, Redis, Kafka, api, agents, realtime, web.
+3. Runs the canonical-data seeder (`services/api/app/scripts/seed_demo.py`) as a one-shot container that exits when finished. The seeder is idempotent: re-running it is a no-op against an already-seeded volume.
+4. Locates `INC-RT-001` — a LockBit 3.0 ransomware investigation that's mid-stream when you arrive (encryption is in progress, the agent is streaming decisions to the Investigation Ledger, an auto-isolation playbook is mid-DAG).
+5. Opens your browser directly at `/cases/INC-RT-001?tab=ledger`, with the demo analyst (`[email protected]`) already auto-logged-in.
+
+Target on a clean Mac with a warm Docker daemon: **clone-to-investigation in under 5 minutes**.
| Step | Time |
|---|---|
-| `docker compose pull` | ~90s |
+| `docker compose pull` (cold) | ~90s |
| `docker compose up` + healthchecks | ~60s |
-| Seed canonical data | ~30s |
-| Kick off investigation | ~30s |
-| Total | ~3.5 min |
+| Seed canonical data (one-shot container) | ~30s |
+| Kick off live investigation step | ~30s |
+| Total | ~3.5 min warm / ~5 min cold |
+
+What you'll see when the browser opens:
+
+- **Investigation Ledger** — the agent's per-step prompt, response, evidence cited, and tool calls for `INC-RT-001`, replayable from any step.
+- **Decision graph** — Cytoscape view of the LangGraph traversal that produced the verdict.
+- **Playbook timeline** — the in-flight ransomware containment DAG, with completed and pending steps.
+- **15 other seeded cases** — phishing, credential access, lateral movement, exfiltration, cloud takeover — across `INC-PH-*`, `INC-CR-*`, `INC-LM-*`, `INC-EX-*`, `INC-CL-*` series, all with populated alerts, IOCs, and ledger artifacts.
+
+When you're done: `pnpm aisoc:demo:down` (stops containers and deletes the demo volumes).
+
+#### Hosted, public-internet equivalent
-When you're done: `pnpm aisoc:demo:down` (deletes the demo volumes).
+The same stack ships a Cloudflare Tunnel template (see [Public demo on your own domain](#public-demo-on-your-own-domain)) and tested deployment configs for [Render](infra/render/render.yaml) and [Fly.io](infra/fly/) — both wire `alembic upgrade head && python -m app.scripts.seed_demo` into the deploy lifecycle so the same `INC-RT-001` showcase is present after `render blueprint launch` or `fly deploy`.
The full development quick start with all services (UEBA, Honeytokens, Purple Team, ClickHouse, OpenSearch, Neo4j, Qdrant) is below.
diff --git a/infra/fly/README.md b/infra/fly/README.md
index de36b0b46..1e17cbd6c 100644
--- a/infra/fly/README.md
+++ b/infra/fly/README.md
@@ -63,9 +63,10 @@ this stack is engineered for.
│ aisoc-demo-seed-cron (scheduled machine) │ no public traffic
│ Lives on the aisoc-demo-api app, runs │
│ daily at 00:00 UTC using the api image: │
- │ 1. wipe demo tenant │
- │ 2. seed canonical alerts/cases │
- │ 3. POST /investigate INC-001 │
+ │ 1. python -m app.scripts.seed_demo │
+ │ 2. seeder is idempotent — refreshes │
+ │ INC-RT-001 + 14 other canonical cases │
+ │ 3. visitors get a hot demo at all times │
└──────────────────────────────────────────────┘
```
@@ -95,39 +96,49 @@ infra/fly/
```
The seeder is **not** a separate app. It ships inside the api image as
-`python -m app.scripts.demo_seed`, which lets us run it two ways without
+`python -m app.scripts.seed_demo`, which lets us run it three ways without
maintaining a fifth Dockerfile or Fly app:
| When | How |
|--------------------------|--------------------------------------------------------------------------------------|
-| Post-deploy (bootstrap) | `flyctl ssh console -a aisoc-demo-api -C "python -m app.scripts.demo_seed --reset --kickoff-investigation"` runs once on a live api machine, populating Postgres and starting the canonical investigation in ~30s. |
+| Every deploy | `[deploy].release_command` in `infra/fly/api/fly.toml` runs `alembic upgrade head && python -m app.scripts.seed_demo` on every `flyctl deploy`. Idempotent — a no-op against an already-seeded volume. |
+| Post-deploy (bootstrap) | `flyctl ssh console -a aisoc-demo-api -C "python -m app.scripts.seed_demo"` runs once on a live api machine. Belt-and-suspenders for first-time deploys. |
| Daily refresh (00:00 UTC)| A scheduled Fly machine on the `aisoc-demo-api` app, named `aisoc-demo-seed-cron`, boots from the same api image, runs the same command, and exits. |
-| Local recovery | `python scripts/demo_seed.py --reset` from the repo root — the shim re-execs the canonical module against your `docker-compose` stack. |
+| Local recovery | `python -m app.scripts.seed_demo` inside the api container of a `docker-compose -f docker-compose.demo.yml` stack — same module, same idempotency. |
The canonical implementation lives in
-[`services/api/app/scripts/demo_seed.py`](../../services/api/app/scripts/demo_seed.py);
-[`scripts/demo_seed.py`](../../scripts/demo_seed.py) is a thin shim for repo-root invocation.
+[`services/api/app/scripts/seed_demo.py`](../../services/api/app/scripts/seed_demo.py).
+The seeder mints 15 incidents (ransomware/phishing/credential-access/lateral/
+exfil/cloud) plus the in-flight `INC-RT-001` LockBit 3.0 investigation that
+the onboarding deeplink targets.
The seed flow is the secret sauce for the TTFI budget:
```
-00:00 UTC ┌────────────────────────────────────────────────────┐
- │ 1. scheduled machine boots from api image │
- │ 2. runs `python -m app.scripts.demo_seed --reset │
- │ --kickoff-investigation` │
- │ 3. POSTs /api/v1/cases/INC-001/investigate │
- │ 4. agents.internal streams events → realtime │
- │ 5. realtime broadcasts → web WS connections │
- │ Investigation completes within 30-90s. │
- └────────────────────────────────────────────────────┘
-
-T+anytime ┌────────────────────────────────────────────────────┐
- │ Visitor lands at /cases/INC-001?tab=ledger │
- │ - case is already CREATED │
- │ - investigation_run is COMPLETED or RUNNING │
- │ - ledger has 20-50 events ready to stream │
- │ Time-to-first-investigation: 0s (already running). │
- └────────────────────────────────────────────────────┘
+On every deploy ┌────────────────────────────────────────────────────┐
+ │ 1. flyctl deploy ships api/agents/realtime/web │
+ │ 2. release_command runs alembic + seed_demo │
+ │ 3. Postgres now contains INC-RT-001 + 14 others │
+ │ 4. Visitors land at /cases/INC-RT-001?tab=ledger │
+ │ with the agent already mid-stream. │
+ └────────────────────────────────────────────────────┘
+
+00:00 UTC daily ┌────────────────────────────────────────────────────┐
+ │ 1. scheduled machine boots from api image │
+ │ 2. runs `python -m app.scripts.seed_demo` │
+ │ 3. Refreshes the showcase case for the next 24h │
+ │ of visitors. All writes happen under the demo │
+ │ tenant's RLS scope. │
+ └────────────────────────────────────────────────────┘
+
+T+anytime ┌────────────────────────────────────────────────────┐
+ │ Visitor lands at /cases/INC-RT-001?tab=ledger │
+ │ - case is already CREATED │
+ │ - investigation_run is RUNNING or COMPLETED │
+ │ - ledger has 20-50 events ready to stream │
+ │ - playbook DAG mid-execution │
+ │ Time-to-first-investigation: 0s (already running). │
+ └────────────────────────────────────────────────────┘
```
## First-time setup
@@ -179,7 +190,7 @@ flag drives two pieces of behavior:
1. **API middleware (`services/api/app/middleware/demo_mode.py`)**
Returns 403 for non-allowlisted writes (POST/PUT/PATCH/DELETE) and stamps
`X-AiSOC-Demo: true` plus `X-AiSOC-Demo-Banner` headers on every response.
- Allowlisted writes: auth flows, `/cases/INC-001/investigate`, alert ack.
+ Allowlisted writes: auth flows, `/cases/INC-RT-001/investigate`, alert ack.
2. **Web banner (`apps/web/src/components/demo/DemoBanner.tsx`)**
Renders a fixed amber strip at the top of every authenticated page with
@@ -206,7 +217,7 @@ curl -si -X POST https://aisoc-demo-api.fly.dev/api/v1/cases | head -3
curl -sf https://api.tryaisoc.com/health
# Visitor flow
-open https://tryaisoc.com/cases/INC-001?tab=ledger
+open https://tryaisoc.com/cases/INC-RT-001?tab=ledger
```
## Troubleshooting
@@ -216,7 +227,7 @@ open https://tryaisoc.com/cases/INC-001?tab=ledger
| `flyctl deploy` hangs on builder | Nuke remote builder: `flyctl builders destroy` |
| API 503 on first hit | Cold start; `min_machines_running=1` should fix |
| Web shows "demo data resets" but writes work| API's `AISOC_DEMO_MODE` not set; redeploy api |
-| INC-001 case missing | Re-run seed: `flyctl ssh console -a aisoc-demo-api -C "python -m app.scripts.demo_seed --reset --kickoff-investigation"` |
+| `INC-RT-001` case missing | Re-run seed: `flyctl ssh console -a aisoc-demo-api -C "python -m app.scripts.seed_demo"` (idempotent) |
| Daily seed cron not firing | Verify the scheduled machine: `flyctl machine list -a aisoc-demo-api` (look for `aisoc-demo-seed-cron`) |
| WS disconnects in 30s | Realtime `auto_stop_machines = "off"` — verify fly.toml |
| Cert pending | `flyctl certs show tryaisoc.com --app aisoc-demo-web` (and same for `api.` / `ws.` subdomains) |
diff --git a/infra/fly/fly-demo-deploy.sh b/infra/fly/fly-demo-deploy.sh
index c72fd7ace..bf4a6ff31 100755
--- a/infra/fly/fly-demo-deploy.sh
+++ b/infra/fly/fly-demo-deploy.sh
@@ -145,10 +145,11 @@ fi
# 4. web last; serves traffic at tryaisoc.com
#
# The seeder is *not* a separate app it ships inside the api image as
-# `python -m app.scripts.demo_seed`, and we invoke it via `flyctl ssh
-# console` post-deploy + a scheduled machine on the api app for the daily
-# cron. This avoids a duplicate Dockerfile + the cost of a fifth Fly app
-# whose only job is to run a 30-second script.
+# `python -m app.scripts.seed_demo`, runs automatically on every deploy via
+# `[deploy].release_command` in api/fly.toml, and is also wired up post-deploy
+# (belt-and-suspenders for first-time deploys) plus on a daily scheduled
+# machine for the 00:00 UTC refresh. This avoids a duplicate Dockerfile +
+# the cost of a fifth Fly app whose only job is to run a 30-second script.
# deploy_app <fly-app-name> <fly.toml subdir under infra/fly/> <build-context dir>
#
@@ -297,8 +298,16 @@ ensure_cert ws.tryaisoc.com aisoc-demo-realtime
# - daily refresh (cron): a scheduled Fly machine on aisoc-demo-api
# boots from the same image, runs the seeder, exits.
#
-# Both paths execute `python -m app.scripts.demo_seed`; the canonical
-# implementation lives in services/api/app/scripts/demo_seed.py.
+# Both paths execute `python -m app.scripts.seed_demo`; the canonical
+# implementation lives in services/api/app/scripts/seed_demo.py and produces
+# the v1.0 canon (15 incidents including the in-flight INC-RT-001 LockBit
+# 3.0 case that the demo deeplink targets).
+#
+# Note: the api app's `[deploy].release_command` already runs
+# `alembic upgrade head && python -m app.scripts.seed_demo` on every
+# `flyctl deploy`, so the post-deploy ssh bootstrap below is a belt-and-
+# suspenders for first-time deploys. seed_demo.py is fully idempotent —
+# repeated runs against an already-seeded volume are a cheap no-op.
if ! $SKIP_SEED; then
log "running seed bootstrap inside aisoc-demo-api (one-shot via ssh)"
# `ssh console -C` runs a single command on a live machine and exits. We
@@ -307,7 +316,7 @@ if ! $SKIP_SEED; then
# reuse a fully-warm container instead of cold-booting another machine.
flyctl ssh console \
--app aisoc-demo-api \
- --command "python -m app.scripts.demo_seed --reset --kickoff-investigation" \
+ --command "python -m app.scripts.seed_demo" \
|| err "(seed bootstrap failed; demo will be cold until daily cron runs)"
log "ensuring daily seed cron at 00:00 UTC on aisoc-demo-api"
@@ -325,7 +334,7 @@ if ! $SKIP_SEED; then
--vm-size shared-cpu-1x \
--vm-memory 512 \
--name aisoc-demo-seed-cron \
- -- python -m app.scripts.demo_seed --reset --kickoff-investigation \
+ -- python -m app.scripts.seed_demo \
2>/dev/null || log "(daily seed cron already configured)"
fi
@@ -353,7 +362,7 @@ log ""
log "Smoke test:"
log " curl -sf https://aisoc-demo-api.fly.dev/health"
log " curl -sf https://api.tryaisoc.com/health # after DNS propagates"
-log " open https://tryaisoc.com/cases/INC-001?tab=ledger"
+log " open https://tryaisoc.com/cases/INC-RT-001?tab=ledger"
log ""
log "Cert status (run after DNS is live):"
log " flyctl certs show tryaisoc.com --app aisoc-demo-web"
diff --git a/scripts/aisoc-demo.ts b/scripts/aisoc-demo.ts
index 5c9ec4e97..0c044f69b 100644
--- a/scripts/aisoc-demo.ts
+++ b/scripts/aisoc-demo.ts
@@ -6,14 +6,19 @@
* 1. Verify Docker + docker compose are present
* 2. Pull prebuilt images from ghcr.io/beenuar/* (no local builds)
* 3. docker compose up -d using docker-compose.demo.yml (slim profile)
+ * — the `seed` service runs `python -m app.scripts.seed_demo` once
+ * automatically when the api is healthy, then exits cleanly.
* 4. Wait for postgres + api to be healthy
- * 5. Seed demo data via `python -m app.scripts.seed_demo`
- * 6. Query the API for a seeded case UUID (dev mode auth bypass)
+ * 5. Re-run the seeder as a safety net (idempotent inside seed_demo.py)
+ * 6. Query the API for the showcase ransomware case (INC-RT-001) with a
+ * fallback to the first available case if the showcase is missing
* 7. Kick off an investigation on that case
- * 8. Open the user's browser at /cases/<uuid>
+ * 8. Open the user's browser at /cases/INC-RT-001?tab=ledger
*
* On a warm Docker daemon the full path is roughly 3.5 minutes:
- * about 90s pull + 60s startup + 30s seed + 30s investigation.
+ * about 90s pull + 60s startup + 30s seed + 30s investigation. The
+ * v1.0 acceptance gate is clone-to-investigation in ≤ 5 minutes on a
+ * clean Mac with a cold Docker daemon.
*
* Usage: pnpm aisoc:demo
*
@@ -408,11 +413,31 @@ async function kickoffInvestigation(caseId: string): Promise<boolean> {
return false;
}
-async function openInBrowser(caseId: string | null, flags: Flags) {
- const url =
- caseId !== null
- ? `http://localhost:3000/cases/${caseId}`
- : "http://localhost:3000/cases";
+// Validates a case_number like "INC-RT-001" / "INC-001" before splicing it
+// into the URL. Defensive against arbitrary strings the API might return —
+// the cases endpoint has resolved arbitrary identifiers in the past.
+const CASE_NUMBER_RE = /^[A-Za-z0-9_-]{1,32}$/;
+function sanitizeCaseNumber(num: unknown): string | null {
+ if (typeof num === "string" && CASE_NUMBER_RE.test(num)) return num;
+ return null;
+}
+
+async function openInBrowser(
+ seeded: { id: string; case_number: string; title: string } | null,
+ flags: Flags,
+) {
+ // Prefer routing by human-readable case_number with the ledger tab
+ // pre-selected — that's the same URL the hosted demo uses and what
+ // NEXT_PUBLIC_DEMO_DEEPLINK points at, so docs/screenshots/local-demo
+ // all land in the same place. The Next.js [id] route resolves both
+ // case_number and UUID via the API's case_number_or_id lookup
+ // (services/api/app/api/v1/endpoints/cases.py).
+ const safeNumber = seeded ? sanitizeCaseNumber(seeded.case_number) : null;
+ const url = seeded
+ ? safeNumber
+ ? `http://localhost:3000/cases/${safeNumber}?tab=ledger`
+ : `http://localhost:3000/cases/${seeded.id}?tab=ledger`
+ : "http://localhost:3000/cases";
step(7, 7, `Opening browser at ${url}`);
if (flags.noOpen) {
log(c.dim("--no-open: not launching browser"));
@@ -459,7 +484,7 @@ async function main() {
if (seededCase) {
await kickoffInvestigation(seededCase.id);
}
- await openInBrowser(seededCase?.id ?? null, flags);
+ await openInBrowser(seededCase, flags);
process.exit(0);
}