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(deploy): close the surface the production compose left open (#947)

Beenu Arora7c62a5017f48
diff --git a/apps/docs/docs/deployment/docker.md b/apps/docs/docs/deployment/docker.md
index af845db84..f6b31a057 100644
--- a/apps/docs/docs/deployment/docker.md
+++ b/apps/docs/docs/deployment/docker.md
@@ -132,10 +132,13 @@ matter:
- **Nothing starts on a default credential.** Every secret is declared
`${VAR:?...}`, so Compose refuses to start and names the variable rather than
booting on a literal published in this repository and looking healthy.
-- **No datastore is bound to the host.** Postgres, Redis, Kafka, Qdrant, Neo4j,
- ClickHouse and OpenSearch publish no ports. `kafka-ui` browses every topic
- with no authentication of its own, so `--profile full` does not start it —
- ask for it by name with `--profile debug-ui` if you want it.
+- **Only the console and the ingest endpoint are reachable.** `web` on `:3000`
+ and `ingest-worker` on `:8081`, and nothing else — not the datastores, not
+ the internal services, not Prometheus or Grafana. The console proxies every
+ upstream server-side, so a browser never needs to reach them; use
+ `docker compose exec` if you need one for debugging. `kafka-ui` browses every
+ topic with no authentication of its own, so `--profile full` does not start
+ it — ask for it by name with `--profile debug-ui`.
CORE is 16 long-running services here, the same as development. `--profile full`
is 21 rather than 22, the difference being `kafka-ui`.
@@ -158,6 +161,13 @@ is 21 rather than 22, the difference being `kafka-ui`.
| `REDIS_PASSWORD` | no | Redis |
| `JWT_SECRET` | no | Ingest token signing |
| `NEO4J_PASSWORD`, `CLICKHOUSE_PASSWORD` | no | `full` profile stores |
+| `GRAFANA_ADMIN_PASSWORD` | no | `monitoring` profile dashboard |
+
+All of them are required even if you only run CORE, where the last three are
+unused: Compose interpolates the whole file before it decides which profile is
+active, so it cannot ask for a variable conditionally. Setting them to any
+value is fine if you never enable those profiles — the alternative is Grafana
+starting on `admin`/`admin` the day somebody adds `--profile monitoring`.
Put a TLS-terminating reverse proxy in front: the console and ingest bind to
loopback unless you set `AISOC_BIND_ADDR` deliberately.
diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml
index ed6229bba..2bde2a6f7 100644
--- a/docker-compose.prod.yml
+++ b/docker-compose.prod.yml
@@ -78,6 +78,7 @@ services:
# lives, which is the defect this file exists to make impossible.
# ---------------------------------------------------------------------------
api:
+ ports: !reset []
restart: unless-stopped
environment:
ENVIRONMENT: production
@@ -101,6 +102,7 @@ services:
CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD:?set CLICKHOUSE_PASSWORD}
ingest-worker:
+ ports: !override ["${AISOC_BIND_ADDR:-127.0.0.1}:8081:8080"]
restart: unless-stopped
environment:
# Both keys, because `envmode.Current()` reads ENV first and the base
@@ -116,6 +118,7 @@ services:
AISOC_NEO4J_PASSWORD: ${NEO4J_PASSWORD:?set NEO4J_PASSWORD}
fusion:
+ ports: !reset []
restart: unless-stopped
environment:
ENVIRONMENT: production
@@ -124,6 +127,7 @@ services:
CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD:?set CLICKHOUSE_PASSWORD}
agents:
+ ports: !reset []
restart: unless-stopped
environment:
ENVIRONMENT: production
@@ -133,6 +137,7 @@ services:
NEO4J_PASSWORD: ${NEO4J_PASSWORD:?set NEO4J_PASSWORD}
actions:
+ ports: !reset []
restart: unless-stopped
environment:
ENVIRONMENT: production
@@ -143,6 +148,7 @@ services:
AISOC_ACTIONS_SERVICE_TOKEN: ${AISOC_ACTIONS_SERVICE_TOKEN:?set AISOC_ACTIONS_SERVICE_TOKEN}
connectors:
+ ports: !reset []
restart: unless-stopped
environment:
ENVIRONMENT: production
@@ -152,6 +158,7 @@ services:
SECRET_KEY: ${SECRET_KEY:?set SECRET_KEY}
threatintel:
+ ports: !reset []
restart: unless-stopped
environment:
ENVIRONMENT: production
@@ -159,6 +166,7 @@ services:
NEO4J_PASSWORD: ${NEO4J_PASSWORD:?set NEO4J_PASSWORD}
realtime:
+ ports: !reset []
restart: unless-stopped
environment:
# Unset, the edge rejects every connection and /internal/* answers 503.
@@ -168,9 +176,11 @@ services:
REALTIME_INTERNAL_TOKEN: ${REALTIME_INTERNAL_TOKEN:?set REALTIME_INTERNAL_TOKEN — run `make env` to generate it}
litellm:
+ ports: !reset []
restart: unless-stopped
ollama:
+ ports: !reset []
restart: unless-stopped
# The console. Demo mode is inlined at build time by Next, so this asserts
@@ -211,3 +221,61 @@ services:
kafka-ui:
profiles: !override ["debug-ui"]
ports: !reset []
+ # `no`, not `unless-stopped`: this is a tool you bring up to look at
+ # something and shut down again. Restarting it on boot would quietly leave
+ # an unauthenticated topic browser running next to production data.
+ restart: "no"
+
+ # ---------------------------------------------------------------------------
+ # HARDENING.md section 2 — transport and network surface.
+ #
+ # Profiled services that bind a host port in the development file. The
+ # console and the ingest endpoint are the only things that need to be
+ # reachable: apps/web/next.config.js proxies every upstream server-side, so
+ # a browser only ever talks to `web`. Reach these with `docker compose exec`
+ # for debugging, or publish one deliberately in a local override.
+ # ---------------------------------------------------------------------------
+ alertmanager:
+ ports: !reset []
+ restart: unless-stopped
+
+ enrichment:
+ ports: !reset []
+
+ honeytokens:
+ ports: !reset []
+
+ osquery-tls:
+ ports: !reset []
+
+ otel-collector:
+ ports: !reset []
+ restart: unless-stopped
+
+ prometheus:
+ ports: !reset []
+ restart: unless-stopped
+
+ purple-team:
+ ports: !reset []
+
+ slack-bot:
+ ports: !reset []
+
+ tempo:
+ ports: !reset []
+ restart: unless-stopped
+
+ ueba:
+ ports: !reset []
+
+ # HARDENING.md section 5 — observability and audit.
+ #
+ # Grafana defaults to admin/admin in the development file. Required here, so
+ # `--profile monitoring` cannot start a dashboard over production telemetry
+ # on a password printed in its own documentation.
+ grafana:
+ ports: !reset []
+ restart: unless-stopped
+ environment:
+ GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD:?set GRAFANA_ADMIN_PASSWORD — required for the monitoring profile}
diff --git a/tests/test_production_compose_gate.py b/tests/test_production_compose_gate.py
index ef61dcc9a..4af62f605 100644
--- a/tests/test_production_compose_gate.py
+++ b/tests/test_production_compose_gate.py
@@ -162,6 +162,19 @@ class TestNothingStartsOnAPublishedCredential:
"a credential published in this repository looks healthy and is not"
)
+ def test_grafana_cannot_start_on_its_documented_default(self, prod: dict) -> None:
+ """`GF_SECURITY_ADMIN_PASSWORD` defaults to `admin` in development.
+
+ Grafana is on the `monitoring` profile, so it is not in CORE — which
+ is exactly why the first pass of this file missed it. A profiled
+ service is still a production service the moment someone asks for the
+ profile, and a dashboard over production telemetry on the password
+ printed in its own documentation is not a smaller problem for being
+ opt-in.
+ """
+ value = dict(_env_items(prod.get("grafana") or {})).get("GF_SECURITY_ADMIN_PASSWORD", "")
+ assert ":?" in value, f"grafana would start on a default admin password: {value!r}"
+
def test_no_dev_secret_literal_reaches_a_service(self, prod: dict) -> None:
"""Asserted on values, not on the file text.
@@ -178,6 +191,125 @@ class TestNothingStartsOnAPublishedCredential:
assert not leaked
+#: The only two things that need to be reachable from outside. The console
+#: proxies every upstream server-side (`apps/web/next.config.js` rewrites API,
+#: agents, fusion, realtime, enrichment and osquery-tls), so a browser only
+#: ever talks to `web`; `ingest-worker` accepts events from agents and SIEMs.
+REACHABLE = frozenset({"web", "ingest-worker"})
+
+
+def _publishers(services: dict) -> dict[str, list[str]]:
+ return {
+ name: [str(entry) for entry in (service or {}).get("ports") or []]
+ for name, service in services.items()
+ if (service or {}).get("ports")
+ }
+
+
+#: Services in the overlay whose `ports:` carries a Compose merge tag. Without
+#: one the value is *merged* with the base rather than replacing it, so a bare
+#: `ports: []` reads as "change nothing" and the inherited binding survives —
+#: which is exactly what happened on the first attempt at this file.
+_TAGGED_PORTS = re.compile(r"^ ([a-z0-9-]+):\n(?: .*\n)*? ports: (![a-z]+)", re.M)
+
+
+def _overlay_port_overrides() -> dict[str, str]:
+ """Which services override `ports`, and with which merge tag."""
+ text = PROD.read_text(encoding="utf-8")
+ tagged = dict(_TAGGED_PORTS.findall(text))
+ declared = {name for name, _ in re.findall(r"^ ([a-z0-9-]+):\n(?: .*\n)*? (ports:)", text, re.M)}
+ return {name: tagged.get(name, "") for name in declared}
+
+
+def _merged_services() -> dict:
+ """Base services with the overlay's port overrides applied.
+
+ The production file `include`s the base, so reading it alone sees only the
+ keys it restates — a check for "what publishes a port" would then miss
+ every binding the overlay never mentions, and pass while the stack exposes
+ them. Merged here rather than shelled out to `docker compose config`,
+ because a gate that needs a Docker daemon skips where there isn't one, and
+ a skip reports nothing while looking green.
+ """
+ merged = {name: dict(service or {}) for name, service in _services(DEV).items()}
+ overlay = _services(PROD)
+ overrides = _overlay_port_overrides()
+ for name, service in overlay.items():
+ target = merged.setdefault(name, {})
+ if "ports" in (service or {}) and name in overrides:
+ target["ports"] = (service or {}).get("ports") or []
+ for key, value in (service or {}).items():
+ if key != "ports":
+ target[key] = value
+ return merged
+
+
+class TestOnlyTheConsoleAndIngestAreReachable:
+ """The first pass of this file only unpublished the datastores.
+
+ Nineteen application and observability services were still bound to the
+ host — including Grafana on its documented admin/admin default — because
+ the assertion was written about datastores rather than about the surface.
+ A gate that names a category catches that category; the property wanted
+ here is the complement, so it is asserted as one.
+ """
+
+ def test_nothing_else_publishes_a_port(self) -> None:
+ extra = {n: p for n, p in _publishers(_merged_services()).items() if n not in REACHABLE}
+ assert not extra, f"these are reachable from the host and need not be: {extra}"
+
+ def test_the_two_that_should_be_reachable_still_are(self) -> None:
+ """The other direction. Unpublishing everything would pass the test
+ above and ship a deployment with no console and no way to send it
+ events."""
+ published = set(_publishers(_merged_services()))
+ assert published == REACHABLE, f"expected exactly {sorted(REACHABLE)}, found {sorted(published)}"
+
+ def test_every_port_override_carries_a_merge_tag(self) -> None:
+ """A bare `ports: []` merges instead of replacing, so it changes nothing.
+
+ This is not hypothetical: the first version of the production file used
+ `ports: []` throughout, `docker compose config` still showed Postgres,
+ Redis, Kafka and Qdrant bound to the host, and the file read as though
+ it had unpublished them.
+ """
+ untagged = [name for name, tag in _overlay_port_overrides().items() if not tag]
+ assert not untagged, f"these override `ports` without !reset or !override, so it does not apply: {untagged}"
+
+ def test_ingest_does_not_publish_its_metrics_listener(self) -> None:
+ """`ingest-worker` binds :8081 and :9090 in development. Prometheus
+ scrapes the second over the compose network, so binding it to the host
+ exposes the counters and buys nothing."""
+ ports = _publishers(_merged_services()).get("ingest-worker", [])
+ assert len(ports) == 1, f"expected only the ingest endpoint, found {ports}"
+ assert "9090" not in str(ports[0])
+
+ def test_the_development_file_would_fail_this(self) -> None:
+ extra = {n for n in _publishers(_services(DEV)) if n not in REACHABLE}
+ assert extra, "docker-compose.yml publishes nothing extra, so this gate compares against nothing"
+
+
+class TestServicesComeBackAfterAReboot:
+ """A production stack that does not restart is a production stack that is
+ down until somebody notices.
+
+ Checked across the merged file rather than the overlay, because the five
+ that lacked a policy — Prometheus, Alertmanager, Tempo, the OTel collector
+ and kafka-ui — were all services the overlay only touched to unpublish.
+ """
+
+ def test_every_service_declares_a_restart_policy(self) -> None:
+ merged = _merged_services()
+ missing = [name for name, service in merged.items() if not (service or {}).get("restart")]
+ assert not missing, f"these would stay down after a crash or reboot: {missing}"
+
+ def test_the_debug_topic_browser_is_not_one_of_them(self) -> None:
+ """kafka-ui is deliberately `no`: it is brought up to look at something
+ and shut down again, and restarting it on boot would leave an
+ unauthenticated topic browser running beside production data."""
+ assert str((_merged_services().get("kafka-ui") or {}).get("restart")) == "no"
+
+
class TestNoDatastoreIsBoundToTheHost:
def test_production_publishes_no_datastore(self, prod: dict) -> None:
assert not _published_datastores(prod)