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
fix(infra): dual-stack IPv4/IPv6 listeners + bake internal Fly DNS into web build
Beenu Arorae69f51a2a8e6
diff --git a/infra/fly/web/fly.toml b/infra/fly/web/fly.tomlindex 3b703476e..64e1a3fe9 100644--- a/infra/fly/web/fly.toml+++ b/infra/fly/web/fly.toml@@ -43,6 +43,18 @@ kill_timeout = "5s"[build.args]NEXT_PUBLIC_API_URL = "https://api.tryaisoc.com"NEXT_PUBLIC_WS_URL = "wss://ws.tryaisoc.com"+ # Server-side proxy targets MUST be passed at build time, not just runtime.+ # next.config.js evaluates `process.env.API_URL` when the config module+ # loads, and the resulting rewrite destinations are written into+ # .next/routes-manifest.json by `next build`. If these aren't set during+ # the build the Dockerfile defaults (http://api:8000 etc., for the local+ # docker-compose stack) bleed through and `next start` proxies to a host+ # that doesn't exist in Fly's 6PN DNS — the browser sees `Internal Server+ # Error` from the same-origin /api/v1/* routes even though api.tryaisoc.com+ # is healthy.+ API_URL = "http://aisoc-demo-api.internal:8000"+ AGENTS_URL = "http://aisoc-demo-agents.internal:8084"+ REALTIME_URL = "http://aisoc-demo-realtime.internal:4000"[env]NODE_ENV = "production"diff --git a/services/agents/Dockerfile b/services/agents/Dockerfileindex dcb42a07e..18fae86f2 100644--- a/services/agents/Dockerfile+++ b/services/agents/Dockerfile@@ -60,4 +60,7 @@ COPY app/ ./app/EXPOSE 8084-CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8084"]+# Dual-stack entrypoint — see app/scripts/serve.py and the matching CMD in+# services/api/Dockerfile for the full rationale (Python's asyncio forces+# IPV6_V6ONLY=1 on `::` binds, which breaks Fly's IPv4 health checks).+CMD ["python", "-m", "app.scripts.serve"]diff --git a/services/agents/app/scripts/__init__.py b/services/agents/app/scripts/__init__.pynew file mode 100644index 000000000..e69de29bbdiff --git a/services/agents/app/scripts/serve.py b/services/agents/app/scripts/serve.pynew file mode 100644index 000000000..66badb6da--- /dev/null+++ b/services/agents/app/scripts/serve.py@@ -0,0 +1,40 @@+"""Dual-stack uvicorn entrypoint for the agents service.++See ``services/api/app/scripts/serve.py`` for the full rationale. Short+version: Python's asyncio sets ``IPV6_V6ONLY=1`` on IPv6 sockets, which+breaks Fly.io health checks (IPv4) when we bind to ``::``. Pre-binding a+dual-stack socket and handing the fd to uvicorn fixes both 6PN (IPv6)+and the fly-proxy edge (IPv4) at once.+"""+from __future__ import annotations++import os+import socket+import sys+++def main() -> None:+ port = int(os.environ.get("PORT", "8084"))++ sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)+ sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)+ sock.bind(("::", port))+ sock.listen(128)+ os.set_inheritable(sock.fileno(), True)++ os.execvp(+ sys.executable,+ [+ sys.executable,+ "-m",+ "uvicorn",+ "app.main:app",+ "--fd",+ str(sock.fileno()),+ ],+ )+++if __name__ == "__main__":+ main()diff --git a/services/api/Dockerfile b/services/api/Dockerfileindex 426527ce9..3b8130133 100644--- a/services/api/Dockerfile+++ b/services/api/Dockerfile@@ -21,4 +21,13 @@ COPY . .EXPOSE 8000-CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]+# Use a tiny Python wrapper (app.scripts.serve) that pre-binds a dual-stack+# IPv6 socket with IPV6_V6ONLY=0 and hands the fd to uvicorn via --fd.+#+# Why not just `uvicorn --host ::`? Python's asyncio explicitly sets+# IPV6_V6ONLY=1 on IPv6 sockets it creates, so binding to "::" only accepts+# IPv6 connections. On Fly we need BOTH: IPv6 for 6PN private traffic+# (aisoc-demo-api.internal from the web app) AND IPv4 for fly-proxy's public+# /health checks against api.tryaisoc.com (which speak IPv4 to 127.0.0.1).+# Pre-binding lets us turn IPV6_V6ONLY off so a single socket serves both.+CMD ["python", "-m", "app.scripts.serve"]diff --git a/services/api/app/scripts/serve.py b/services/api/app/scripts/serve.pynew file mode 100644index 000000000..3ad81bdb1--- /dev/null+++ b/services/api/app/scripts/serve.py@@ -0,0 +1,56 @@+"""Dual-stack uvicorn entrypoint.++Why this exists:+ uvicorn's ``--host`` accepts a single string. If we pass ``::`` Python's+ asyncio explicitly sets ``IPV6_V6ONLY=1`` on the socket+ (see ``Lib/asyncio/base_events.py``), so the listener only accepts IPv6+ connections. On Fly.io we need both:++ * IPv6 — for 6PN private traffic (``aisoc-demo-api.internal:8000`` from+ sibling apps like the web Next.js rewriter), which routes via IPv6.+ * IPv4 — for ``fly-proxy``'s public health checks against+ ``api.tryaisoc.com/health``, which speak IPv4 to ``127.0.0.1:8000``.++ If we ``--host 0.0.0.0`` we lose 6PN reachability; if we ``--host ::``+ we lose the public health check (returns 503). The clean fix is to+ pre-bind a dual-stack socket with ``IPV6_V6ONLY=0`` and hand the file+ descriptor to uvicorn via ``--fd``.++This wrapper is the production CMD for the API container.+"""+from __future__ import annotations++import os+import socket+import sys+++def main() -> None:+ port = int(os.environ.get("PORT", "8000"))++ sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)+ # Allow IPv4-mapped IPv6 connections (dual-stack).+ sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)+ sock.bind(("::", port))+ sock.listen(128)+ # Sockets created via socket.socket() in Python 3.4+ are non-inheritable+ # (close-on-exec). uvicorn re-opens the fd after exec, so we must mark+ # the descriptor as inheritable before handing off.+ os.set_inheritable(sock.fileno(), True)++ os.execvp(+ sys.executable,+ [+ sys.executable,+ "-m",+ "uvicorn",+ "app.main:app",+ "--fd",+ str(sock.fileno()),+ ],+ )+++if __name__ == "__main__":+ main()diff --git a/services/connectors/Dockerfile b/services/connectors/Dockerfileindex 47b8b803c..f4b4bb00e 100644--- a/services/connectors/Dockerfile+++ b/services/connectors/Dockerfile@@ -14,4 +14,5 @@ COPY app/ ./app/EXPOSE 8087-CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8087"]+# Dual-stack entrypoint (IPv6 + IPv4-mapped). See app/scripts/serve.py.+CMD ["python", "-m", "app.scripts.serve"]diff --git a/services/connectors/app/scripts/__init__.py b/services/connectors/app/scripts/__init__.pynew file mode 100644index 000000000..e69de29bbdiff --git a/services/connectors/app/scripts/serve.py b/services/connectors/app/scripts/serve.pynew file mode 100644index 000000000..dc7873172--- /dev/null+++ b/services/connectors/app/scripts/serve.py@@ -0,0 +1,36 @@+"""Dual-stack uvicorn entrypoint for the connectors service.++See ``services/api/app/scripts/serve.py`` for the full rationale.+"""+from __future__ import annotations++import os+import socket+import sys+++def main() -> None:+ port = int(os.environ.get("PORT", "8087"))++ sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)+ sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)+ sock.bind(("::", port))+ sock.listen(128)+ os.set_inheritable(sock.fileno(), True)++ os.execvp(+ sys.executable,+ [+ sys.executable,+ "-m",+ "uvicorn",+ "app.main:app",+ "--fd",+ str(sock.fileno()),+ ],+ )+++if __name__ == "__main__":+ main()diff --git a/services/realtime/src/index.ts b/services/realtime/src/index.tsindex 107dac1df..59f94c851 100644--- a/services/realtime/src/index.ts+++ b/services/realtime/src/index.ts@@ -397,8 +397,12 @@ app.get('/health', reportHealth);app.get('/healthz', reportHealth);// --- Start ----server.listen(PORT, async () => {- log.info({ port: PORT }, 'AiSOC Real-time service started');+// Bind to "::" so we are reachable over Fly.io's 6PN private network (IPv6).+// Node defaults to "::" when IPv6 is available, but be explicit to match the+// other services and avoid surprises if a future Node release changes the+// default or the container is launched with IPv6 disabled.+server.listen(PORT, '::', async () => {+ log.info({ port: PORT, host: '::' }, 'AiSOC Real-time service started');try {await startKafkaConsumer();} catch (err) {