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(demo): make stack public-host-agnostic and tunnel-ready for tryaisoc.com

Beenu Arora24c3b94ffbf5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d80d66036..8c314056b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -119,16 +119,31 @@ hosted on `tryaisoc.com` via Cloudflare Tunnel.
#### Public demo on `tryaisoc.com`
-- **Cloudflare Tunnel infra** (`infra/cloudflare/`) — `config.yml`,
+- **Cloudflare Tunnel infra** (`infra/cloudflare/`) — `config.yml.example`,
`tunnel.sh`, and a README explaining how to run the demo profile
- behind `tryaisoc.com` via `cloudflared`.
-- **`make demo-public` target** — boots `docker-compose.demo.yml`
- (read-only demo profile with seeded incidents) and brings up the
- Cloudflare tunnel that maps `tryaisoc.com` → `localhost:3000`
- (web), `api.tryaisoc.com` → `localhost:8000` (API), and
- `docs.tryaisoc.com` → `localhost:3001` (Docusaurus).
+ behind `tryaisoc.com` via `cloudflared`. Tunnel script reads
+ `DOMAIN`, `TUNNEL_NAME`, `SUBDOMAINS`, `SKIP_DNS`, `SKIP_RUN` env
+ vars; defaults publish apex + `api.`, `ws.`, `docs.` subdomains.
+- **`pnpm demo:public` script** (`scripts/demo-public.sh`) — boots
+ `docker-compose.demo.yml` (read-only demo profile with seeded
+ incidents) via `pnpm aisoc:demo --no-open`, then brings up the
+ Cloudflare Tunnel that maps `tryaisoc.com` → web (`:3000`),
+ `api.tryaisoc.com` → api (`:8000`), `ws.tryaisoc.com` → realtime
+ (`:4000`), and `docs.tryaisoc.com` → Docusaurus (`:3001`).
+ Companion scripts: `pnpm demo:public:tunnel-only` (skip stack
+ bring-up, just run the tunnel) and `pnpm demo:public:setup`
+ (provision tunnel + DNS without running cloudflared, for
+ `cloudflared service install` flows).
+- **Public-host-agnostic web bundle** (`apps/web/next.config.js`,
+ `apps/web/src/lib/api.ts`) — the Next.js client now emits
+ same-origin relative paths (`/api/v1/...`, `/ws/...`) instead of
+ `localhost:8000`-baked URLs, with server-side rewrites proxying
+ to api/agents/realtime by Docker DNS name. The same image works
+ on `localhost:3000`, behind Cloudflare Tunnel on `tryaisoc.com`,
+ or behind any reverse proxy without a rebuild.
- **README "Try it live"** — top-of-README link to the public demo
- with a one-liner for hosting your own.
+ with a one-liner for hosting your own on a Cloudflare-managed
+ domain.
---
diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile
index 34607b4cd..12cc59358 100644
--- a/apps/web/Dockerfile
+++ b/apps/web/Dockerfile
@@ -5,48 +5,30 @@ FROM node:20-alpine AS base
RUN apk add --no-cache libc6-compat
RUN npm install -g pnpm@8
-# ─── Dependencies ────────────────────────────────────────────────────────────
-FROM base AS deps
-WORKDIR /app
-
-COPY package.json pnpm-workspace.yaml ./
-COPY pnpm-lock.yaml* ./
-COPY packages/types/package.json ./packages/types/
-COPY packages/ui/package.json ./packages/ui/
-COPY packages/ocsf/package.json ./packages/ocsf/
-COPY apps/web/package.json ./apps/web/
-
-# Hoisted node_modules so pnpm-installed bins are on PATH and Next.js can
-# resolve workspace packages without symlink games.
-RUN echo "node-linker=hoisted" > .npmrc && \
- echo "shamefully-hoist=true" >> .npmrc && \
- pnpm install --no-frozen-lockfile
-
# ─── Builder ──────────────────────────────────────────────────────────────────
+# Single-stage install + build keeps pnpm's symlinked workspace layout
+# intact (matches local dev). Splitting into a deps-only stage previously
+# broke bin shims for tsup/tsc inside packages/*/node_modules.
FROM base AS builder
WORKDIR /app
-COPY --from=deps /app/node_modules ./node_modules
-COPY --from=deps /app/.npmrc ./.npmrc
-
COPY package.json pnpm-workspace.yaml ./
COPY pnpm-lock.yaml* ./
-COPY packages/types ./packages/types
-COPY packages/ui ./packages/ui
-COPY packages/ocsf ./packages/ocsf
-COPY apps/web ./apps/web
COPY turbo.json ./
+COPY packages ./packages
+COPY apps/web ./apps/web
ENV NEXT_TELEMETRY_DISABLED=1
+# Use pnpm's default symlinked node_modules — same layout as local dev,
+# so tsup/tsc bin shims resolve correctly inside each workspace package.
+RUN pnpm install --no-frozen-lockfile
+
# Build workspace packages then the Next.js app.
RUN pnpm --filter @aisoc/types build && \
pnpm --filter @aisoc/ui build && \
pnpm --filter @aisoc/web build
-# Prune dev dependencies for a smaller runtime.
-RUN pnpm --filter @aisoc/web --prod deploy /app/deploy 2>/dev/null || true
-
# ─── Runner ───────────────────────────────────────────────────────────────────
FROM base AS runner
WORKDIR /app
@@ -59,15 +41,12 @@ ENV HOSTNAME="0.0.0.0"
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
-# Copy hoisted node_modules (contains next + workspace deps).
-COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
-COPY --from=builder --chown=nextjs:nodejs /app/apps/web/.next ./.next
-COPY --from=builder --chown=nextjs:nodejs /app/apps/web/public ./public
-COPY --from=builder --chown=nextjs:nodejs /app/apps/web/package.json ./package.json
-COPY --from=builder --chown=nextjs:nodejs /app/apps/web/next.config.js ./next.config.js
+# Copy the full workspace so symlinked workspace packages keep resolving.
+COPY --from=builder --chown=nextjs:nodejs /app ./
USER nextjs
EXPOSE 3000
+WORKDIR /app/apps/web
-# Use the next binary from hoisted node_modules.
-CMD ["node_modules/.bin/next", "start"]
+# pnpm resolves the workspace's next binary correctly under symlinked layout.
+CMD ["pnpm", "start"]
diff --git a/apps/web/next.config.js b/apps/web/next.config.js
index 4f9ab67e0..b9e865009 100644
--- a/apps/web/next.config.js
+++ b/apps/web/next.config.js
@@ -1,4 +1,15 @@
/** @type {import('next').NextConfig} */
+
+// ─── Server-side rewrite targets ────────────────────────────────────────────
+//
+// These are the *origin* URLs the Next.js server uses when proxying
+// `/api/v1/*`, `/api/v1/contextual/*`, `/ws/*` and `/sse` to downstream
+// services. They never reach the browser — only the Node.js process.
+//
+// Defaults are localhost for `pnpm --filter @aisoc/web dev` outside Docker.
+// In the demo Compose stack the `web` service overrides these via env to
+// Docker DNS names (`http://api:8000`, `http://agents:8084`,
+// `http://realtime:4000`).
const REALTIME_HOST = process.env.REALTIME_URL || 'http://localhost:8086';
const API_HOST = process.env.API_URL || 'http://localhost:8000';
const AGENTS_HOST = process.env.AGENTS_URL || 'http://localhost:8001';
@@ -17,22 +28,39 @@ const nextConfig = {
eslint: {
ignoreDuringBuilds: true,
},
+ // ─── Client-side env (baked into the JS bundle at build time) ────────────
+ //
+ // Defaults are empty strings, which makes every fetch in `lib/api.ts`
+ // emit a same-origin path (e.g. `/api/v1/alerts`). Next.js then proxies
+ // those paths to the correct service via the rewrites below. This keeps
+ // a single image working on:
+ // - localhost:3000 (developer machine)
+ // - https://tryaisoc.com (Cloudflare Tunnel)
+ // - any reverse-proxy in between
+ //
+ // Override via build args / docker-compose if you ever want the bundle to
+ // call a different origin directly (skipping the Next proxy).
env: {
- NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000',
- NEXT_PUBLIC_AGENTS_URL: process.env.NEXT_PUBLIC_AGENTS_URL || 'http://localhost:8001',
- NEXT_PUBLIC_ACTIONS_URL: process.env.NEXT_PUBLIC_ACTIONS_URL || 'http://localhost:8002',
- NEXT_PUBLIC_FUSION_URL: process.env.NEXT_PUBLIC_FUSION_URL || 'http://localhost:8003',
- NEXT_PUBLIC_THREATINTEL_URL: process.env.NEXT_PUBLIC_THREATINTEL_URL || 'http://localhost:8005',
- NEXT_PUBLIC_ENRICHMENT_URL: process.env.NEXT_PUBLIC_ENRICHMENT_URL || 'http://localhost:8080',
- NEXT_PUBLIC_WS_URL: process.env.NEXT_PUBLIC_WS_URL || 'ws://localhost:8086',
- NEXT_PUBLIC_REALTIME_URL: process.env.NEXT_PUBLIC_REALTIME_URL || 'http://localhost:8086',
+ NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL || '',
+ NEXT_PUBLIC_AGENTS_URL: process.env.NEXT_PUBLIC_AGENTS_URL || '',
+ NEXT_PUBLIC_ACTIONS_URL: process.env.NEXT_PUBLIC_ACTIONS_URL || '',
+ NEXT_PUBLIC_FUSION_URL: process.env.NEXT_PUBLIC_FUSION_URL || '',
+ NEXT_PUBLIC_THREATINTEL_URL: process.env.NEXT_PUBLIC_THREATINTEL_URL || '',
+ NEXT_PUBLIC_ENRICHMENT_URL: process.env.NEXT_PUBLIC_ENRICHMENT_URL || '',
+ NEXT_PUBLIC_WS_URL: process.env.NEXT_PUBLIC_WS_URL || '',
+ NEXT_PUBLIC_REALTIME_URL: process.env.NEXT_PUBLIC_REALTIME_URL || '',
NEXT_PUBLIC_TENANT_ID: process.env.NEXT_PUBLIC_TENANT_ID || 'default',
+ NEXT_PUBLIC_PURPLE_TEAM_API: process.env.NEXT_PUBLIC_PURPLE_TEAM_API || '',
+ NEXT_PUBLIC_HONEYTOKENS_URL: process.env.NEXT_PUBLIC_HONEYTOKENS_URL || '',
},
- // Proxy WebSocket and HTTP calls to the realtime service during development.
- // In production, nginx (or your reverse proxy) handles this routing.
+ // ─── Same-origin proxy rules ─────────────────────────────────────────────
+ //
+ // Order matters: more specific paths (contextual, realtime healthz) must
+ // come before the generic `/api/v1/:path*` catch-all so they hit the
+ // right downstream service.
async rewrites() {
return [
- // WebSocket / SSE (realtime service)
+ // WebSocket / SSE — realtime gateway.
{
source: '/ws/:path*',
destination: `${REALTIME_HOST}/ws/:path*`,
@@ -41,7 +69,17 @@ const nextConfig = {
source: '/sse',
destination: `${REALTIME_HOST}/sse`,
},
- // REST API — proxy to api service (port 8000)
+ // Realtime health probe (used by status pages).
+ {
+ source: '/api/v1/realtime/healthz',
+ destination: `${REALTIME_HOST}/healthz`,
+ },
+ // Contextual actions live on the agents service, not the core API.
+ {
+ source: '/api/v1/contextual/:path*',
+ destination: `${AGENTS_HOST}/api/v1/contextual/:path*`,
+ },
+ // Catch-all for the core API.
{
source: '/api/v1/:path*',
destination: `${API_HOST}/api/v1/:path*`,
diff --git a/apps/web/src/app/(app)/honeytokens/page.tsx b/apps/web/src/app/(app)/honeytokens/page.tsx
index b8f93800f..7b8baf6de 100644
--- a/apps/web/src/app/(app)/honeytokens/page.tsx
+++ b/apps/web/src/app/(app)/honeytokens/page.tsx
@@ -3,7 +3,10 @@
import { useState } from "react";
import useSWR, { mutate } from "swr";
-const API = process.env.NEXT_PUBLIC_HONEYTOKENS_URL ?? "http://localhost:8005";
+// Same-origin by default — Next.js rewrites proxy `/api/v1/honeytokens/*`
+// to the honeytokens service. Override with `NEXT_PUBLIC_HONEYTOKENS_URL`
+// to debug against a different origin.
+const API = process.env.NEXT_PUBLIC_HONEYTOKENS_URL ?? "";
const TENANT_ID = process.env.NEXT_PUBLIC_TENANT_ID ?? "00000000-0000-0000-0000-000000000001";
const fetcher = (url: string) => fetch(url).then((r) => r.json());
diff --git a/apps/web/src/app/(app)/purple-team/page.tsx b/apps/web/src/app/(app)/purple-team/page.tsx
index b85c172eb..6ea8be05d 100644
--- a/apps/web/src/app/(app)/purple-team/page.tsx
+++ b/apps/web/src/app/(app)/purple-team/page.tsx
@@ -3,7 +3,10 @@
import { useState } from 'react'
import useSWR from 'swr'
-const API = process.env.NEXT_PUBLIC_PURPLE_TEAM_API ?? 'http://localhost:8006'
+// Same-origin by default — Next.js rewrites proxy `/api/v1/purple-team/*` to
+// the purple-team service. Override with `NEXT_PUBLIC_PURPLE_TEAM_API` for
+// debugging against a different origin.
+const API = process.env.NEXT_PUBLIC_PURPLE_TEAM_API ?? ''
// --------------------------------------------------------------------------
// Types
diff --git a/apps/web/src/app/(responder)/responder/login/page.tsx b/apps/web/src/app/(responder)/responder/login/page.tsx
index a3598076d..3caad8b2b 100644
--- a/apps/web/src/app/(responder)/responder/login/page.tsx
+++ b/apps/web/src/app/(responder)/responder/login/page.tsx
@@ -11,7 +11,7 @@
import Link from 'next/link';
import { useRouter, useSearchParams } from 'next/navigation';
-import { useEffect, useState } from 'react';
+import { Suspense, useEffect, useState } from 'react';
import { passkeyApi } from '@/lib/api';
import {
saveSession,
@@ -22,7 +22,11 @@ import { getPasskey, isWebAuthnSupported } from '@/lib/responder/webauthn';
type Phase = 'idle' | 'pending' | 'success' | 'error';
-export default function ResponderLoginPage() {
+// Avoid Next 14 static-prerender bailout — this page reads `?next=` from
+// the URL and is only ever reached interactively from a phone.
+export const dynamic = 'force-dynamic';
+
+function ResponderLoginInner() {
const router = useRouter();
const search = useSearchParams();
const next = search?.get('next') || '/responder/triage';
@@ -220,3 +224,11 @@ export default function ResponderLoginPage() {
</div>
);
}
+
+export default function ResponderLoginPage() {
+ return (
+ <Suspense fallback={null}>
+ <ResponderLoginInner />
+ </Suspense>
+ );
+}
diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.ts
index 78887be9f..8581d1537 100644
--- a/apps/web/src/lib/api.ts
+++ b/apps/web/src/lib/api.ts
@@ -9,26 +9,45 @@
* wrap with SWR / React Query for caching + retries.
* - Errors are thrown as native `Error` with the HTTP status + body so
* UI components can catch and render `<ErrorState error={e} />`.
- * - Base URLs are configured via NEXT_PUBLIC_* env vars and default to
- * local-development hostnames.
+ * - Base URLs default to "" (same-origin) so the browser hits whatever
+ * host it loaded the page from. Next.js `rewrites()` then proxies the
+ * `/api/v1/*`, `/api/v1/contextual/*`, `/ws/*` and `/sse` paths to the
+ * right downstream service. This makes the bundle host-agnostic — the
+ * same image works on `localhost:3000`, behind nginx, or behind a
+ * Cloudflare Tunnel pointed at `tryaisoc.com`.
+ * - `NEXT_PUBLIC_*_URL` env vars are still honoured if you want to bypass
+ * the proxy (e.g. point the bundle at a different API origin during
+ * local debugging).
*/
-const API_BASE =
- process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000';
-const AGENTS_BASE =
- process.env.NEXT_PUBLIC_AGENTS_URL || 'http://localhost:8001';
-const ACTIONS_BASE =
- process.env.NEXT_PUBLIC_ACTIONS_URL || 'http://localhost:8002';
-const FUSION_BASE =
- process.env.NEXT_PUBLIC_FUSION_URL || 'http://localhost:8003';
-const THREATINTEL_BASE =
- process.env.NEXT_PUBLIC_THREATINTEL_URL || 'http://localhost:8005';
-const ENRICHMENT_BASE =
- process.env.NEXT_PUBLIC_ENRICHMENT_URL || 'http://localhost:8080';
-const REALTIME_BASE =
- process.env.NEXT_PUBLIC_REALTIME_URL || 'http://localhost:8086';
-const WS_BASE =
- process.env.NEXT_PUBLIC_WS_URL || 'ws://localhost:8086';
+const API_BASE = process.env.NEXT_PUBLIC_API_URL || '';
+const AGENTS_BASE = process.env.NEXT_PUBLIC_AGENTS_URL || '';
+const ACTIONS_BASE = process.env.NEXT_PUBLIC_ACTIONS_URL || '';
+const FUSION_BASE = process.env.NEXT_PUBLIC_FUSION_URL || '';
+const THREATINTEL_BASE = process.env.NEXT_PUBLIC_THREATINTEL_URL || '';
+const ENRICHMENT_BASE = process.env.NEXT_PUBLIC_ENRICHMENT_URL || '';
+const REALTIME_BASE = process.env.NEXT_PUBLIC_REALTIME_URL || '';
+const WS_BASE = process.env.NEXT_PUBLIC_WS_URL || '';
+
+/**
+ * Compute the WebSocket origin at call time.
+ *
+ * If the bundle was built with `NEXT_PUBLIC_WS_URL` set, use that verbatim.
+ * Otherwise, derive `wss://<current-host>` from `window.location` so the WS
+ * connection lands on the same host the page was loaded from (the Next.js
+ * rewrites then proxy `/ws/*` to the realtime gateway).
+ *
+ * SSR fallback: returns `''` so the resulting URL is path-only; nothing on
+ * the server actually opens WebSockets.
+ */
+function wsOrigin(): string {
+ if (WS_BASE) return WS_BASE;
+ if (typeof window !== 'undefined') {
+ const proto = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
+ return `${proto}//${window.location.host}`;
+ }
+ return '';
+}
const TENANT_ID =
process.env.NEXT_PUBLIC_TENANT_ID ||
@@ -1083,6 +1102,19 @@ export const contextualApi = {
}),
};
+// Re-export base URLs so dev tooling and tests can introspect them.
+// Production callers should prefer the typed functions above.
+export const __apiBases = {
+ api: API_BASE,
+ agents: AGENTS_BASE,
+ actions: ACTIONS_BASE,
+ fusion: FUSION_BASE,
+ threatintel: THREATINTEL_BASE,
+ enrichment: ENRICHMENT_BASE,
+ realtime: REALTIME_BASE,
+ ws: WS_BASE,
+} as const;
+
// ─── Web Push & Responder PWA ────────────────────────────────────────────────
//
// Phase 4B. The mobile responder PWA subscribes to Web Push so on-call
@@ -1348,14 +1380,19 @@ export const passkeyApi = {
export const realtimeApi = {
/** Returns a ready-to-open WebSocket URL for the given channel. */
channelUrl(channel: 'alerts' | 'cases' | 'agents' | 'all') {
- return `${WS_BASE}/ws/${channel}?tenant_id=${encodeURIComponent(TENANT_ID)}`;
+ return `${wsOrigin()}/ws/${channel}?tenant_id=${encodeURIComponent(TENANT_ID)}`;
},
- /** Health endpoint of the realtime gateway, useful for status pages. */
+ /**
+ * Health endpoint of the realtime gateway, useful for status pages.
+ * Uses the dedicated `/api/v1/realtime/healthz` proxy path so it works
+ * same-origin behind the Cloudflare Tunnel.
+ */
health: () =>
- request<{ status: string; clients: number }>('/healthz', {
- baseUrl: REALTIME_BASE,
- }),
+ request<{ status: string; clients: number }>(
+ '/api/v1/realtime/healthz',
+ { baseUrl: REALTIME_BASE },
+ ),
};
export default {
diff --git a/docker-compose.demo.yml b/docker-compose.demo.yml
index 3ff3d9969..de39b50ae 100644
--- a/docker-compose.demo.yml
+++ b/docker-compose.demo.yml
@@ -120,8 +120,17 @@ services:
api:
image: ghcr.io/beenuar/aisoc-core-api:${AISOC_TAG:-latest}
+ # Local build context for `pnpm aisoc:demo --rebuild`. Without this the
+ # `--build` flag is a no-op because compose has nothing to build from.
+ # When pulling prebuilt images this block is ignored.
+ build:
+ context: ./services/api
container_name: aisoc-demo-api
- pull_policy: always
+ # `missing` lets `pnpm aisoc:demo --rebuild` use locally built images
+ # without being clobbered by a registry pull. Compose still pulls when
+ # the image isn't present locally (first run) or when the user runs
+ # `docker compose pull` explicitly.
+ pull_policy: missing
depends_on:
postgres:
condition: service_healthy
@@ -152,8 +161,10 @@ services:
agents:
image: ghcr.io/beenuar/aisoc-agents:${AISOC_TAG:-latest}
+ build:
+ context: ./services/agents
container_name: aisoc-demo-agents
- pull_policy: always
+ pull_policy: missing
depends_on:
postgres:
condition: service_healthy
@@ -175,8 +186,10 @@ services:
realtime:
image: ghcr.io/beenuar/aisoc-realtime:${AISOC_TAG:-latest}
+ build:
+ context: ./services/realtime
container_name: aisoc-demo-realtime
- pull_policy: always
+ pull_policy: missing
depends_on:
redis:
condition: service_healthy
@@ -195,16 +208,28 @@ services:
web:
image: ghcr.io/beenuar/aisoc-web:${AISOC_TAG:-latest}
+ # Build context for `pnpm aisoc:demo --rebuild`. The Dockerfile bakes the
+ # frontend bundle with empty NEXT_PUBLIC_* defaults so every fetch is a
+ # same-origin relative path (`/api/v1/...`, `/ws/...`). Next.js then
+ # proxies those to the services below using the Docker DNS targets in
+ # `environment:`.
+ build:
+ context: .
+ dockerfile: apps/web/Dockerfile
container_name: aisoc-demo-web
- pull_policy: always
+ pull_policy: missing
depends_on:
- api
+ - agents
- realtime
ports:
- "127.0.0.1:3000:3000"
environment:
- NEXT_PUBLIC_API_URL: http://localhost:8000
- NEXT_PUBLIC_WS_URL: ws://localhost:8086
+ # Server-side rewrite targets (used by the Next.js Node process).
+ # These never reach the browser — only the proxy layer in next.config.js.
+ API_URL: http://api:8000
+ AGENTS_URL: http://agents:8084
+ REALTIME_URL: http://realtime:4000
NODE_ENV: production
networks:
- aisoc-demo
diff --git a/infra/cloudflare/tunnel.sh b/infra/cloudflare/tunnel.sh
index 9916c9ea0..1f8fe1d49 100755
--- a/infra/cloudflare/tunnel.sh
+++ b/infra/cloudflare/tunnel.sh
@@ -23,14 +23,19 @@
#
# 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)
+# 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")
+# TUNNEL_ORIGIN_CERT Path to the Cloudflare origin certificate
+# (default: ~/.cloudflared/cert.pem). Set this to
+# keep multiple Cloudflare accounts side-by-side —
+# e.g. cert.pem for one zone and
+# cert.tryaisoc.pem for tryaisoc.com.
+# 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
@@ -42,6 +47,12 @@ DOMAIN="${DOMAIN:-tryaisoc.com}"
TUNNEL_NAME="${TUNNEL_NAME:-aisoc-tryaisoc}"
SUBDOMAINS="${SUBDOMAINS:-api ws docs}"
CFD_DIR="${CFD_DIR:-$HOME/.cloudflared}"
+# TUNNEL_ORIGIN_CERT is a recognised cloudflared env var: it points the binary
+# at a non-default cert.pem. We default it to the conventional location so
+# users with a single account see no behaviour change, but exporting it lets
+# multi-account setups keep their certs separate.
+TUNNEL_ORIGIN_CERT="${TUNNEL_ORIGIN_CERT:-$CFD_DIR/cert.pem}"
+export TUNNEL_ORIGIN_CERT
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEMPLATE="$SCRIPT_DIR/config.yml.example"
RENDERED_CONFIG="$CFD_DIR/${TUNNEL_NAME}.yml"
@@ -73,8 +84,8 @@ fatal() { printf "%s[tunnel]%s %s%s%s\n" "$C_DIM" "$C_RESET" "$C_RED" "$*" "$C_
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."
+if [ ! -f "$TUNNEL_ORIGIN_CERT" ]; then
+ fatal "Missing origin certificate at $TUNNEL_ORIGIN_CERT. Run 'cloudflared tunnel login' to authorise this machine for the $DOMAIN zone, or set TUNNEL_ORIGIN_CERT to point at an existing cert."
fi
if [ ! -f "$TEMPLATE" ]; then
@@ -87,6 +98,7 @@ 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}"
+log "origin cert = ${TUNNEL_ORIGIN_CERT}"
# ---------------------------------------------------------------------------
# Step 1 — find or create the tunnel
@@ -162,14 +174,43 @@ else
# 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.
+ #
+ # SUBTLE FOOTGUN: if the active cert.pem belongs to a different Cloudflare
+ # account/zone than $DOMAIN, cloudflared "succeeds" by creating a CNAME on
+ # the *cert's* zone with $DOMAIN as a label — e.g. asked to route
+ # tryaisoc.com it will create `tryaisoc.com.intel.nexus`. We detect that
+ # pattern explicitly and abort with guidance.
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
+ local log="/tmp/cfd-route-${TUNNEL_NAME}.log"
+ cloudflared tunnel route dns "$TUNNEL_NAME" "$host" >"$log" 2>&1 || true
+
+ # Misroute detection: cloudflared logs lines like
+ # "INF Added CNAME <fqdn> which will route to ..."
+ # If <fqdn> doesn't end with the host we asked for, the cert is wrong.
+ local added_cname
+ added_cname="$(grep -oE 'Added CNAME [^ ]+' "$log" | awk '{print $3}' | head -n1 || true)"
+ if [ -n "$added_cname" ] && [ "$added_cname" != "$host" ]; then
+ cat "$log" >&2
+ fatal "DNS misroute detected for ${host}: cloudflared created '${added_cname}' instead. The active origin certificate at ${TUNNEL_ORIGIN_CERT} is authorised for a *different* Cloudflare zone, not ${DOMAIN}.
+
+To fix:
+ 1. Back up the current cert if you want to keep it:
+ mv ${TUNNEL_ORIGIN_CERT} ${TUNNEL_ORIGIN_CERT}.$(date +%Y%m%d).bak
+ 2. Log in with the Cloudflare account that owns ${DOMAIN}:
+ cloudflared tunnel login
+ (this writes a fresh ${TUNNEL_ORIGIN_CERT})
+ 3. (Optional) save it under a per-account name and export:
+ mv ${TUNNEL_ORIGIN_CERT} ${CFD_DIR}/cert.${DOMAIN}.pem
+ export TUNNEL_ORIGIN_CERT=${CFD_DIR}/cert.${DOMAIN}.pem
+ 4. Re-run this script. You may also want to delete the misrouted CNAME
+ ('${added_cname}') from the wrong zone in the Cloudflare dashboard."
+ fi
+
+ if grep -q "successfully\|already exists\|Added CNAME" "$log"; 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
+ cat "$log" >&2
fatal "failed to route DNS for $host (see log above)"
fi
}
diff --git a/services/agents/Dockerfile b/services/agents/Dockerfile
index 045bcb8ae..9e996410e 100644
--- a/services/agents/Dockerfile
+++ b/services/agents/Dockerfile
@@ -2,14 +2,57 @@ FROM python:3.11-slim
WORKDIR /app
-RUN pip install poetry==1.7.1 && \
- poetry config virtualenvs.create false
+# System deps occasionally needed by transitive packages (qdrant fastembed,
+# weasyprint, etc.). Keep the list small; expand only when poetry resolution
+# proves a missing system library is required.
+RUN apt-get update && apt-get install -y --no-install-recommends \
+ build-essential \
+ && rm -rf /var/lib/apt/lists/*
+
+RUN pip install --no-cache-dir poetry==1.7.1 \
+ && poetry config virtualenvs.create false
COPY pyproject.toml poetry.lock* ./
-RUN poetry install --no-interaction --no-ansi --no-dev 2>/dev/null || \
- pip install fastapi uvicorn[standard] langgraph langchain langchain-core \
- langchain-openai openai redis[hiredis] httpx structlog \
- prometheus-client python-dateutil aiokafka pydantic pydantic-settings
+
+# Run poetry without swallowing errors. If resolution fails for any reason
+# (network blip, transient registry timeout, etc.) we fall through to a
+# complete pip install that mirrors pyproject.toml so the image still ships
+# a working agents service. The previous fallback omitted opentelemetry-*
+# and a handful of other deps, producing images that crashed on import.
+RUN set -eux; \
+ if poetry install --no-interaction --no-ansi --without dev --no-root; then \
+ echo "[agents] poetry install succeeded"; \
+ else \
+ echo "[agents] poetry install failed; using pip fallback"; \
+ pip install --no-cache-dir \
+ "fastapi>=0.109,<0.110" \
+ "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" \
+ "openai>=1.12,<2" \
+ "redis[hiredis]>=5.0,<6" \
+ "httpx>=0.26,<0.27" \
+ "structlog>=24,<25" \
+ "prometheus-client>=0.19,<0.20" \
+ "python-dateutil>=2.8,<3" \
+ "aiokafka>=0.10,<0.11" \
+ "qdrant-client[fastembed]>=1.9,<2" \
+ "markdown>=3.5,<4" \
+ "opentelemetry-sdk>=1.24,<2" \
+ "opentelemetry-instrumentation-fastapi>=0.45b0" \
+ "opentelemetry-instrumentation-httpx>=0.45b0" \
+ "asyncpg>=0.29,<0.30" \
+ "sqlalchemy[asyncio]>=2.0.25,<3" ; \
+ fi
+
+# 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"
COPY app/ ./app/
diff --git a/services/agents/app/api/playbooks.py b/services/agents/app/api/playbooks.py
index 583ddcd07..7b9a59ded 100644
--- a/services/agents/app/api/playbooks.py
+++ b/services/agents/app/api/playbooks.py
@@ -79,7 +79,7 @@ async def update_playbook(playbook_id: str, data: dict[str, Any]) -> dict:
return updated.model_dump()
[email protected]("/{playbook_id}", summary="Delete a playbook", status_code=204)
[email protected]("/{playbook_id}", summary="Delete a playbook", status_code=204, response_model=None)
async def delete_playbook(playbook_id: str) -> None:
store = PlaybookStore.default()
if not store.delete(playbook_id):
diff --git a/services/agents/app/playbook/store.py b/services/agents/app/playbook/store.py
index 8c51a7419..568e97c05 100644
--- a/services/agents/app/playbook/store.py
+++ b/services/agents/app/playbook/store.py
@@ -27,9 +27,29 @@ logger = logging.getLogger("aisoc.playbook.store")
_DEFAULT_STORE_DIR = Path(__file__).parent.parent.parent / "data" / "playbooks"
-# services/agents/app/playbook/store.py -> services/agents/app/playbook ->
-# services/agents/app -> services/agents -> services -> repo root
-_REPO_ROOT = Path(__file__).resolve().parents[4]
+
+def _resolve_repo_root() -> Path:
+ """Best-effort repo root resolution.
+
+ On the host the file lives at ``services/agents/app/playbook/store.py``
+ so the repo root is ``parents[4]``. Inside the agents Docker image the
+ code is copied to ``/app/app/playbook/store.py`` and only ``parents[2]``
+ exists. We walk up while the index is in range and treat the first
+ ancestor that contains a ``playbooks`` directory as the root; otherwise
+ we fall back to the deepest available ancestor.
+ """
+ here = Path(__file__).resolve()
+ candidates = list(here.parents)
+ for candidate in candidates:
+ if (candidate / "playbooks" / "packs").is_dir():
+ return candidate
+ # Prefer the conventional host layout when available.
+ if len(candidates) > 4:
+ return candidates[4]
+ return candidates[-1]
+
+
+_REPO_ROOT = _resolve_repo_root()
_DEFAULT_PACK_ROOT = _REPO_ROOT / "playbooks" / "packs" / "v1"
diff --git a/services/api/app/api/v1/endpoints/api_keys.py b/services/api/app/api/v1/endpoints/api_keys.py
index 907d810dd..7ec854136 100644
--- a/services/api/app/api/v1/endpoints/api_keys.py
+++ b/services/api/app/api/v1/endpoints/api_keys.py
@@ -247,7 +247,7 @@ async def update_api_key(
return _api_key_to_out(ak)
[email protected]("/{key_id}", status_code=status.HTTP_204_NO_CONTENT)
[email protected]("/{key_id}", status_code=status.HTTP_204_NO_CONTENT, response_model=None)
async def revoke_api_key(
key_id: uuid.UUID,
db: DBSession,
diff --git a/services/api/app/api/v1/endpoints/connectors.py b/services/api/app/api/v1/endpoints/connectors.py
index 287a91494..f57b9c94c 100644
--- a/services/api/app/api/v1/endpoints/connectors.py
+++ b/services/api/app/api/v1/endpoints/connectors.py
@@ -130,7 +130,7 @@ async def update_connector(
return ConnectorResponse.model_validate(connector)
[email protected]("/{connector_id}", status_code=status.HTTP_204_NO_CONTENT)
[email protected]("/{connector_id}", status_code=status.HTTP_204_NO_CONTENT, response_model=None)
async def delete_connector(
connector_id: uuid.UUID,
current_user: Annotated[AuthUser, Depends(require_permission("connectors:delete"))],
diff --git a/services/api/app/api/v1/endpoints/detection_rules.py b/services/api/app/api/v1/endpoints/detection_rules.py
index 02d4efafa..8b1a08c53 100644
--- a/services/api/app/api/v1/endpoints/detection_rules.py
+++ b/services/api/app/api/v1/endpoints/detection_rules.py
@@ -177,7 +177,7 @@ async def update_rule(
return DetectionRuleResponse.model_validate(rule)
[email protected]("/{rule_id}", status_code=status.HTTP_204_NO_CONTENT)
[email protected]("/{rule_id}", status_code=status.HTTP_204_NO_CONTENT, response_model=None)
async def delete_rule(
rule_id: uuid.UUID,
current_user: Annotated[AuthUser, Depends(require_permission("rules:write"))],
diff --git a/services/api/app/api/v1/endpoints/marketplace.py b/services/api/app/api/v1/endpoints/marketplace.py
index e16c8b02e..cb85339c4 100644
--- a/services/api/app/api/v1/endpoints/marketplace.py
+++ b/services/api/app/api/v1/endpoints/marketplace.py
@@ -39,13 +39,14 @@ router = APIRouter(prefix="/marketplace", tags=["marketplace"])
# ── Locating the on-disk index ────────────────────────────────────────────────
-# This file lives at services/api/app/api/v1/endpoints/marketplace.py, so the
-# repo root is seven levels up (endpoints/v1/api/app/api/services/<root>).
-# Falling back to a couple of well-known absolute locations keeps things
-# working in containerised deploys where the index has been baked alongside
-# the API binary.
+# On the host this file lives at services/api/app/api/v1/endpoints/marketplace.py
+# so the repo root is six levels up. Inside the API Docker image only the
+# /app/app/... subtree is copied, so parents[6] would IndexError. We resolve
+# the deepest available ancestor and rely on the absolute container paths
+# below as a safety net.
_HERE = Path(__file__).resolve()
-_REPO_ROOT = _HERE.parents[6]
+_HERE_PARENTS = list(_HERE.parents)
+_REPO_ROOT = _HERE_PARENTS[6] if len(_HERE_PARENTS) > 6 else _HERE_PARENTS[-1]
_CANDIDATE_PATHS = [
_REPO_ROOT / "marketplace" / "index.json",
_REPO_ROOT / "apps" / "web" / "public" / "marketplace" / "index.json",
diff --git a/services/api/app/api/v1/endpoints/passkeys.py b/services/api/app/api/v1/endpoints/passkeys.py
index fe2f25bba..1532eefa5 100644
--- a/services/api/app/api/v1/endpoints/passkeys.py
+++ b/services/api/app/api/v1/endpoints/passkeys.py
@@ -477,7 +477,7 @@ async def list_my_credentials(
return CredentialsListResponse(items=[PasskeyCredentialOut.model_validate(r) for r in rows])
[email protected]("/credentials/{credential_id}", status_code=status.HTTP_204_NO_CONTENT)
[email protected]("/credentials/{credential_id}", status_code=status.HTTP_204_NO_CONTENT, response_model=None)
async def revoke_credential(
credential_id: uuid.UUID,
user: AuthUser,
diff --git a/services/api/app/api/v1/endpoints/playbooks.py b/services/api/app/api/v1/endpoints/playbooks.py
index 52b7926ea..d7869111e 100644
--- a/services/api/app/api/v1/endpoints/playbooks.py
+++ b/services/api/app/api/v1/endpoints/playbooks.py
@@ -71,7 +71,7 @@ async def update_playbook(playbook_id: str, request: Request):
return await _proxy("PUT", f"/{playbook_id}", json=body)
[email protected]("/{playbook_id}", summary="Delete a playbook", status_code=204)
[email protected]("/{playbook_id}", summary="Delete a playbook", status_code=204, response_model=None)
async def delete_playbook(playbook_id: str):
await _proxy("DELETE", f"/{playbook_id}")
diff --git a/services/api/app/api/v1/endpoints/plugins.py b/services/api/app/api/v1/endpoints/plugins.py
index bd21306d4..af8f5090c 100644
--- a/services/api/app/api/v1/endpoints/plugins.py
+++ b/services/api/app/api/v1/endpoints/plugins.py
@@ -163,7 +163,7 @@ async def reload_plugin(
return _to_plugin_out(_mgr().get_plugin(plugin_id)) # type: ignore[arg-type]
[email protected]("/{plugin_id}", status_code=status.HTTP_204_NO_CONTENT)
[email protected]("/{plugin_id}", status_code=status.HTTP_204_NO_CONTENT, response_model=None)
async def unload_plugin(
plugin_id: str,
_: Annotated[AuthUser, Depends(require_permission("plugins:admin"))] = None,
diff --git a/services/api/app/api/v1/endpoints/rbac.py b/services/api/app/api/v1/endpoints/rbac.py
index 5bf961bfb..c79e4b64d 100644
--- a/services/api/app/api/v1/endpoints/rbac.py
+++ b/services/api/app/api/v1/endpoints/rbac.py
@@ -222,7 +222,7 @@ async def update_role(
)
[email protected]("/roles/{role_id}", status_code=status.HTTP_204_NO_CONTENT)
[email protected]("/roles/{role_id}", status_code=status.HTTP_204_NO_CONTENT, response_model=None)
async def delete_role(
role_id: uuid.UUID,
current_user: Annotated[AuthUser, Depends(require_permission("roles:write"))],
@@ -288,7 +288,7 @@ async def assign_role(
return UserRoleOut(user_id=user_id, role_id=role.id, role_name=role.name)
[email protected]("/users/{user_id}/roles/{role_id}", status_code=status.HTTP_204_NO_CONTENT)
[email protected]("/users/{user_id}/roles/{role_id}", status_code=status.HTTP_204_NO_CONTENT, response_model=None)
async def revoke_role(
user_id: uuid.UUID,
role_id: uuid.UUID,
diff --git a/services/api/app/core/config.py b/services/api/app/core/config.py
index b31186c83..22e90fb6e 100644
--- a/services/api/app/core/config.py
+++ b/services/api/app/core/config.py
@@ -32,6 +32,16 @@ class Settings(BaseSettings):
env_file_encoding="utf-8",
case_sensitive=False,
extra="ignore",
+ # pydantic-settings v2 attempts to JSON-decode environment variables
+ # whose annotation is a complex type (list/dict/...) BEFORE any
+ # ``field_validator(mode="before")`` runs. That breaks our documented
+ # convention of comma-separated values for fields like ``CORS_ORIGINS``
+ # (e.g. ``CORS_ORIGINS=http://localhost:3000``). Disabling decoding
+ # makes the raw string flow into the validator unchanged, which then
+ # parses the comma-separated form. Operators who prefer JSON syntax
+ # can still pass ``["..."]`` via the .env file pathway because the
+ # validator falls through for non-string inputs.
+ enable_decoding=False,
)
# App
diff --git a/services/api/pyproject.toml b/services/api/pyproject.toml
index 7a9bcc56c..5f014c152 100644
--- a/services/api/pyproject.toml
+++ b/services/api/pyproject.toml
@@ -10,7 +10,7 @@ readme = "README.md"
python = "^3.11"
fastapi = "^0.111.0"
uvicorn = { version = "^0.29.0", extras = ["standard"] }
-pydantic = "^2.7.0"
+pydantic = ">=2.7,<2.11"
pydantic-settings = "^2.2.1"
sqlalchemy = { version = "^2.0.30", extras = ["asyncio"] }
asyncpg = "^0.29.0"
diff --git a/services/honeytokens/app/api/routes.py b/services/honeytokens/app/api/routes.py
index af69c54c2..97f7411a5 100644
--- a/services/honeytokens/app/api/routes.py
+++ b/services/honeytokens/app/api/routes.py
@@ -148,7 +148,7 @@ async def revoke_token(token_id: uuid.UUID, db: DB) -> TokenOut:
return TokenOut.model_validate(token)
[email protected]("/{token_id}", status_code=204)
[email protected]("/{token_id}", status_code=204, response_model=None)
async def delete_token(token_id: uuid.UUID, db: DB) -> None:
result = await db.execute(select(Honeytoken).where(Honeytoken.id == token_id))
token = result.scalar_one_or_none()
diff --git a/services/realtime/src/index.ts b/services/realtime/src/index.ts
index 6bff07bcc..d83b8790c 100644
--- a/services/realtime/src/index.ts
+++ b/services/realtime/src/index.ts
@@ -292,7 +292,7 @@ app.post('/internal/agent-event', (req, res) => {
) {
const approvalId =
(data && (data.approval_id as string | undefined)) ?? run_id;
- const caseId = data && (data.case_id as string | undefined);
+ const caseId = (data?.case_id as string | undefined) ?? undefined;
const userIds =
data &&
(data.notify_user_ids as string[] | undefined) instanceof Array