Skip to content

armgit / AiSOC

Public Imported from GitHub
0

Open-source AI Security Operations Center: alert fusion, LLM-agent triage, MITRE ATT&CK investigation, and a replayable decision ledger for every agent step. Self-hostable, runs with no API keys, MIT licensed. Ships an MCP server for Claude, Cursor and Continue.

feat(demo): public-facing demo on tryaisoc.com via Cloudflare Tunnel

Beenu Arora4bf300803343
diff --git a/docker-compose.demo.yml b/docker-compose.demo.yml
index b4f292284..3ff3d9969 100644
--- a/docker-compose.demo.yml
+++ b/docker-compose.demo.yml
@@ -16,6 +16,15 @@
# Manual usage:
# docker compose -f docker-compose.demo.yml pull
# docker compose -f docker-compose.demo.yml up -d
+#
+# SECURITY NOTE
+# -------------
+# Host port publishings below are bound to 127.0.0.1 so the demo's
+# development passwords are not exposed on the LAN. The same passwords
+# ship with every clone of this repo. If you need to reach these from
+# another machine, write a docker-compose.override.yml that changes
+# the host binding for the specific service you're exposing — and
+# rotate the password while you're there.
###############################################################################
networks:
@@ -39,7 +48,7 @@ services:
POSTGRES_USER: aisoc
POSTGRES_PASSWORD: aisoc_dev_secret
ports:
- - "5432:5432"
+ - "127.0.0.1:5432:5432"
volumes:
- postgres_demo_data:/var/lib/postgresql/data
networks:
@@ -55,7 +64,7 @@ services:
container_name: aisoc-demo-redis
command: redis-server --appendonly yes --requirepass redis_dev_secret
ports:
- - "6379:6379"
+ - "127.0.0.1:6379:6379"
volumes:
- redis_demo_data:/data
networks:
@@ -87,7 +96,7 @@ services:
zookeeper:
condition: service_healthy
ports:
- - "9092:9092"
+ - "127.0.0.1:9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
@@ -121,7 +130,7 @@ services:
kafka:
condition: service_healthy
ports:
- - "8000:8000"
+ - "127.0.0.1:8000:8000"
environment:
DATABASE_URL: postgresql+asyncpg://aisoc:aisoc_dev_secret@postgres:5432/aisoc
REDIS_URL: redis://:redis_dev_secret@redis:6379/0
@@ -151,7 +160,7 @@ services:
redis:
condition: service_healthy
ports:
- - "8001:8084"
+ - "127.0.0.1:8001:8084"
environment:
DATABASE_URL: postgresql+asyncpg://aisoc:aisoc_dev_secret@postgres:5432/aisoc
REDIS_URL: redis://:redis_dev_secret@redis:6379/4
@@ -174,7 +183,7 @@ services:
kafka:
condition: service_healthy
ports:
- - "8086:4000"
+ - "127.0.0.1:8086:4000"
environment:
KAFKA_BOOTSTRAP_SERVERS: kafka:29092
REDIS_URL: redis://:redis_dev_secret@redis:6379
@@ -192,7 +201,7 @@ services:
- api
- realtime
ports:
- - "3000:3000"
+ - "127.0.0.1:3000:3000"
environment:
NEXT_PUBLIC_API_URL: http://localhost:8000
NEXT_PUBLIC_WS_URL: ws://localhost:8086
diff --git a/docker-compose.yml b/docker-compose.yml
index 368f94ad0..4c6be8571 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -2,6 +2,17 @@
# AiSOC - AI Security Operations Center
# Docker Compose - Full Development Stack
# AiSOC — open-source under MIT License
+#
+# SECURITY NOTE
+# -------------
+# All host port publishings below are bound to 127.0.0.1 so a default
+# `docker compose up` does NOT expose Postgres / Kafka / OpenSearch /
+# Neo4j / Redis (with their development passwords) to the network the
+# host is attached to. This is intentional: the same passwords ship in
+# every clone of this repo. If you need to reach these from another
+# machine, write a docker-compose.override.yml that changes the host
+# binding for the specific service you're exposing — and rotate the
+# password while you're there.
###############################################################################
version: '3.8'
@@ -32,7 +43,7 @@ services:
POSTGRES_USER: aisoc
POSTGRES_PASSWORD: aisoc_dev_secret
ports:
- - "5432:5432"
+ - "127.0.0.1:5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
- ./services/api/migrations:/docker-entrypoint-initdb.d:ro
@@ -49,7 +60,7 @@ services:
container_name: aisoc-redis
command: redis-server --appendonly yes --requirepass redis_dev_secret
ports:
- - "6379:6379"
+ - "127.0.0.1:6379:6379"
volumes:
- redis_data:/data
networks:
@@ -81,7 +92,7 @@ services:
zookeeper:
condition: service_healthy
ports:
- - "9092:9092"
+ - "127.0.0.1:9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
@@ -108,7 +119,7 @@ services:
kafka:
condition: service_healthy
ports:
- - "8090:8080"
+ - "127.0.0.1:8090:8080"
environment:
KAFKA_CLUSTERS_0_NAME: local
KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:29092
@@ -119,8 +130,8 @@ services:
image: clickhouse/clickhouse-server:23.8
container_name: aisoc-clickhouse
ports:
- - "8123:8123"
- - "9000:9000"
+ - "127.0.0.1:8123:8123"
+ - "127.0.0.1:9000:9000"
volumes:
- clickhouse_data:/var/lib/clickhouse
- ./services/api/clickhouse:/docker-entrypoint-initdb.d:ro
@@ -154,7 +165,7 @@ services:
volumes:
- opensearch_data:/usr/share/opensearch/data
ports:
- - "9200:9200"
+ - "127.0.0.1:9200:9200"
networks:
- aisoc
@@ -162,7 +173,7 @@ services:
image: qdrant/qdrant:v1.7.0
container_name: aisoc-qdrant
ports:
- - "6333:6333"
+ - "127.0.0.1:6333:6333"
volumes:
- qdrant_data:/qdrant/storage
networks:
@@ -172,8 +183,8 @@ services:
image: neo4j:5.15-community
container_name: aisoc-neo4j
ports:
- - "7474:7474" # HTTP browser
- - "7687:7687" # Bolt
+ - "127.0.0.1:7474:7474" # HTTP browser
+ - "127.0.0.1:7687:7687" # Bolt
environment:
NEO4J_AUTH: neo4j/neo4j_dev_secret
NEO4J_PLUGINS: '["apoc"]'
@@ -206,7 +217,7 @@ services:
kafka:
condition: service_healthy
ports:
- - "8000:8000"
+ - "127.0.0.1:8000:8000"
environment:
DATABASE_URL: postgresql+asyncpg://aisoc:aisoc_dev_secret@postgres:5432/aisoc
REDIS_URL: redis://:redis_dev_secret@redis:6379/0
@@ -233,8 +244,8 @@ services:
kafka:
condition: service_healthy
ports:
- - "8081:8080"
- - "9090:9090"
+ - "127.0.0.1:8081:8080"
+ - "127.0.0.1:9090:9090"
environment:
ENV: development
HTTP_PORT: 8080
@@ -259,7 +270,7 @@ services:
kafka:
condition: service_healthy
ports:
- - "8080:8082"
+ - "127.0.0.1:8080:8082"
environment:
KAFKA_BOOTSTRAP_SERVERS: kafka:29092
REDIS_URL: redis://:redis_dev_secret@redis:6379/2
@@ -282,7 +293,7 @@ services:
kafka:
condition: service_healthy
ports:
- - "8003:8003"
+ - "127.0.0.1:8003:8003"
environment:
KAFKA_BOOTSTRAP_SERVERS: kafka:29092
REDIS_URL: redis://:redis_dev_secret@redis:6379/3
@@ -302,7 +313,7 @@ services:
redis:
condition: service_healthy
ports:
- - "8001:8084"
+ - "127.0.0.1:8001:8084"
environment:
DATABASE_URL: postgresql+asyncpg://aisoc:aisoc_dev_secret@postgres:5432/aisoc
REDIS_URL: redis://:redis_dev_secret@redis:6379/4
@@ -330,7 +341,7 @@ services:
kafka:
condition: service_healthy
ports:
- - "8002:8085"
+ - "127.0.0.1:8002:8085"
environment:
KAFKA_BOOTSTRAP_SERVERS: kafka:29092
REDIS_URL: redis://:redis_dev_secret@redis:6379/5
@@ -351,7 +362,7 @@ services:
redis:
condition: service_healthy
ports:
- - "8088:8003"
+ - "127.0.0.1:8088:8003"
profiles:
- connectors
environment:
@@ -379,7 +390,7 @@ services:
kafka:
condition: service_healthy
ports:
- - "8005:8005"
+ - "127.0.0.1:8005:8005"
environment:
KAFKA_BOOTSTRAP_SERVERS: kafka:29092
REDIS_URL: redis://:redis_dev_secret@redis:6379/7
@@ -411,7 +422,7 @@ services:
kafka:
condition: service_healthy
ports:
- - "8007:8004"
+ - "127.0.0.1:8007:8004"
environment:
DATABASE_URL: postgresql+asyncpg://aisoc:aisoc_dev_secret@postgres:5432/aisoc
REDIS_URL: redis://:redis_dev_secret@redis:6379/8
@@ -435,7 +446,7 @@ services:
kafka:
condition: service_healthy
ports:
- - "8008:8005"
+ - "127.0.0.1:8008:8005"
environment:
DATABASE_URL: postgresql+asyncpg://aisoc:aisoc_dev_secret@postgres:5432/aisoc
REDIS_URL: redis://:redis_dev_secret@redis:6379/9
@@ -456,7 +467,7 @@ services:
redis:
condition: service_healthy
ports:
- - "8006:8006"
+ - "127.0.0.1:8006:8006"
environment:
DATABASE_URL: postgresql+asyncpg://aisoc:aisoc_dev_secret@postgres:5432/aisoc
REDIS_URL: redis://:redis_dev_secret@redis:6379/10
@@ -477,7 +488,7 @@ services:
kafka:
condition: service_healthy
ports:
- - "8086:4000"
+ - "127.0.0.1:8086:4000"
environment:
KAFKA_BOOTSTRAP_SERVERS: kafka:29092
REDIS_URL: redis://:redis_dev_secret@redis:6379
@@ -496,7 +507,7 @@ services:
- api
- realtime
ports:
- - "3000:3000"
+ - "127.0.0.1:3000:3000"
environment:
NEXT_PUBLIC_API_URL: http://localhost:8000
NEXT_PUBLIC_WS_URL: ws://localhost:8086
@@ -511,7 +522,7 @@ services:
image: prom/prometheus:v2.48.0
container_name: aisoc-prometheus
ports:
- - "9091:9090"
+ - "127.0.0.1:9091:9090"
volumes:
- ./infra/docker/prometheus.yml:/etc/prometheus/prometheus.yml:ro
networks:
@@ -525,9 +536,12 @@ services:
depends_on:
- prometheus
ports:
- - "3001:3000"
+ - "127.0.0.1:3001:3000"
+ # Default admin password is intentionally weak for the dev compose stack;
+ # the 127.0.0.1 binding above keeps the dashboard off the LAN. Override
+ # GF_SECURITY_ADMIN_PASSWORD in production deployments (helm/terraform).
environment:
- GF_SECURITY_ADMIN_PASSWORD: admin
+ GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD:-admin}
volumes:
- ./infra/docker/grafana:/etc/grafana/provisioning:ro
networks:
diff --git a/infra/cloudflare/README.md b/infra/cloudflare/README.md
new file mode 100644
index 000000000..daa46d640
--- /dev/null
+++ b/infra/cloudflare/README.md
@@ -0,0 +1,211 @@
+# Cloudflare Tunnel for `tryaisoc.com`
+
+This directory contains everything needed to expose a local AiSOC stack to the
+public internet through a Cloudflare Tunnel, anchored at the domain
+[`tryaisoc.com`](https://tryaisoc.com).
+
+It is the canonical way to host a **public, read-only demo** of AiSOC on your
+own machine without opening a single inbound port on your router or firewall.
+
+> **Why a tunnel and not a direct LAN bind?**
+> Compose binds every service port to `127.0.0.1` by default (see
+> `docker-compose.yml` and `docker-compose.demo.yml`). That keeps the dev
+> passwords that ship with the repo from leaking onto your LAN. The tunnel
+> punches a single outbound TLS connection to Cloudflare and lets us route
+> traffic in front of `cloudflared` instead of in front of Compose.
+
+## Prerequisites
+
+1. **`cloudflared` installed** — `brew install cloudflared` (macOS) or
+ [follow the upstream install guide](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/install-and-setup/installation/).
+2. **A Cloudflare account that owns `tryaisoc.com`** (or any other zone you
+ control — point `tunnel.sh` at it via the `DOMAIN` env var; no source edits
+ required).
+3. **Login once** — `cloudflared tunnel login`. This drops a `cert.pem` in
+ `~/.cloudflared/` that authorises this machine to manage tunnels and DNS
+ for the zone.
+4. **A running stack** — the demo profile from `pnpm aisoc:demo` is the
+ intended target. The wrapper `pnpm demo:public` (see below) brings the
+ stack up and the tunnel up in one command.
+
+## Topology
+
+```
+ ┌──────────────────────────┐ ┌─────────────────────────────────┐
+ │ Visitor (browser) │ TLS → │ Cloudflare edge (tryaisoc.com) │
+ └──────────────────────────┘ └─────────────────────────────────┘
+ │
+ │ outbound-only
+ │ QUIC / HTTP/2
+ ▼
+ ┌────────────────────┐
+ │ cloudflared │
+ │ (this machine) │
+ └────────────────────┘
+ │ │ │
+ 127.0.0.1:3000 │ │ 127.0.0.1:8000
+ (web) │ │ (api)
+ ▼ ▼
+ ┌───────────────────────┐
+ │ Docker Compose stack │
+ │ (postgres, kafka, │
+ │ api, web, agents, │
+ │ realtime…) │
+ └───────────────────────┘
+```
+
+The four hostnames the tunnel publishes:
+
+| Hostname | Routes to | Service |
+| ------------------------ | -------------------------- | ------------------------- |
+| `tryaisoc.com` | `http://localhost:3000` | Next.js web app |
+| `api.tryaisoc.com` | `http://localhost:8000` | FastAPI core API |
+| `ws.tryaisoc.com` | `http://localhost:8086` | Realtime WebSocket gateway|
+| `docs.tryaisoc.com` | `http://localhost:3001` | Docusaurus (optional) |
+
+Cloudflare terminates TLS and gives you HTTPS for free. The web app inside the
+container still talks to `localhost:8000` for its server-side fetches because
+that's where `cloudflared` lives, not where browsers are pointing — the
+browser hits `api.tryaisoc.com`, which `cloudflared` rewrites to
+`localhost:8000`.
+
+## Quick start
+
+There are three pnpm wrappers for the common shapes:
+
+```sh
+# Stack + tunnel, all-in-one (this is what most people want):
+pnpm demo:public
+
+# Stack already up — just bring the tunnel online:
+pnpm demo:public:tunnel-only
+
+# Provision the tunnel + DNS, but DON'T run it
+# (handy before `cloudflared service install` for a 24/7 deployment):
+SKIP_RUN=1 pnpm demo:public:setup
+```
+
+Under the hood:
+
+- `pnpm demo:public` → [`scripts/demo-public.sh`](../../scripts/demo-public.sh) → runs
+ `pnpm aisoc:demo --no-open`, then execs `infra/cloudflare/tunnel.sh`.
+- `pnpm demo:public:tunnel-only` → same wrapper with `--skip-stack`.
+- `pnpm demo:public:setup` → `bash infra/cloudflare/tunnel.sh` directly, with
+ no stack management.
+
+If you'd rather drive the pieces yourself:
+
+```sh
+# 1. Make sure the stack is up.
+pnpm aisoc:demo # or: docker compose -f docker-compose.demo.yml up -d
+
+# 2. Bring up the tunnel.
+bash infra/cloudflare/tunnel.sh
+```
+
+`tunnel.sh` will:
+
+1. Verify `cloudflared` is installed and authenticated.
+2. Create a tunnel named `aisoc-tryaisoc` (configurable via `TUNNEL_NAME`) if
+ it doesn't already exist.
+3. Render `config.yml` from `config.yml.example`, substituting the tunnel
+ UUID, the credentials path, and the apex domain (`DOMAIN`, default
+ `tryaisoc.com`).
+4. Validate the rendered config with `cloudflared tunnel ingress validate`.
+5. Create / update DNS routes for the apex and each subdomain in
+ `SUBDOMAINS` (default `"api ws docs"`).
+6. Run `cloudflared tunnel --config <generated-config> run`.
+
+The first run takes ~10 seconds for DNS propagation; subsequent runs are
+instant.
+
+### Environment variables
+
+Both `pnpm demo:public*` and `bash infra/cloudflare/tunnel.sh` honour the
+same set:
+
+| Var | Default | Purpose |
+| ------------- | ---------------- | -------------------------------------------------------- |
+| `DOMAIN` | `tryaisoc.com` | Apex domain. The script routes `DOMAIN` and each subdomain in `SUBDOMAINS` to the tunnel. |
+| `TUNNEL_NAME` | `aisoc-tryaisoc` | Cloudflare tunnel name. Reused if it already exists. |
+| `SUBDOMAINS` | `"api ws docs"` | Space-separated list of subdomains to route in addition to the apex. |
+| `SKIP_DNS` | *(unset)* | If set to `1`, don't touch DNS records (assume they exist). |
+| `SKIP_RUN` | *(unset)* | If set to `1`, set everything up but don't run the tunnel — pair with `cloudflared service install` for a 24/7 setup. |
+| `CFD_DIR` | `~/.cloudflared` | Where `cloudflared`'s `cert.pem`, credentials JSONs, and rendered configs live. |
+
+`scripts/demo-public.sh --help` documents the wrapper-level flags
+(`--skip-stack`, `--no-open`, etc.) on top of these.
+
+## Files
+
+| File | Purpose |
+| --------------------- | -------------------------------------------------------------------------------------------- |
+| `tunnel.sh` | Idempotent helper that creates the tunnel, sets DNS routes, and runs `cloudflared`. |
+| `config.yml.example` | Ingress template. The script renders this into `~/.cloudflared/aisoc-tryaisoc.yml`. |
+| `README.md` | This file. |
+
+The rendered `aisoc-tryaisoc.yml` and the `*-credentials.json` file live in
+`~/.cloudflared/` — they are **not** stored in the repo. The credentials JSON
+is what proves to Cloudflare that this machine is allowed to run the tunnel.
+
+## Hosting your own demo on a different domain
+
+You don't need to edit any files. Both `tunnel.sh` and `config.yml.example`
+were written to be domain-agnostic — the script renders the template, and the
+template uses placeholders that the script substitutes at run time.
+
+```sh
+# Apex + the same default subdomains (api, ws, docs) on a zone you own:
+DOMAIN=aisoc.example.com pnpm demo:public
+
+# Custom tunnel name + a different set of subdomains:
+DOMAIN=aisoc.example.com \
+TUNNEL_NAME=acme-aisoc \
+SUBDOMAINS="api ws" \
+ pnpm demo:public
+
+# Set everything up against your zone, but don't run cloudflared yet
+# (e.g. so you can install it as a system service afterwards):
+DOMAIN=aisoc.example.com SKIP_RUN=1 pnpm demo:public:setup
+```
+
+Cloudflare needs to manage DNS for the zone, and you need to have run
+`cloudflared tunnel login` once for that account. Everything else is
+parameterised.
+
+## Stopping
+
+`Ctrl+C` in the foreground tunnel — that's it. The Compose stack keeps
+running. To take everything down:
+
+```sh
+pnpm aisoc:demo:down
+cloudflared tunnel delete aisoc-tryaisoc # only if you want to release the tunnel + DNS
+```
+
+## Production-grade extras (optional)
+
+If you want to leave the demo up 24/7 without a terminal window pinned, run
+`cloudflared` as a launchd / systemd service:
+
+```sh
+# macOS
+sudo cloudflared service install \
+ --config "$HOME/.cloudflared/aisoc-tryaisoc.yml"
+
+# Linux
+sudo cloudflared service install
+```
+
+`cloudflared service uninstall` reverses it.
+
+## What the tunnel does NOT do
+
+- **It does not change auth.** The demo profile still uses the seeded
+ `aisoc:aisoc_dev_secret` credentials. Treat the public demo as a sandbox.
+- **It does not protect the API.** Anyone with the URL can hit
+ `api.tryaisoc.com`. If you need access control, wire up Cloudflare Access
+ in front of the hostnames — `tunnel.sh` is intentionally Access-agnostic so
+ you can layer it on without rewriting the script.
+- **It does not seed data.** Run `pnpm seed:demo` after the stack is up to
+ populate sample incidents.
diff --git a/infra/cloudflare/config.yml.example b/infra/cloudflare/config.yml.example
new file mode 100644
index 000000000..7f24197c9
--- /dev/null
+++ b/infra/cloudflare/config.yml.example
@@ -0,0 +1,54 @@
+# Cloudflare Tunnel ingress for AiSOC's public demo.
+#
+# `infra/cloudflare/tunnel.sh` renders this template into
+# ~/.cloudflared/aisoc-tryaisoc.yml, substituting placeholders for the
+# tunnel UUID, the credentials path, and the apex domain. See tunnel.sh
+# for the exact substitution markers.
+#
+# Edit the routes here, not the rendered file — the rendered file is
+# regenerated on every run of tunnel.sh.
+
+tunnel: __TUNNEL_ID__
+credentials-file: __CREDENTIALS__
+
+# Healthcheck/metrics for cloudflared itself, on localhost only.
+metrics: 127.0.0.1:20241
+
+ingress:
+ # Web app (Next.js, port 3000 in compose).
+ - hostname: __DOMAIN__
+ service: http://localhost:3000
+ originRequest:
+ connectTimeout: 30s
+ noTLSVerify: false
+ httpHostHeader: __DOMAIN__
+
+ # Core API (FastAPI, port 8000 in compose).
+ - hostname: api.__DOMAIN__
+ service: http://localhost:8000
+ originRequest:
+ connectTimeout: 30s
+ noTLSVerify: false
+ httpHostHeader: api.__DOMAIN__
+
+ # Realtime WebSocket gateway (Go, port 8086 → 4000 internal in compose).
+ - hostname: ws.__DOMAIN__
+ service: http://localhost:8086
+ originRequest:
+ connectTimeout: 30s
+ noTLSVerify: false
+ # WS upgrade requires the original Host header.
+ httpHostHeader: ws.__DOMAIN__
+
+ # Docusaurus docs (optional — only routed if you run `pnpm --filter @aisoc/docs dev`
+ # or build + serve the static site on port 3001).
+ - hostname: docs.__DOMAIN__
+ service: http://localhost:3001
+ originRequest:
+ connectTimeout: 30s
+ noTLSVerify: false
+ httpHostHeader: docs.__DOMAIN__
+
+ # Catch-all — every other request returns 404 from cloudflared itself,
+ # never reaching the local stack.
+ - service: http_status:404
diff --git a/infra/cloudflare/tunnel.sh b/infra/cloudflare/tunnel.sh
new file mode 100755
index 000000000..9916c9ea0
--- /dev/null
+++ b/infra/cloudflare/tunnel.sh
@@ -0,0 +1,205 @@
+#!/usr/bin/env bash
+#
+# tunnel.sh — bring up a Cloudflare Tunnel for the AiSOC public demo.
+#
+# What this script does, top to bottom:
+#
+# 1. Verifies cloudflared is installed and the user has logged in
+# (~/.cloudflared/cert.pem must exist).
+# 2. Creates a named tunnel ($TUNNEL_NAME) if it doesn't already exist.
+# If a tunnel with the same name exists, it is reused — the script
+# never deletes or recreates an existing tunnel.
+# 3. Renders config.yml.example into ~/.cloudflared/$TUNNEL_NAME.yml,
+# substituting the tunnel UUID, credentials path, and domain.
+# 4. Creates / updates DNS routes on the zone for the four hostnames the
+# ingress publishes (apex, api, ws, docs).
+# 5. Runs `cloudflared tunnel run` in the foreground. Ctrl+C exits cleanly.
+#
+# Usage:
+#
+# bash infra/cloudflare/tunnel.sh # default: tryaisoc.com
+# DOMAIN=demo.example.com bash infra/cloudflare/tunnel.sh
+# TUNNEL_NAME=my-aisoc bash infra/cloudflare/tunnel.sh
+#
+# Env vars (all optional):
+#
+# DOMAIN Apex domain to publish (default: tryaisoc.com)
+# TUNNEL_NAME Cloudflare Tunnel name (default: aisoc-tryaisoc)
+# SUBDOMAINS Space-separated subdomains to wire up under DOMAIN
+# (default: "api ws docs")
+# SKIP_DNS=1 Skip the DNS-route step (useful if DNS is already set
+# or managed outside cloudflared)
+# SKIP_RUN=1 Generate config + DNS but don't run the tunnel
+# (useful for `cloudflared service install` flows)
+
+set -euo pipefail
+
+# ---------------------------------------------------------------------------
+# Config
+# ---------------------------------------------------------------------------
+
+DOMAIN="${DOMAIN:-tryaisoc.com}"
+TUNNEL_NAME="${TUNNEL_NAME:-aisoc-tryaisoc}"
+SUBDOMAINS="${SUBDOMAINS:-api ws docs}"
+CFD_DIR="${CFD_DIR:-$HOME/.cloudflared}"
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+TEMPLATE="$SCRIPT_DIR/config.yml.example"
+RENDERED_CONFIG="$CFD_DIR/${TUNNEL_NAME}.yml"
+
+# ---------------------------------------------------------------------------
+# Pretty logging
+# ---------------------------------------------------------------------------
+
+if [ -t 1 ]; then
+ C_DIM=$'\033[2m'
+ C_GREEN=$'\033[32m'
+ C_YELLOW=$'\033[33m'
+ C_RED=$'\033[31m'
+ C_BOLD=$'\033[1m'
+ C_RESET=$'\033[0m'
+else
+ C_DIM="" C_GREEN="" C_YELLOW="" C_RED="" C_BOLD="" C_RESET=""
+fi
+
+log() { printf "%s[tunnel]%s %s\n" "$C_DIM" "$C_RESET" "$*"; }
+ok() { printf "%s[tunnel]%s %s%s%s\n" "$C_DIM" "$C_RESET" "$C_GREEN" "$*" "$C_RESET"; }
+warn() { printf "%s[tunnel]%s %s%s%s\n" "$C_DIM" "$C_RESET" "$C_YELLOW" "$*" "$C_RESET"; }
+fatal() { printf "%s[tunnel]%s %s%s%s\n" "$C_DIM" "$C_RESET" "$C_RED" "$*" "$C_RESET" >&2; exit 1; }
+
+# ---------------------------------------------------------------------------
+# Preflight checks
+# ---------------------------------------------------------------------------
+
+command -v cloudflared >/dev/null 2>&1 || fatal \
+ "cloudflared is not installed. Install it with 'brew install cloudflared' (macOS) or follow https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/install-and-setup/installation/."
+
+if [ ! -f "$CFD_DIR/cert.pem" ]; then
+ fatal "Missing $CFD_DIR/cert.pem. Run 'cloudflared tunnel login' first to authorise this machine for the $DOMAIN zone."
+fi
+
+if [ ! -f "$TEMPLATE" ]; then
+ fatal "Template not found: $TEMPLATE"
+fi
+
+mkdir -p "$CFD_DIR"
+
+log "domain = ${C_BOLD}${DOMAIN}${C_RESET}"
+log "tunnel name = ${C_BOLD}${TUNNEL_NAME}${C_RESET}"
+log "subdomains = ${C_BOLD}${SUBDOMAINS}${C_RESET}"
+log "config dir = ${CFD_DIR}"
+
+# ---------------------------------------------------------------------------
+# Step 1 — find or create the tunnel
+# ---------------------------------------------------------------------------
+
+# `cloudflared tunnel list` output:
+# ID NAME CREATED CONNECTIONS
+TUNNEL_ID="$(cloudflared tunnel list --output json 2>/dev/null \
+ | python3 -c "import json,sys
+data=json.load(sys.stdin)
+for t in data:
+ if t.get('name')=='$TUNNEL_NAME':
+ print(t['id']); break" || true)"
+
+if [ -z "${TUNNEL_ID:-}" ]; then
+ log "creating tunnel '$TUNNEL_NAME'..."
+ cloudflared tunnel create "$TUNNEL_NAME" >/dev/null
+ TUNNEL_ID="$(cloudflared tunnel list --output json 2>/dev/null \
+ | python3 -c "import json,sys
+data=json.load(sys.stdin)
+for t in data:
+ if t.get('name')=='$TUNNEL_NAME':
+ print(t['id']); break")"
+ ok "created tunnel ${TUNNEL_NAME} (id ${TUNNEL_ID})"
+else
+ ok "reusing existing tunnel ${TUNNEL_NAME} (id ${TUNNEL_ID})"
+fi
+
+CREDENTIALS="$CFD_DIR/${TUNNEL_ID}.json"
+if [ ! -f "$CREDENTIALS" ]; then
+ fatal "Expected credentials file at $CREDENTIALS but it doesn't exist. Try recreating the tunnel: 'cloudflared tunnel delete $TUNNEL_NAME' then re-run this script."
+fi
+
+# ---------------------------------------------------------------------------
+# Step 2 — render config.yml from the template
+# ---------------------------------------------------------------------------
+
+log "rendering ingress config to ${RENDERED_CONFIG}"
+
+# Use a tempfile so a partial render never lands at the destination.
+TMP_CONFIG="$(mktemp)"
+trap 'rm -f "$TMP_CONFIG"' EXIT
+
+# Substitute placeholders. We use sed with a delimiter that won't appear in
+# the substituted values (| for paths, ~ for the UUID — both safe).
+sed \
+ -e "s|__TUNNEL_ID__|${TUNNEL_ID}|g" \
+ -e "s|__CREDENTIALS__|${CREDENTIALS}|g" \
+ -e "s|__DOMAIN__|${DOMAIN}|g" \
+ "$TEMPLATE" > "$TMP_CONFIG"
+
+# Validate the rendered yaml by asking cloudflared to parse it.
+if ! cloudflared tunnel --config "$TMP_CONFIG" ingress validate >/dev/null 2>&1; then
+ warn "rendered config failed cloudflared's ingress validate — dumping to help debug:"
+ cat "$TMP_CONFIG" >&2
+ fatal "ingress validation failed; aborting before writing $RENDERED_CONFIG"
+fi
+
+mv "$TMP_CONFIG" "$RENDERED_CONFIG"
+trap - EXIT
+ok "config rendered (${TUNNEL_ID} → $DOMAIN)"
+
+# ---------------------------------------------------------------------------
+# Step 3 — DNS routes
+# ---------------------------------------------------------------------------
+
+if [ "${SKIP_DNS:-0}" = "1" ]; then
+ warn "SKIP_DNS=1 — leaving DNS untouched."
+else
+ log "wiring DNS routes for ${DOMAIN} and subdomains: ${SUBDOMAINS}"
+
+ # cloudflared tunnel route dns is idempotent: if the CNAME already points
+ # at this tunnel, it succeeds silently. If it points at *another* tunnel,
+ # it fails with a clear error. We treat that as fatal because silently
+ # repointing someone else's record would be a footgun.
+ route_dns() {
+ local host="$1"
+ if cloudflared tunnel route dns "$TUNNEL_NAME" "$host" 2>&1 | tee /tmp/cfd-route-${TUNNEL_NAME}.log | grep -q "successfully\|already exists"; then
+ ok " $host → $TUNNEL_NAME"
+ elif grep -q "already exists" /tmp/cfd-route-${TUNNEL_NAME}.log; then
+ ok " $host (already pointed at $TUNNEL_NAME)"
+ else
+ cat /tmp/cfd-route-${TUNNEL_NAME}.log >&2
+ fatal "failed to route DNS for $host (see log above)"
+ fi
+ }
+
+ route_dns "$DOMAIN"
+ for sub in $SUBDOMAINS; do
+ route_dns "${sub}.${DOMAIN}"
+ done
+fi
+
+# ---------------------------------------------------------------------------
+# Step 4 — run the tunnel (or stop here if SKIP_RUN=1)
+# ---------------------------------------------------------------------------
+
+if [ "${SKIP_RUN:-0}" = "1" ]; then
+ ok "SKIP_RUN=1 — config + DNS are ready. Run manually with:"
+ log " cloudflared tunnel --config $RENDERED_CONFIG run"
+ exit 0
+fi
+
+cat <<EOF
+
+${C_BOLD}AiSOC public demo is now reachable at:${C_RESET}
+ • https://${DOMAIN}
+ • https://api.${DOMAIN}
+ • https://ws.${DOMAIN}
+ • https://docs.${DOMAIN}
+
+${C_DIM}Press Ctrl+C to stop the tunnel. The Compose stack will keep running.${C_RESET}
+
+EOF
+
+exec cloudflared tunnel --config "$RENDERED_CONFIG" run
diff --git a/package.json b/package.json
index e831e7dca..118199478 100644
--- a/package.json
+++ b/package.json
@@ -25,6 +25,9 @@
"demo:produce": "go run ./services/demo-producer",
"demo:produce:fast": "go run ./services/demo-producer --rate 8 --batch 10",
"detections:validate": "python3 scripts/validate_detections.py",
+ "playbooks:validate": "python3 scripts/validate_playbooks.py",
+ "playbooks:lint": "python3 scripts/lint_playbooks.py",
+ "eval:run": "python3 scripts/run_evals.py",
"marketplace:build": "python3 scripts/build_marketplace.py",
"marketplace:check": "python3 scripts/build_marketplace.py --check",
"marketplace:sync": "python3 scripts/build_marketplace.py && cp marketplace/index.json apps/web/public/marketplace/index.json && echo 'marketplace/index.json built and synced to apps/web/public/'",
@@ -32,7 +35,10 @@
"aisoc:doctor": "tsx scripts/aisoc-doctor.ts",
"aisoc:demo": "tsx scripts/aisoc-demo.ts",
"aisoc:demo:down": "docker compose -f docker-compose.demo.yml down -v",
- "aisoc:demo:logs": "docker compose -f docker-compose.demo.yml logs -f"
+ "aisoc:demo:logs": "docker compose -f docker-compose.demo.yml logs -f",
+ "demo:public": "bash scripts/demo-public.sh",
+ "demo:public:tunnel-only": "bash scripts/demo-public.sh --skip-stack",
+ "demo:public:setup": "bash infra/cloudflare/tunnel.sh"
},
"devDependencies": {
"@types/node": "^20.11.0",
diff --git a/scripts/aisoc-doctor.ts b/scripts/aisoc-doctor.ts
index e2e82a7de..03905e112 100644
--- a/scripts/aisoc-doctor.ts
+++ b/scripts/aisoc-doctor.ts
@@ -161,18 +161,22 @@ async function checkDocker() {
return;
}
- const expectedServices = [
- "aisoc-api",
- "aisoc-agents",
- "aisoc-web",
- "aisoc-postgres",
- "aisoc-redis",
- "aisoc-realtime",
+ // The doctor runs against either the full stack (`aisoc-*`) or the
+ // smaller demo stack (`aisoc-demo-*`). We accept either prefix for the
+ // core services so `pnpm aisoc:demo` users don't see false FAILs.
+ const expectedRoles = [
+ "api",
+ "agents",
+ "web",
+ "postgres",
+ "redis",
+ "realtime",
];
- for (const svc of expectedServices) {
- const found = services.find((s: any) => s.Name === svc);
+ for (const role of expectedRoles) {
+ const candidates = [`aisoc-${role}`, `aisoc-demo-${role}`];
+ const found = services.find((s: any) => candidates.includes(s.Name));
if (!found) {
- record(`container ${svc}`, "FAIL", "not running");
+ record(`container ${role}`, "FAIL", `not running (looked for ${candidates.join(" or ")})`);
continue;
}
const healthy =
@@ -180,9 +184,9 @@ async function checkDocker() {
found.Health === "" /* no healthcheck */ ||
found.State === "running";
record(
- `container ${svc}`,
+ `container ${role}`,
healthy ? "OK" : "FAIL",
- `state=${found.State}${found.Health ? ` health=${found.Health}` : ""}`
+ `${found.Name} state=${found.State}${found.Health ? ` health=${found.Health}` : ""}`
);
}
}
@@ -214,8 +218,11 @@ async function checkApi() {
}
record("GET /health", "OK", JSON.stringify(health).slice(0, 80));
- // Demo data: at least one alert
- const alerts = await fetchJson("http://localhost:8000/v1/alerts?limit=1");
+ // Demo data: at least one alert. The API is mounted at `/api/v1`
+ // (services/api/app/api/v1/router.py), not `/v1` — using the wrong
+ // prefix here used to produce a permanent false FAIL after a clean
+ // `pnpm aisoc:demo`.
+ const alerts = await fetchJson("http://localhost:8000/api/v1/alerts?limit=1");
if (!alerts) {
record(
"demo data seeded",
diff --git a/scripts/demo-public.sh b/scripts/demo-public.sh
new file mode 100755
index 000000000..c85ac9094
--- /dev/null
+++ b/scripts/demo-public.sh
@@ -0,0 +1,106 @@
+#!/usr/bin/env bash
+#
+# demo-public.sh — public-facing demo on tryaisoc.com.
+#
+# Composition of two things that already exist:
+#
+# 1. `pnpm aisoc:demo --no-open` — boots the slim demo profile from
+# docker-compose.demo.yml, waits for postgres + api + web, seeds canonical
+# data, kicks off an investigation. Defined in scripts/aisoc-demo.ts.
+#
+# 2. `infra/cloudflare/tunnel.sh` — creates / reuses the cloudflared tunnel
+# named $TUNNEL_NAME, wires DNS for $DOMAIN + subdomains, and runs
+# cloudflared in the foreground.
+#
+# When the user Ctrl+C's the tunnel, the Compose stack keeps running. Tear it
+# down with `pnpm aisoc:demo:down`.
+#
+# Usage:
+# bash scripts/demo-public.sh # tryaisoc.com
+# DOMAIN=demo.example.com bash scripts/demo-public.sh
+#
+# All env vars from infra/cloudflare/tunnel.sh are honoured (DOMAIN,
+# TUNNEL_NAME, SUBDOMAINS, SKIP_DNS, SKIP_RUN).
+#
+# Flags forwarded to aisoc:demo:
+# --skip-stack skip step 1 entirely (the stack is already up)
+# --tag <tag> passed through to aisoc:demo (sets AISOC_TAG)
+# --no-pull passed through to aisoc:demo
+
+set -euo pipefail
+
+ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+cd "$ROOT"
+
+if [ -t 1 ]; then
+ C_BOLD=$'\033[1m'; C_DIM=$'\033[2m'; C_GREEN=$'\033[32m'
+ C_RED=$'\033[31m'; C_YELLOW=$'\033[33m'; C_RESET=$'\033[0m'
+else
+ C_BOLD="" C_DIM="" C_GREEN="" C_RED="" C_YELLOW="" C_RESET=""
+fi
+
+SKIP_STACK=0
+DEMO_FLAGS=()
+
+while [ $# -gt 0 ]; do
+ case "$1" in
+ --skip-stack) SKIP_STACK=1; shift ;;
+ --tag) DEMO_FLAGS+=("--tag" "$2"); shift 2 ;;
+ --no-pull) DEMO_FLAGS+=("--no-pull"); shift ;;
+ --rebuild) DEMO_FLAGS+=("--rebuild"); shift ;;
+ -h|--help)
+ # Print the leading comment block only (everything from the shebang
+ # up to the first blank line that follows a `#`-prefixed line).
+ awk '
+ NR==1 { next } # skip shebang
+ /^#/ { sub(/^# ?/, ""); print; next }
+ { exit }
+ ' "$0"
+ exit 0
+ ;;
+ *)
+ printf "%sunknown flag:%s %s\n" "$C_RED" "$C_RESET" "$1" >&2
+ exit 64
+ ;;
+ esac
+done
+
+DOMAIN="${DOMAIN:-tryaisoc.com}"
+
+printf "%s%s── AiSOC public demo ──%s\n" "$C_BOLD" "$C_GREEN" "$C_RESET"
+printf " domain : %s%s%s\n" "$C_BOLD" "$DOMAIN" "$C_RESET"
+printf " stack : docker-compose.demo.yml (read-only profile, prebuilt images)\n"
+printf " tunnel : cloudflared (outbound only — no inbound ports needed)\n\n"
+
+# ---------------------------------------------------------------------------
+# Step 1 — local stack (skippable if it's already up)
+# ---------------------------------------------------------------------------
+
+if [ "$SKIP_STACK" = "1" ]; then
+ printf "%s[1/2] skipping local stack (--skip-stack)%s\n" "$C_DIM" "$C_RESET"
+else
+ printf "%s[1/2] starting local stack via aisoc:demo%s\n" "$C_BOLD" "$C_RESET"
+
+ # Prefer pnpm if available, fall back to npx tsx so the script also works in
+ # contexts where pnpm isn't installed (e.g. cloud demos that only have node).
+ if command -v pnpm >/dev/null 2>&1; then
+ pnpm aisoc:demo --no-open "${DEMO_FLAGS[@]}"
+ elif command -v npx >/dev/null 2>&1; then
+ npx tsx scripts/aisoc-demo.ts --no-open "${DEMO_FLAGS[@]}"
+ else
+ printf "%sneither pnpm nor npx is available; install Node.js >= 20 and corepack enable%s\n" "$C_RED" "$C_RESET" >&2
+ exit 1
+ fi
+fi
+
+# ---------------------------------------------------------------------------
+# Step 2 — cloudflared tunnel (foreground)
+# ---------------------------------------------------------------------------
+
+printf "\n%s[2/2] bringing up Cloudflare Tunnel for %s%s%s%s\n" \
+ "$C_BOLD" "$C_DIM" "$DOMAIN" "$C_RESET" "$C_RESET"
+printf "%s(Ctrl+C exits the tunnel; the local stack keeps running)%s\n\n" \
+ "$C_DIM" "$C_RESET"
+
+# Hand off — exec replaces this shell with cloudflared, so signals are clean.
+exec env DOMAIN="$DOMAIN" bash "$ROOT/infra/cloudflare/tunnel.sh"