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): refresh the images when the tag they name can move (#976)

Beenu Arorac32fead0291f
diff --git a/.env.example b/.env.example
index 2004bea71..a595f787c 100644
--- a/.env.example
+++ b/.env.example
@@ -27,11 +27,22 @@
# ─── Image Pinning ────────────────────────────────────────────────────────────
# Tag pulled by every `image: ghcr.io/beenuar/aisoc-*:${AISOC_VERSION:-latest}`
-# in docker-compose.yml. With `pull_policy: missing`, Docker will pull this tag
-# on first boot and skip the local build (~90 s vs ~15 min). Pin to a release
-# tag (e.g. v7.2.0) for reproducible deploys; leave as `latest` to track main.
+# in docker-compose.yml. Docker pulls this tag on first boot and skips the
+# local build (~90 s vs ~15 min). Pin to a release tag (e.g. v12.0.0) for
+# reproducible deploys; leave as `latest` to track the newest release.
AISOC_VERSION=latest
+# What `pull_policy:` resolves to for every first-party image. `missing` means
+# "use what is local if there is one", which is right for an immutable release
+# tag and wrong for `latest`, which is republished on every merge — so
+# `make up` refreshes the images itself whenever AISOC_VERSION names a moving
+# tag, and skips it when the tag is pinned.
+#
+# Set this to `never` on an air-gapped host: Compose then refuses to contact a
+# registry, and `make up` skips its refresh for the same reason. `always` makes
+# Compose itself re-check on every container start.
+# AISOC_PULL_POLICY=never
+
# ─── Core Configuration ───────────────────────────────────────────────────────
# `development` enables the dev auth bypass in services/api/app/api/v1/dev_auth.py.
# Set `production` for anything network-reachable; docker-compose.yml reads this
diff --git a/Makefile b/Makefile
index d094cba01..237e52135 100644
--- a/Makefile
+++ b/Makefile
@@ -44,7 +44,7 @@ PROFILE_ARG := $(if $(PROFILE),--profile $(PROFILE),)
CONSOLE_URL = $(shell sed -n 's/^AISOC_CONSOLE_URL=//p' .env 2>/dev/null | tail -n1 | tr -d '\r')
console_url = $(if $(strip $(CONSOLE_URL)),$(strip $(CONSOLE_URL)),http://localhost:3000)
-.PHONY: help install env up up-full down restart status doctor smoke demo logs clean \
+.PHONY: help install env up up-full pull down restart status doctor smoke demo logs clean \
bootstrap ingest-token test test-unit test-integration test-e2e stats papers \
papers-install demo-script
@@ -60,8 +60,13 @@ help:
@echo " make smoke Push one real event through the pipeline and check it becomes an alert"
@echo " make doctor Diagnose the deployment and say what to fix"
@echo ""
+ @echo " Upgrading"
+ @echo " git pull && make up Fetches new images when AISOC_VERSION is a moving tag"
+ @echo " (the default). A pinned release is immutable and is not refetched."
+ @echo ""
@echo " Running it"
@echo " make status Show every service and its health"
+ @echo " make pull Refresh the images (what \`make up\` does on a moving tag)"
@echo " make logs Follow logs (SERVICE=fusion to narrow)"
@echo " make restart Restart the stack"
@echo " make down Stop the stack, keep the data"
@@ -94,7 +99,7 @@ env:
# allocated` against whichever container lost the race, which names neither the
# process holding the port nor what to do about it. Half the stack is running
# by then, so the error also arrives after a minute of unrelated output.
-up: env _ports
+up: env _ports _refresh
$(COMPOSE) up -d
@echo ""
@echo "Waiting for services to become healthy…"
@@ -134,7 +139,7 @@ bootstrap:
# 8123 stopped the stack after eight containers had already started, with
# `Bind for 0.0.0.0:8123 failed: port is already allocated` naming neither the
# process holding it nor what to do.
-up-full: env _ports
+up-full: env _ports _refresh
AISOC_LAKE_WRITER_ENABLED=true AISOC_GRAPH_ENABLED=true $(COMPOSE) --profile full up -d
@$(MAKE) --no-print-directory _wait PROFILE=full
@echo ""
@@ -144,6 +149,45 @@ up-full: env _ports
@echo "Prove the pipeline works: make smoke"
@$(MAKE) --no-print-directory bootstrap
+# Refreshes the images when the tag they name can move.
+#
+# `pull_policy: missing` is correct for a pinned tag — `v12.0.0` is immutable,
+# so once it is local there is nothing to fetch — and wrong for `latest`, which
+# is republished on every merge to main. With `AISOC_VERSION=latest` (the
+# default) and `missing` on all fifteen first-party services, `git pull &&
+# make up` ran brand-new compose configuration against whatever images the
+# machine happened to have. Nothing anywhere told an operator to pull.
+#
+# Measured: a stack whose images were pulled at 08:14 UTC stayed on them
+# across `make up` while `ghcr.io/beenuar/aisoc-web:latest` had been
+# republished at 15:29 UTC, seven commits later. The revision label says so,
+# and nothing in the output did.
+#
+# So this pulls when the tag can move and does nothing when it cannot:
+#
+# * a first run downloads the same bytes either way, so it costs nothing;
+# * a warm run on `latest` spends ~25s on manifest checks and gets the fix
+# the operator just pulled, which is the point;
+# * a pinned `AISOC_VERSION` skips it entirely and prints why;
+# * `AISOC_PULL_POLICY=never` (also honoured by compose itself) skips it,
+# for an air-gapped host that must never reach a registry.
+_refresh:
+ @version="$${AISOC_VERSION:-$$(sed -n 's/^AISOC_VERSION=//p' .env 2>/dev/null | tail -1)}"; \
+ version="$${version:-latest}"; \
+ policy="$${AISOC_PULL_POLICY:-$$(sed -n 's/^AISOC_PULL_POLICY=//p' .env 2>/dev/null | tail -1)}"; \
+ if [ "$$policy" = "never" ]; then \
+ echo "AISOC_PULL_POLICY=never — not contacting a registry; running whatever is local."; \
+ elif [ "$$version" = "latest" ] || [ "$$version" = "main" ] || [ "$$version" = "edge" ]; then \
+ echo "AISOC_VERSION=$$version is a moving tag — refreshing images (pin a release to skip this)."; \
+ $(COMPOSE) $(PROFILE_ARG) pull --quiet || echo " (pull failed — continuing with the local images)"; \
+ else \
+ echo "AISOC_VERSION=$$version is pinned and immutable — nothing to refresh."; \
+ fi
+
+# The same refresh on its own, for an operator who wants to fetch now and
+# start later, or who is diagnosing a version mismatch.
+pull: _refresh
+
# Names a port conflict before compose hits it. Silent when every port is
# either free or already held by this deployment's own containers — re-running
# `make up` on a running stack must not be reported as a conflict with itself.
diff --git a/apps/docs/docs/deployment/docker.md b/apps/docs/docs/deployment/docker.md
index 0a52e6b1f..e65fc9bf7 100644
--- a/apps/docs/docs/deployment/docker.md
+++ b/apps/docs/docs/deployment/docker.md
@@ -225,6 +225,45 @@ ghcr.io/beenuar/aisoc-web:<version>
| `main` | The newest commit on `main`. | Anyone tracking the tip |
| `vX.Y.Z-demo`, `demo` | `aisoc-web` only: the console built for a public demo. | `infra/compose/docker-compose.demo.yml` |
+### Upgrading
+
+```bash
+git pull
+make up
+```
+
+`make up` refreshes the images **when the tag they name can move**. Compose's
+`pull_policy: missing` is right for a pinned release — `v12.0.0` is immutable,
+so once it is local there is nothing to fetch — and wrong for `latest`, which
+is republished on every merge. Until this was wired, `git pull && make up` ran
+brand-new compose configuration against whatever images the machine already
+had, and nothing in the output said so: a stack whose images were pulled at
+08:14 UTC stayed on them while `ghcr.io/beenuar/aisoc-web:latest` had been
+republished at 15:29 UTC, seven commits later.
+
+What that means in practice:
+
+- **A first run costs nothing extra.** There are no images yet, so the same
+ bytes are downloaded either way.
+- **A warm run on `latest` spends a few seconds** on manifest checks and then
+ runs the code you just pulled.
+- **A pinned `AISOC_VERSION` skips it** and says so — there is nothing to
+ refresh behind an immutable tag.
+- **`AISOC_PULL_POLICY=never` skips it too**, and is also honoured by Compose
+ itself, so an air-gapped host never reaches a registry.
+
+`make pull` does the refresh on its own, for fetching now and starting later.
+
+To see what is actually running:
+
+```bash
+docker image inspect ghcr.io/beenuar/aisoc-web:latest \
+ --format '{{index .Config.Labels "org.opencontainers.image.revision"}}'
+```
+
+That is the commit the image was built from. If it does not match the commit
+you have checked out, the console is not running your code.
+
The demo tags exist because the console's demo mode is a **build-time** choice,
not a runtime one: Next.js inlines `NEXT_PUBLIC_*` values into the client
bundle during `next build`, so an image built for a demo cannot be turned back
diff --git a/docker-compose.yml b/docker-compose.yml
index 354dfabe7..63d154574 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -349,7 +349,7 @@ services:
context: ./services/api
dockerfile: Dockerfile
image: ghcr.io/beenuar/aisoc-core-api:${AISOC_VERSION:-latest}
- pull_policy: missing
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
container_name: aisoc-api
depends_on:
postgres:
@@ -475,7 +475,7 @@ services:
context: ./services/ingest
dockerfile: Dockerfile
image: ghcr.io/beenuar/aisoc-ingest:${AISOC_VERSION:-latest}
- pull_policy: missing
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
container_name: aisoc-ingest
depends_on:
kafka:
@@ -534,7 +534,7 @@ services:
context: ./services/enrichment
dockerfile: Dockerfile
image: ghcr.io/beenuar/aisoc-enrichment:${AISOC_VERSION:-latest}
- pull_policy: missing
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
container_name: aisoc-enrichment
depends_on:
redis:
@@ -559,7 +559,7 @@ services:
context: ./services/fusion
dockerfile: Dockerfile
image: ghcr.io/beenuar/aisoc-fusion:${AISOC_VERSION:-latest}
- pull_policy: missing
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
container_name: aisoc-fusion
depends_on:
# Postgres was missing here, so during a cold boot fusion tried to write
@@ -601,7 +601,7 @@ services:
context: ./services/agents
dockerfile: Dockerfile
image: ghcr.io/beenuar/aisoc-agents:${AISOC_VERSION:-latest}
- pull_policy: missing
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
container_name: aisoc-agents
depends_on:
postgres:
@@ -785,7 +785,7 @@ services:
context: ./services/osquery-tls
dockerfile: Dockerfile
image: ghcr.io/beenuar/aisoc-osquery-tls:${AISOC_VERSION:-latest}
- pull_policy: missing
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
container_name: aisoc-osquery-tls
depends_on:
postgres:
@@ -854,7 +854,7 @@ services:
context: ./services/actions
dockerfile: Dockerfile
image: ghcr.io/beenuar/aisoc-actions:${AISOC_VERSION:-latest}
- pull_policy: missing
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
container_name: aisoc-actions
depends_on:
redis:
@@ -896,7 +896,7 @@ services:
context: ./services/connectors
dockerfile: Dockerfile
image: ghcr.io/beenuar/aisoc-connectors:${AISOC_VERSION:-latest}
- pull_policy: missing
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
container_name: aisoc-connectors
depends_on:
kafka:
@@ -967,7 +967,7 @@ services:
context: ./services/threatintel
dockerfile: Dockerfile
image: ghcr.io/beenuar/aisoc-threatintel:${AISOC_VERSION:-latest}
- pull_policy: missing
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
container_name: aisoc-threatintel
depends_on:
redis:
@@ -1020,7 +1020,7 @@ services:
context: ./services/ueba
dockerfile: Dockerfile
image: ghcr.io/beenuar/aisoc-ueba:${AISOC_VERSION:-latest}
- pull_policy: missing
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
container_name: aisoc-ueba
depends_on:
postgres:
@@ -1076,7 +1076,7 @@ services:
context: ./services/honeytokens
dockerfile: Dockerfile
image: ghcr.io/beenuar/aisoc-honeytokens:${AISOC_VERSION:-latest}
- pull_policy: missing
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
container_name: aisoc-honeytokens
depends_on:
postgres:
@@ -1131,7 +1131,7 @@ services:
context: ./services/purple-team
dockerfile: Dockerfile
image: ghcr.io/beenuar/aisoc-purple-team:${AISOC_VERSION:-latest}
- pull_policy: missing
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
container_name: aisoc-purple-team
depends_on:
postgres:
@@ -1177,7 +1177,7 @@ services:
context: ./services/realtime
dockerfile: Dockerfile
image: ghcr.io/beenuar/aisoc-realtime:${AISOC_VERSION:-latest}
- pull_policy: missing
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
container_name: aisoc-realtime
depends_on:
redis:
@@ -1210,7 +1210,7 @@ services:
context: ./services/slack-bot
dockerfile: Dockerfile
image: ghcr.io/beenuar/aisoc-slack-bot:${AISOC_VERSION:-latest}
- pull_policy: missing
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
container_name: aisoc-slack-bot
depends_on:
- api
@@ -1246,7 +1246,7 @@ services:
context: .
dockerfile: apps/web/Dockerfile
image: ghcr.io/beenuar/aisoc-web:${AISOC_VERSION:-latest}
- pull_policy: missing
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
container_name: aisoc-web
depends_on:
- api
diff --git a/infra/compose/docker-compose.demo.yml b/infra/compose/docker-compose.demo.yml
index 211dbf3e4..fcb2c1016 100644
--- a/infra/compose/docker-compose.demo.yml
+++ b/infra/compose/docker-compose.demo.yml
@@ -178,7 +178,7 @@ services:
# 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
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
depends_on:
postgres:
condition: service_healthy
@@ -227,7 +227,7 @@ services:
build:
context: ../../services/agents
container_name: aisoc-demo-agents
- pull_policy: missing
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
depends_on:
postgres:
condition: service_healthy
@@ -263,7 +263,7 @@ services:
build:
context: ../../services/realtime
container_name: aisoc-demo-realtime
- pull_policy: missing
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
depends_on:
redis:
condition: service_healthy
@@ -294,7 +294,7 @@ services:
build:
context: ../../services/api
container_name: aisoc-demo-seed
- pull_policy: missing
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
depends_on:
api:
condition: service_healthy
@@ -348,7 +348,7 @@ services:
NEXT_PUBLIC_DEMO_AUTOLOGIN_EMAIL: "[email protected]"
NEXT_PUBLIC_DEMO_AUTOLOGIN_PASSWORD: "aisoc-demo"
container_name: aisoc-demo-web
- pull_policy: missing
+ pull_policy: ${AISOC_PULL_POLICY:-missing}
depends_on:
- api
- agents
diff --git a/tests/test_image_refresh_gate.py b/tests/test_image_refresh_gate.py
new file mode 100644
index 000000000..638bdc38f
--- /dev/null
+++ b/tests/test_image_refresh_gate.py
@@ -0,0 +1,142 @@
+"""`make up` has to be able to deliver a newer image than the one on disk.
+
+What was observed
+-----------------
+All fifteen first-party services carried `pull_policy: missing` against
+`${AISOC_VERSION:-latest}`, a tag that is republished on every merge. `missing`
+means "use the local image if there is one", so `git pull && make up` ran
+brand-new compose configuration against whatever the machine already had, and
+nothing anywhere told an operator to pull. Measured on a real host:
+
+ local aisoc-web:latest pulled 08:14 UTC
+ GHCR aisoc-web:latest published 15:29 UTC, seven commits later
+
+`make up` left the 08:14 image running. A QA pass hit exactly this and ended
+up with the API on `main` and the agents service 55 commits behind, which
+produced a misleading test result.
+
+Why these assertions run the recipe
+-----------------------------------
+`pull_policy` being the right string is necessary and not sufficient — the
+question is what `make up` *does*, and only running it answers that. The
+refresh decision is therefore exercised by invoking the real `_refresh`
+recipe with `COMPOSE` pointed at `echo`, so the decision is observable
+without contacting a registry.
+"""
+
+from __future__ import annotations
+
+import os
+import pathlib
+import re
+import shutil
+import subprocess
+
+import pytest
+import yaml
+
+REPO = pathlib.Path(__file__).resolve().parents[1]
+COMPOSE_FILES = (
+ REPO / "docker-compose.yml",
+ REPO / "infra" / "compose" / "docker-compose.demo.yml",
+)
+
+#: The form every first-party image must carry: overridable, defaulting to
+#: `missing`. A bare `missing` is what could not be turned off for an
+#: air-gapped host and could not be turned up for a moving tag.
+EXPECTED_POLICY = "${AISOC_PULL_POLICY:-missing}"
+
+
+def _services(path: pathlib.Path) -> dict:
+ return (yaml.safe_load(path.read_text(encoding="utf-8")) or {}).get("services") or {}
+
+
+def _first_party(services: dict) -> dict[str, dict]:
+ return {name: service for name, service in services.items() if "ghcr.io/beenuar/aisoc-" in str((service or {}).get("image", ""))}
+
+
[email protected]("path", COMPOSE_FILES, ids=lambda p: p.name)
+class TestEveryFirstPartyImageCanBeRefreshed:
+ def test_the_file_declares_some(self, path: pathlib.Path) -> None:
+ """A compose file that stopped naming first-party images would pass
+ every assertion below by having nothing to check."""
+ assert _first_party(_services(path)), f"{path.name} names no ghcr.io/beenuar/aisoc-* image"
+
+ def test_pull_policy_is_overridable(self, path: pathlib.Path) -> None:
+ hardcoded = {
+ name: service.get("pull_policy")
+ for name, service in _first_party(_services(path)).items()
+ if service.get("pull_policy") != EXPECTED_POLICY
+ }
+ assert not hardcoded, (
+ f"these cannot be refreshed on a moving tag or held back on an air-gapped host: {hardcoded}. "
+ f"Use `pull_policy: {EXPECTED_POLICY}`."
+ )
+
+
+def _run_refresh(env: dict[str, str]) -> str:
+ """The real `_refresh` recipe, with `COMPOSE` replaced by `echo`.
+
+ Substituting the command rather than mocking the decision is the point:
+ the branch under test is written in the Makefile, so the Makefile has to
+ be the thing that runs.
+ """
+ result = subprocess.run( # noqa: S603 - fixed argv, no shell
+ ["make", "--no-print-directory", "_refresh", "COMPOSE=echo compose"],
+ cwd=REPO,
+ capture_output=True,
+ text=True,
+ check=False,
+ env={**os.environ, **env},
+ )
+ assert result.returncode == 0, result.stderr
+ return result.stdout
+
+
[email protected](shutil.which("make") is None, reason="needs make")
+class TestTheRefreshDecision:
+ def test_a_moving_tag_pulls(self) -> None:
+ out = _run_refresh({"AISOC_VERSION": "latest", "AISOC_PULL_POLICY": ""})
+ assert "moving tag" in out
+ assert "compose pull" in out, f"the recipe did not reach a pull:\n{out}"
+
+ @pytest.mark.parametrize("tag", ["main", "edge"])
+ def test_the_other_moving_tags_pull_too(self, tag: str) -> None:
+ assert "compose pull" in _run_refresh({"AISOC_VERSION": tag, "AISOC_PULL_POLICY": ""})
+
+ def test_a_pinned_release_does_not(self) -> None:
+ """The other direction. Pulling unconditionally would pass the test
+ above and spend a registry round trip per service on every `make up`
+ against an immutable tag."""
+ out = _run_refresh({"AISOC_VERSION": "v12.0.0", "AISOC_PULL_POLICY": ""})
+ assert "pinned and immutable" in out
+ assert "compose pull" not in out, f"a pinned tag was refetched:\n{out}"
+
+ def test_an_airgapped_host_never_reaches_a_registry(self) -> None:
+ out = _run_refresh({"AISOC_VERSION": "latest", "AISOC_PULL_POLICY": "never"})
+ assert "not contacting a registry" in out
+ assert "compose pull" not in out, f"AISOC_PULL_POLICY=never still pulled:\n{out}"
+
+
+class TestUpCannotSkipTheRefresh:
+ """`_refresh` existing is worth nothing if `up` does not depend on it —
+ which is the same shape as the defect: a mechanism present and uncalled.
+ """
+
+ @pytest.mark.parametrize("target", ["up", "up-full"])
+ def test_the_target_depends_on_it(self, target: str) -> None:
+ text = (REPO / "Makefile").read_text(encoding="utf-8")
+ match = re.search(rf"^{re.escape(target)}:(.*)$", text, re.M)
+ assert match, f"no `{target}:` target in the Makefile"
+ assert "_refresh" in match.group(1), f"`{target}` does not depend on _refresh: {match.group(1)!r}"
+
+
+class TestTheUpgradePathIsDocumented:
+ """The QA pass that found this had no document to follow. A mechanism
+ nobody is told about is only half a fix."""
+
+ def test_the_deployment_page_says_how_to_upgrade(self) -> None:
+ page = (REPO / "apps" / "docs" / "docs" / "deployment" / "docker.md").read_text(encoding="utf-8")
+ assert "### Upgrading" in page
+ assert "git pull" in page
+ assert "AISOC_PULL_POLICY" in page, "the air-gapped escape hatch has to be discoverable"