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(docker): keep poetry's dependency closure out of all 13 runtime images (#1287)

Beenu Arorac7498115ab29
diff --git a/services/actions/Dockerfile b/services/actions/Dockerfile
index 12ab37463..a14f998bf 100644
--- a/services/actions/Dockerfile
+++ b/services/actions/Dockerfile
@@ -1,26 +1,61 @@
-FROM python:3.11-slim
+# ── Stage 1: turn the lock into a hash-pinned requirements file ──────────────
+#
+# Poetry runs here and nowhere else; nothing from this stage reaches the
+# runtime image except the file it writes.
+#
+# Poetry's version is pinned, its dependency closure is not. Installing it into
+# the runtime image under `virtualenvs.create false` put the ~35 packages
+# poetry itself depends on into the same site-packages as the application's, so
+# they shipped, and each of them moved whenever PyPI published a release. Two
+# builds of one commit straddling such a release were therefore different
+# images: issue #1217 was `platformdirs` 4.12.3 against 4.12.4.
+#
+# `poetry export` reads pyproject.toml and poetry.lock and nothing else, so
+# what it writes is the same whatever poetry's own closure resolved to. It
+# still refuses a lock that no longer matches the manifest ("changed
+# significantly since poetry.lock was last generated"), so editing the manifest
+# without re-locking remains a build error rather than a silent re-resolution
+# nobody reviewed.
+FROM python:3.11-slim AS deps
+
+# `export` left poetry's core in 2.x, so the plugin that provides it is pinned
+# beside poetry rather than resolved at build time.
+RUN pip install --no-cache-dir poetry==2.4.1 poetry-plugin-export==1.9.0
WORKDIR /app
+COPY pyproject.toml poetry.lock ./
-RUN pip install poetry==2.4.1 && \
- poetry config virtualenvs.create false
+# `--only main` is exactly what `poetry install --only main --no-root`
+# installed: the main group, and not the project itself.
+RUN poetry export --only main --format requirements.txt --output /requirements.txt
-COPY pyproject.toml poetry.lock ./
-# Dependencies come from poetry.lock and nowhere else, so two builds of this
-# commit install byte-identical versions. `poetry install` refuses a lock that
-# no longer matches pyproject.toml ("changed significantly since poetry.lock
-# was last generated"), so editing the manifest without re-locking is a build
-# error rather than a silent re-resolution nobody reviewed. The matching
-# `poetry check --lock` runs in CI, where the README the check wants is on
-# disk; this layer has only the two files it installs from.
+# ── Stage 2: the runtime image ───────────────────────────────────────────────
+FROM python:3.11-slim
+
+WORKDIR /app
+
+COPY --from=deps /requirements.txt /requirements.txt
+
+# Every version in this image comes from poetry.lock by way of the stage above,
+# and `--require-hashes` makes that deterministic by construction rather than
+# by the timing of the build: pip refuses any requirement that is not pinned
+# with `==` and carrying a matching hash, so a re-published or substituted
+# artefact fails the build instead of shipping. Poetry is not installed here,
+# so its dependency closure is not in the image and cannot drift between two
+# builds of this commit.
#
# There is deliberately no pip fallback here. The one this replaced carried its
# own copy of the dependency list, drifted from pyproject.toml, and pinned
# versions no test ever ran. When a transient poetry failure triggered it on
# 2026-09-24 the api image shipped FastAPI 0.111.1 and died at import. A build
# that fails is recoverable; an image that boots on untested versions is not.
-RUN poetry install --no-interaction --no-ansi --only main --no-root
+RUN pip install --no-cache-dir --require-hashes -r /requirements.txt
+
+# The manifest and the lock stay in the image as the record of what it was
+# built from. The dependency layer above no longer reads them, so metadata
+# edits that change no resolved version no longer rebuild it.
+COPY pyproject.toml poetry.lock ./
COPY app/ ./app/
diff --git a/services/agents/Dockerfile b/services/agents/Dockerfile
index 291e3be33..ef18e5f20 100644
--- a/services/agents/Dockerfile
+++ b/services/agents/Dockerfile
@@ -1,3 +1,36 @@
+# ── Stage 1: turn the lock into a hash-pinned requirements file ──────────────
+#
+# Poetry runs here and nowhere else; nothing from this stage reaches the
+# runtime image except the file it writes.
+#
+# Poetry's version is pinned, its dependency closure is not. Installing it into
+# the runtime image under `virtualenvs.create false` put the ~35 packages
+# poetry itself depends on into the same site-packages as the application's, so
+# they shipped, and each of them moved whenever PyPI published a release. Two
+# builds of one commit straddling such a release were therefore different
+# images: issue #1217 was `platformdirs` 4.12.3 against 4.12.4.
+#
+# `poetry export` reads pyproject.toml and poetry.lock and nothing else, so
+# what it writes is the same whatever poetry's own closure resolved to. It
+# still refuses a lock that no longer matches the manifest ("changed
+# significantly since poetry.lock was last generated"), so editing the manifest
+# without re-locking remains a build error rather than a silent re-resolution
+# nobody reviewed.
+FROM python:3.11-slim AS deps
+
+# `export` left poetry's core in 2.x, so the plugin that provides it is pinned
+# beside poetry rather than resolved at build time.
+RUN pip install --no-cache-dir poetry==2.4.1 poetry-plugin-export==1.9.0
+
+WORKDIR /app
+COPY pyproject.toml poetry.lock ./
+
+# `--only main` is exactly what `poetry install --only main --no-root`
+# installed: the main group, and not the project itself.
+RUN poetry export --only main --format requirements.txt --output /requirements.txt
+
+
+# ── Stage 2: the runtime image ───────────────────────────────────────────────
FROM python:3.11-slim
WORKDIR /app
@@ -9,25 +42,27 @@ 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==2.4.1 \
- && poetry config virtualenvs.create false
+COPY --from=deps /requirements.txt /requirements.txt
-COPY pyproject.toml poetry.lock ./
-
-# Dependencies come from poetry.lock and nowhere else, so two builds of this
-# commit install byte-identical versions. `poetry install` refuses a lock that
-# no longer matches pyproject.toml ("changed significantly since poetry.lock
-# was last generated"), so editing the manifest without re-locking is a build
-# error rather than a silent re-resolution nobody reviewed. The matching
-# `poetry check --lock` runs in CI, where the README the check wants is on
-# disk; this layer has only the two files it installs from.
+# Every version in this image comes from poetry.lock by way of the stage above,
+# and `--require-hashes` makes that deterministic by construction rather than
+# by the timing of the build: pip refuses any requirement that is not pinned
+# with `==` and carrying a matching hash, so a re-published or substituted
+# artefact fails the build instead of shipping. Poetry is not installed here,
+# so its dependency closure is not in the image and cannot drift between two
+# builds of this commit.
#
# There is deliberately no pip fallback here. The one this replaced carried its
# own copy of the dependency list, drifted from pyproject.toml, and pinned
# versions no test ever ran. When a transient poetry failure triggered it on
# 2026-09-24 the api image shipped FastAPI 0.111.1 and died at import. A build
# that fails is recoverable; an image that boots on untested versions is not.
-RUN poetry install --no-interaction --no-ansi --only main --no-root
+RUN pip install --no-cache-dir --require-hashes -r /requirements.txt
+
+# The manifest and the lock stay in the image as the record of what it was
+# built from. The dependency layer above no longer reads them, so metadata
+# edits that change no resolved version no longer rebuild it.
+COPY pyproject.toml poetry.lock ./
# Smoke-import the modules the orchestrator pulls in at module load time.
# Catches "image built but broken" cases at build time instead of runtime.
diff --git a/services/api/Dockerfile b/services/api/Dockerfile
index 53356bdb6..f082a3f31 100644
--- a/services/api/Dockerfile
+++ b/services/api/Dockerfile
@@ -1,3 +1,36 @@
+# ── Stage 1: turn the lock into a hash-pinned requirements file ──────────────
+#
+# Poetry runs here and nowhere else; nothing from this stage reaches the
+# runtime image except the file it writes.
+#
+# Poetry's version is pinned, its dependency closure is not. Installing it into
+# the runtime image under `virtualenvs.create false` put the ~35 packages
+# poetry itself depends on into the same site-packages as the application's, so
+# they shipped, and each of them moved whenever PyPI published a release. Two
+# builds of one commit straddling such a release were therefore different
+# images: issue #1217 was `platformdirs` 4.12.3 against 4.12.4.
+#
+# `poetry export` reads pyproject.toml and poetry.lock and nothing else, so
+# what it writes is the same whatever poetry's own closure resolved to. It
+# still refuses a lock that no longer matches the manifest ("changed
+# significantly since poetry.lock was last generated"), so editing the manifest
+# without re-locking remains a build error rather than a silent re-resolution
+# nobody reviewed.
+FROM python:3.11-slim AS deps
+
+# `export` left poetry's core in 2.x, so the plugin that provides it is pinned
+# beside poetry rather than resolved at build time.
+RUN pip install --no-cache-dir poetry==2.4.1 poetry-plugin-export==1.9.0
+
+WORKDIR /app
+COPY pyproject.toml poetry.lock ./
+
+# `--only main` is exactly what `poetry install --only main --no-root`
+# installed: the main group, and not the project itself.
+RUN poetry export --only main --format requirements.txt --output /requirements.txt
+
+
+# ── Stage 2: the runtime image ───────────────────────────────────────────────
FROM python:3.11-slim AS base
WORKDIR /app
@@ -17,25 +50,22 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
shared-mime-info \
&& rm -rf /var/lib/apt/lists/*
-RUN pip install poetry==2.4.1 && \
- poetry config virtualenvs.create false
-
-COPY pyproject.toml poetry.lock ./
+COPY --from=deps /requirements.txt /requirements.txt
-# Dependencies come from poetry.lock and nowhere else, so two builds of this
-# commit install byte-identical versions. `poetry install` refuses a lock that
-# no longer matches pyproject.toml ("changed significantly since poetry.lock
-# was last generated"), so editing the manifest without re-locking is a build
-# error rather than a silent re-resolution nobody reviewed. The matching
-# `poetry check --lock` runs in CI, where the README the check wants is on
-# disk; this layer has only the two files it installs from.
+# Every version in this image comes from poetry.lock by way of the stage above,
+# and `--require-hashes` makes that deterministic by construction rather than
+# by the timing of the build: pip refuses any requirement that is not pinned
+# with `==` and carrying a matching hash, so a re-published or substituted
+# artefact fails the build instead of shipping. Poetry is not installed here,
+# so its dependency closure is not in the image and cannot drift between two
+# builds of this commit.
#
# There is deliberately no pip fallback here. The one this replaced carried its
# own copy of the dependency list, drifted from pyproject.toml, and pinned
# versions no test ever ran. When a transient poetry failure triggered it on
# 2026-09-24 the api image shipped FastAPI 0.111.1 and died at import. A build
# that fails is recoverable; an image that boots on untested versions is not.
-RUN poetry install --no-interaction --no-ansi --only main --no-root
+RUN pip install --no-cache-dir --require-hashes -r /requirements.txt
COPY . .
diff --git a/services/connectors/Dockerfile b/services/connectors/Dockerfile
index c654bf5ed..2401834df 100644
--- a/services/connectors/Dockerfile
+++ b/services/connectors/Dockerfile
@@ -1,26 +1,61 @@
-FROM python:3.11-slim
+# ── Stage 1: turn the lock into a hash-pinned requirements file ──────────────
+#
+# Poetry runs here and nowhere else; nothing from this stage reaches the
+# runtime image except the file it writes.
+#
+# Poetry's version is pinned, its dependency closure is not. Installing it into
+# the runtime image under `virtualenvs.create false` put the ~35 packages
+# poetry itself depends on into the same site-packages as the application's, so
+# they shipped, and each of them moved whenever PyPI published a release. Two
+# builds of one commit straddling such a release were therefore different
+# images: issue #1217 was `platformdirs` 4.12.3 against 4.12.4.
+#
+# `poetry export` reads pyproject.toml and poetry.lock and nothing else, so
+# what it writes is the same whatever poetry's own closure resolved to. It
+# still refuses a lock that no longer matches the manifest ("changed
+# significantly since poetry.lock was last generated"), so editing the manifest
+# without re-locking remains a build error rather than a silent re-resolution
+# nobody reviewed.
+FROM python:3.11-slim AS deps
+
+# `export` left poetry's core in 2.x, so the plugin that provides it is pinned
+# beside poetry rather than resolved at build time.
+RUN pip install --no-cache-dir poetry==2.4.1 poetry-plugin-export==1.9.0
WORKDIR /app
+COPY pyproject.toml poetry.lock ./
-RUN pip install --no-cache-dir poetry==2.4.1 && \
- poetry config virtualenvs.create false
+# `--only main` is exactly what `poetry install --only main --no-root`
+# installed: the main group, and not the project itself.
+RUN poetry export --only main --format requirements.txt --output /requirements.txt
-COPY pyproject.toml poetry.lock ./
-# Dependencies come from poetry.lock and nowhere else, so two builds of this
-# commit install byte-identical versions. `poetry install` refuses a lock that
-# no longer matches pyproject.toml ("changed significantly since poetry.lock
-# was last generated"), so editing the manifest without re-locking is a build
-# error rather than a silent re-resolution nobody reviewed. The matching
-# `poetry check --lock` runs in CI, where the README the check wants is on
-# disk; this layer has only the two files it installs from.
+# ── Stage 2: the runtime image ───────────────────────────────────────────────
+FROM python:3.11-slim
+
+WORKDIR /app
+
+COPY --from=deps /requirements.txt /requirements.txt
+
+# Every version in this image comes from poetry.lock by way of the stage above,
+# and `--require-hashes` makes that deterministic by construction rather than
+# by the timing of the build: pip refuses any requirement that is not pinned
+# with `==` and carrying a matching hash, so a re-published or substituted
+# artefact fails the build instead of shipping. Poetry is not installed here,
+# so its dependency closure is not in the image and cannot drift between two
+# builds of this commit.
#
# There is deliberately no pip fallback here. The one this replaced carried its
# own copy of the dependency list, drifted from pyproject.toml, and pinned
# versions no test ever ran. When a transient poetry failure triggered it on
# 2026-09-24 the api image shipped FastAPI 0.111.1 and died at import. A build
# that fails is recoverable; an image that boots on untested versions is not.
-RUN poetry install --no-interaction --no-ansi --only main --no-root
+RUN pip install --no-cache-dir --require-hashes -r /requirements.txt
+
+# The manifest and the lock stay in the image as the record of what it was
+# built from. The dependency layer above no longer reads them, so metadata
+# edits that change no resolved version no longer rebuild it.
+COPY pyproject.toml poetry.lock ./
COPY app/ ./app/
diff --git a/services/fusion/Dockerfile b/services/fusion/Dockerfile
index a3eb82e06..3743e7303 100644
--- a/services/fusion/Dockerfile
+++ b/services/fusion/Dockerfile
@@ -1,26 +1,61 @@
-FROM python:3.11-slim
+# ── Stage 1: turn the lock into a hash-pinned requirements file ──────────────
+#
+# Poetry runs here and nowhere else; nothing from this stage reaches the
+# runtime image except the file it writes.
+#
+# Poetry's version is pinned, its dependency closure is not. Installing it into
+# the runtime image under `virtualenvs.create false` put the ~35 packages
+# poetry itself depends on into the same site-packages as the application's, so
+# they shipped, and each of them moved whenever PyPI published a release. Two
+# builds of one commit straddling such a release were therefore different
+# images: issue #1217 was `platformdirs` 4.12.3 against 4.12.4.
+#
+# `poetry export` reads pyproject.toml and poetry.lock and nothing else, so
+# what it writes is the same whatever poetry's own closure resolved to. It
+# still refuses a lock that no longer matches the manifest ("changed
+# significantly since poetry.lock was last generated"), so editing the manifest
+# without re-locking remains a build error rather than a silent re-resolution
+# nobody reviewed.
+FROM python:3.11-slim AS deps
+
+# `export` left poetry's core in 2.x, so the plugin that provides it is pinned
+# beside poetry rather than resolved at build time.
+RUN pip install --no-cache-dir poetry==2.4.1 poetry-plugin-export==1.9.0
WORKDIR /app
+COPY pyproject.toml poetry.lock ./
-RUN pip install poetry==2.4.1 && \
- poetry config virtualenvs.create false
+# `--only main` is exactly what `poetry install --only main --no-root`
+# installed: the main group, and not the project itself.
+RUN poetry export --only main --format requirements.txt --output /requirements.txt
-COPY pyproject.toml poetry.lock ./
-# Dependencies come from poetry.lock and nowhere else, so two builds of this
-# commit install byte-identical versions. `poetry install` refuses a lock that
-# no longer matches pyproject.toml ("changed significantly since poetry.lock
-# was last generated"), so editing the manifest without re-locking is a build
-# error rather than a silent re-resolution nobody reviewed. The matching
-# `poetry check --lock` runs in CI, where the README the check wants is on
-# disk; this layer has only the two files it installs from.
+# ── Stage 2: the runtime image ───────────────────────────────────────────────
+FROM python:3.11-slim
+
+WORKDIR /app
+
+COPY --from=deps /requirements.txt /requirements.txt
+
+# Every version in this image comes from poetry.lock by way of the stage above,
+# and `--require-hashes` makes that deterministic by construction rather than
+# by the timing of the build: pip refuses any requirement that is not pinned
+# with `==` and carrying a matching hash, so a re-published or substituted
+# artefact fails the build instead of shipping. Poetry is not installed here,
+# so its dependency closure is not in the image and cannot drift between two
+# builds of this commit.
#
# There is deliberately no pip fallback here. The one this replaced carried its
# own copy of the dependency list, drifted from pyproject.toml, and pinned
# versions no test ever ran. When a transient poetry failure triggered it on
# 2026-09-24 the api image shipped FastAPI 0.111.1 and died at import. A build
# that fails is recoverable; an image that boots on untested versions is not.
-RUN poetry install --no-interaction --no-ansi --only main --no-root
+RUN pip install --no-cache-dir --require-hashes -r /requirements.txt
+
+# The manifest and the lock stay in the image as the record of what it was
+# built from. The dependency layer above no longer reads them, so metadata
+# edits that change no resolved version no longer rebuild it.
+COPY pyproject.toml poetry.lock ./
COPY app/ ./app/
diff --git a/services/honeytokens/Dockerfile b/services/honeytokens/Dockerfile
index 8280f7cb2..b6174e845 100644
--- a/services/honeytokens/Dockerfile
+++ b/services/honeytokens/Dockerfile
@@ -1,3 +1,36 @@
+# ── Stage 1: turn the lock into a hash-pinned requirements file ──────────────
+#
+# Poetry runs here and nowhere else; nothing from this stage reaches the
+# runtime image except the file it writes.
+#
+# Poetry's version is pinned, its dependency closure is not. Installing it into
+# the runtime image under `virtualenvs.create false` put the ~35 packages
+# poetry itself depends on into the same site-packages as the application's, so
+# they shipped, and each of them moved whenever PyPI published a release. Two
+# builds of one commit straddling such a release were therefore different
+# images: issue #1217 was `platformdirs` 4.12.3 against 4.12.4.
+#
+# `poetry export` reads pyproject.toml and poetry.lock and nothing else, so
+# what it writes is the same whatever poetry's own closure resolved to. It
+# still refuses a lock that no longer matches the manifest ("changed
+# significantly since poetry.lock was last generated"), so editing the manifest
+# without re-locking remains a build error rather than a silent re-resolution
+# nobody reviewed.
+FROM python:3.11-slim AS deps
+
+# `export` left poetry's core in 2.x, so the plugin that provides it is pinned
+# beside poetry rather than resolved at build time.
+RUN pip install --no-cache-dir poetry==2.4.1 poetry-plugin-export==1.9.0
+
+WORKDIR /app
+COPY pyproject.toml poetry.lock ./
+
+# `--only main` is exactly what `poetry install --only main --no-root`
+# installed: the main group, and not the project itself.
+RUN poetry export --only main --format requirements.txt --output /requirements.txt
+
+
+# ── Stage 2: the runtime image ───────────────────────────────────────────────
FROM python:3.11-slim
WORKDIR /app
@@ -6,18 +39,27 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
-RUN pip install --no-cache-dir poetry==2.4.1 \
- && poetry config virtualenvs.create false
+COPY --from=deps /requirements.txt /requirements.txt
-COPY pyproject.toml poetry.lock ./
+# Every version in this image comes from poetry.lock by way of the stage above,
+# and `--require-hashes` makes that deterministic by construction rather than
+# by the timing of the build: pip refuses any requirement that is not pinned
+# with `==` and carrying a matching hash, so a re-published or substituted
+# artefact fails the build instead of shipping. Poetry is not installed here,
+# so its dependency closure is not in the image and cannot drift between two
+# builds of this commit.
+#
+# This layer reads only the exported requirements, so it still caches across
+# source edits — the reason the hand-written `pip install` list it replaces
+# existed at all. That list was a second copy of pyproject.toml maintained by a
+# comment asking for lockstep, and every one of the four had drifted from the
+# manifest it mirrored.
+RUN pip install --no-cache-dir --require-hashes -r /requirements.txt
-# Dependencies come from poetry.lock, so two builds of this commit install
-# byte-identical versions. This layer deliberately copies only the manifest
-# and the lock, so it still caches across source edits — the reason the
-# hand-written `pip install` list it replaces existed at all. That list was a
-# second copy of pyproject.toml maintained by a comment asking for lockstep,
-# and every one of the four had drifted from the manifest it mirrored.
-RUN poetry install --no-interaction --no-ansi --only main --no-root
+# The manifest and the lock stay in the image as the record of what it was
+# built from. The dependency layer above no longer reads them, so metadata
+# edits that change no resolved version no longer rebuild it.
+COPY pyproject.toml poetry.lock ./
COPY alembic.ini .
COPY alembic/ alembic/
diff --git a/services/mesh/Dockerfile b/services/mesh/Dockerfile
index 2fe5e5089..bf13b34b8 100644
--- a/services/mesh/Dockerfile
+++ b/services/mesh/Dockerfile
@@ -1,3 +1,36 @@
+# ── Stage 1: turn the lock into a hash-pinned requirements file ──────────────
+#
+# Poetry runs here and nowhere else; nothing from this stage reaches the
+# runtime image except the file it writes.
+#
+# Poetry's version is pinned, its dependency closure is not. Installing it into
+# the runtime image under `virtualenvs.create false` put the ~35 packages
+# poetry itself depends on into the same site-packages as the application's, so
+# they shipped, and each of them moved whenever PyPI published a release. Two
+# builds of one commit straddling such a release were therefore different
+# images: issue #1217 was `platformdirs` 4.12.3 against 4.12.4.
+#
+# `poetry export` reads pyproject.toml and poetry.lock and nothing else, so
+# what it writes is the same whatever poetry's own closure resolved to. It
+# still refuses a lock that no longer matches the manifest ("changed
+# significantly since poetry.lock was last generated"), so editing the manifest
+# without re-locking remains a build error rather than a silent re-resolution
+# nobody reviewed.
+FROM python:3.11-slim AS deps
+
+# `export` left poetry's core in 2.x, so the plugin that provides it is pinned
+# beside poetry rather than resolved at build time.
+RUN pip install --no-cache-dir poetry==2.4.1 poetry-plugin-export==1.9.0
+
+WORKDIR /app
+COPY pyproject.toml poetry.lock ./
+
+# `--only main` is exactly what `poetry install --only main --no-root`
+# installed: the main group, and not the project itself.
+RUN poetry export --only main --format requirements.txt --output /requirements.txt
+
+
+# ── Stage 2: the runtime image ───────────────────────────────────────────────
FROM python:3.11-slim
WORKDIR /app
@@ -6,18 +39,27 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
-RUN pip install --no-cache-dir poetry==2.4.1 \
- && poetry config virtualenvs.create false
+COPY --from=deps /requirements.txt /requirements.txt
-COPY pyproject.toml poetry.lock ./
+# Every version in this image comes from poetry.lock by way of the stage above,
+# and `--require-hashes` makes that deterministic by construction rather than
+# by the timing of the build: pip refuses any requirement that is not pinned
+# with `==` and carrying a matching hash, so a re-published or substituted
+# artefact fails the build instead of shipping. Poetry is not installed here,
+# so its dependency closure is not in the image and cannot drift between two
+# builds of this commit.
+#
+# This layer reads only the exported requirements, so it still caches across
+# source edits — the reason the hand-written `pip install` list it replaces
+# existed at all. That list was a second copy of pyproject.toml maintained by a
+# comment asking for lockstep, and every one of the four had drifted from the
+# manifest it mirrored.
+RUN pip install --no-cache-dir --require-hashes -r /requirements.txt
-# Dependencies come from poetry.lock, so two builds of this commit install
-# byte-identical versions. This layer deliberately copies only the manifest
-# and the lock, so it still caches across source edits — the reason the
-# hand-written `pip install` list it replaces existed at all. That list was a
-# second copy of pyproject.toml maintained by a comment asking for lockstep,
-# and every one of the four had drifted from the manifest it mirrored.
-RUN poetry install --no-interaction --no-ansi --only main --no-root
+# The manifest and the lock stay in the image as the record of what it was
+# built from. The dependency layer above no longer reads them, so metadata
+# edits that change no resolved version no longer rebuild it.
+COPY pyproject.toml poetry.lock ./
COPY app/ app/
diff --git a/services/osquery-tls/Dockerfile b/services/osquery-tls/Dockerfile
index bedcf7846..a0e42fdb9 100644
--- a/services/osquery-tls/Dockerfile
+++ b/services/osquery-tls/Dockerfile
@@ -1,3 +1,36 @@
+# ── Stage 1: turn the lock into a hash-pinned requirements file ──────────────
+#
+# Poetry runs here and nowhere else; nothing from this stage reaches the
+# runtime image except the file it writes.
+#
+# Poetry's version is pinned, its dependency closure is not. Installing it into
+# the runtime image under `virtualenvs.create false` put the ~35 packages
+# poetry itself depends on into the same site-packages as the application's, so
+# they shipped, and each of them moved whenever PyPI published a release. Two
+# builds of one commit straddling such a release were therefore different
+# images: issue #1217 was `platformdirs` 4.12.3 against 4.12.4.
+#
+# `poetry export` reads pyproject.toml and poetry.lock and nothing else, so
+# what it writes is the same whatever poetry's own closure resolved to. It
+# still refuses a lock that no longer matches the manifest ("changed
+# significantly since poetry.lock was last generated"), so editing the manifest
+# without re-locking remains a build error rather than a silent re-resolution
+# nobody reviewed.
+FROM python:3.11-slim AS deps
+
+# `export` left poetry's core in 2.x, so the plugin that provides it is pinned
+# beside poetry rather than resolved at build time.
+RUN pip install --no-cache-dir poetry==2.4.1 poetry-plugin-export==1.9.0
+
+WORKDIR /app
+COPY pyproject.toml poetry.lock ./
+
+# `--only main` is exactly what `poetry install --only main --no-root`
+# installed: the main group, and not the project itself.
+RUN poetry export --only main --format requirements.txt --output /requirements.txt
+
+
+# ── Stage 2: the runtime image ───────────────────────────────────────────────
FROM python:3.11-slim AS base
WORKDIR /app
@@ -11,25 +44,22 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
-RUN pip install poetry==2.4.1 && \
- poetry config virtualenvs.create false
-
-COPY pyproject.toml poetry.lock ./
+COPY --from=deps /requirements.txt /requirements.txt
-# Dependencies come from poetry.lock and nowhere else, so two builds of this
-# commit install byte-identical versions. `poetry install` refuses a lock that
-# no longer matches pyproject.toml ("changed significantly since poetry.lock
-# was last generated"), so editing the manifest without re-locking is a build
-# error rather than a silent re-resolution nobody reviewed. The matching
-# `poetry check --lock` runs in CI, where the README the check wants is on
-# disk; this layer has only the two files it installs from.
+# Every version in this image comes from poetry.lock by way of the stage above,
+# and `--require-hashes` makes that deterministic by construction rather than
+# by the timing of the build: pip refuses any requirement that is not pinned
+# with `==` and carrying a matching hash, so a re-published or substituted
+# artefact fails the build instead of shipping. Poetry is not installed here,
+# so its dependency closure is not in the image and cannot drift between two
+# builds of this commit.
#
# There is deliberately no pip fallback here. The one this replaced carried its
# own copy of the dependency list, drifted from pyproject.toml, and pinned
# versions no test ever ran. When a transient poetry failure triggered it on
# 2026-09-24 the api image shipped FastAPI 0.111.1 and died at import. A build
# that fails is recoverable; an image that boots on untested versions is not.
-RUN poetry install --no-interaction --no-ansi --only main --no-root
+RUN pip install --no-cache-dir --require-hashes -r /requirements.txt
COPY . .
diff --git a/services/purple-team/Dockerfile b/services/purple-team/Dockerfile
index 1adb44ab0..ffbe93501 100644
--- a/services/purple-team/Dockerfile
+++ b/services/purple-team/Dockerfile
@@ -1,3 +1,36 @@
+# ── Stage 1: turn the lock into a hash-pinned requirements file ──────────────
+#
+# Poetry runs here and nowhere else; nothing from this stage reaches the
+# runtime image except the file it writes.
+#
+# Poetry's version is pinned, its dependency closure is not. Installing it into
+# the runtime image under `virtualenvs.create false` put the ~35 packages
+# poetry itself depends on into the same site-packages as the application's, so
+# they shipped, and each of them moved whenever PyPI published a release. Two
+# builds of one commit straddling such a release were therefore different
+# images: issue #1217 was `platformdirs` 4.12.3 against 4.12.4.
+#
+# `poetry export` reads pyproject.toml and poetry.lock and nothing else, so
+# what it writes is the same whatever poetry's own closure resolved to. It
+# still refuses a lock that no longer matches the manifest ("changed
+# significantly since poetry.lock was last generated"), so editing the manifest
+# without re-locking remains a build error rather than a silent re-resolution
+# nobody reviewed.
+FROM python:3.11-slim AS deps
+
+# `export` left poetry's core in 2.x, so the plugin that provides it is pinned
+# beside poetry rather than resolved at build time.
+RUN pip install --no-cache-dir poetry==2.4.1 poetry-plugin-export==1.9.0
+
+WORKDIR /app
+COPY pyproject.toml poetry.lock ./
+
+# `--only main` is exactly what `poetry install --only main --no-root`
+# installed: the main group, and not the project itself.
+RUN poetry export --only main --format requirements.txt --output /requirements.txt
+
+
+# ── Stage 2: the runtime image ───────────────────────────────────────────────
FROM python:3.11-slim
WORKDIR /app
@@ -6,18 +39,27 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
-RUN pip install --no-cache-dir poetry==2.4.1 \
- && poetry config virtualenvs.create false
+COPY --from=deps /requirements.txt /requirements.txt
-COPY pyproject.toml poetry.lock ./
+# Every version in this image comes from poetry.lock by way of the stage above,
+# and `--require-hashes` makes that deterministic by construction rather than
+# by the timing of the build: pip refuses any requirement that is not pinned
+# with `==` and carrying a matching hash, so a re-published or substituted
+# artefact fails the build instead of shipping. Poetry is not installed here,
+# so its dependency closure is not in the image and cannot drift between two
+# builds of this commit.
+#
+# This layer reads only the exported requirements, so it still caches across
+# source edits — the reason the hand-written `pip install` list it replaces
+# existed at all. That list was a second copy of pyproject.toml maintained by a
+# comment asking for lockstep, and every one of the four had drifted from the
+# manifest it mirrored.
+RUN pip install --no-cache-dir --require-hashes -r /requirements.txt
-# Dependencies come from poetry.lock, so two builds of this commit install
-# byte-identical versions. This layer deliberately copies only the manifest
-# and the lock, so it still caches across source edits — the reason the
-# hand-written `pip install` list it replaces existed at all. That list was a
-# second copy of pyproject.toml maintained by a comment asking for lockstep,
-# and every one of the four had drifted from the manifest it mirrored.
-RUN poetry install --no-interaction --no-ansi --only main --no-root
+# The manifest and the lock stay in the image as the record of what it was
+# built from. The dependency layer above no longer reads them, so metadata
+# edits that change no resolved version no longer rebuild it.
+COPY pyproject.toml poetry.lock ./
COPY alembic.ini .
COPY alembic/ alembic/
diff --git a/services/slack-bot/Dockerfile b/services/slack-bot/Dockerfile
index 30a428bc9..ef9871c45 100644
--- a/services/slack-bot/Dockerfile
+++ b/services/slack-bot/Dockerfile
@@ -1,26 +1,61 @@
-FROM python:3.11-slim
+# ── Stage 1: turn the lock into a hash-pinned requirements file ──────────────
+#
+# Poetry runs here and nowhere else; nothing from this stage reaches the
+# runtime image except the file it writes.
+#
+# Poetry's version is pinned, its dependency closure is not. Installing it into
+# the runtime image under `virtualenvs.create false` put the ~35 packages
+# poetry itself depends on into the same site-packages as the application's, so
+# they shipped, and each of them moved whenever PyPI published a release. Two
+# builds of one commit straddling such a release were therefore different
+# images: issue #1217 was `platformdirs` 4.12.3 against 4.12.4.
+#
+# `poetry export` reads pyproject.toml and poetry.lock and nothing else, so
+# what it writes is the same whatever poetry's own closure resolved to. It
+# still refuses a lock that no longer matches the manifest ("changed
+# significantly since poetry.lock was last generated"), so editing the manifest
+# without re-locking remains a build error rather than a silent re-resolution
+# nobody reviewed.
+FROM python:3.11-slim AS deps
+
+# `export` left poetry's core in 2.x, so the plugin that provides it is pinned
+# beside poetry rather than resolved at build time.
+RUN pip install --no-cache-dir poetry==2.4.1 poetry-plugin-export==1.9.0
WORKDIR /app
+COPY pyproject.toml poetry.lock ./
-RUN pip install --no-cache-dir poetry==2.4.1 && \
- poetry config virtualenvs.create false
+# `--only main` is exactly what `poetry install --only main --no-root`
+# installed: the main group, and not the project itself.
+RUN poetry export --only main --format requirements.txt --output /requirements.txt
-COPY pyproject.toml poetry.lock ./
-# Dependencies come from poetry.lock and nowhere else, so two builds of this
-# commit install byte-identical versions. `poetry install` refuses a lock that
-# no longer matches pyproject.toml ("changed significantly since poetry.lock
-# was last generated"), so editing the manifest without re-locking is a build
-# error rather than a silent re-resolution nobody reviewed. The matching
-# `poetry check --lock` runs in CI, where the README the check wants is on
-# disk; this layer has only the two files it installs from.
+# ── Stage 2: the runtime image ───────────────────────────────────────────────
+FROM python:3.11-slim
+
+WORKDIR /app
+
+COPY --from=deps /requirements.txt /requirements.txt
+
+# Every version in this image comes from poetry.lock by way of the stage above,
+# and `--require-hashes` makes that deterministic by construction rather than
+# by the timing of the build: pip refuses any requirement that is not pinned
+# with `==` and carrying a matching hash, so a re-published or substituted
+# artefact fails the build instead of shipping. Poetry is not installed here,
+# so its dependency closure is not in the image and cannot drift between two
+# builds of this commit.
#
# There is deliberately no pip fallback here. The one this replaced carried its
# own copy of the dependency list, drifted from pyproject.toml, and pinned
# versions no test ever ran. When a transient poetry failure triggered it on
# 2026-09-24 the api image shipped FastAPI 0.111.1 and died at import. A build
# that fails is recoverable; an image that boots on untested versions is not.
-RUN poetry install --no-interaction --no-ansi --only main --no-root
+RUN pip install --no-cache-dir --require-hashes -r /requirements.txt
+
+# The manifest and the lock stay in the image as the record of what it was
+# built from. The dependency layer above no longer reads them, so metadata
+# edits that change no resolved version no longer rebuild it.
+COPY pyproject.toml poetry.lock ./
COPY app/ ./app/
diff --git a/services/teams-bot/Dockerfile b/services/teams-bot/Dockerfile
index adce190e7..3c179472f 100644
--- a/services/teams-bot/Dockerfile
+++ b/services/teams-bot/Dockerfile
@@ -1,26 +1,61 @@
-FROM python:3.11-slim
+# ── Stage 1: turn the lock into a hash-pinned requirements file ──────────────
+#
+# Poetry runs here and nowhere else; nothing from this stage reaches the
+# runtime image except the file it writes.
+#
+# Poetry's version is pinned, its dependency closure is not. Installing it into
+# the runtime image under `virtualenvs.create false` put the ~35 packages
+# poetry itself depends on into the same site-packages as the application's, so
+# they shipped, and each of them moved whenever PyPI published a release. Two
+# builds of one commit straddling such a release were therefore different
+# images: issue #1217 was `platformdirs` 4.12.3 against 4.12.4.
+#
+# `poetry export` reads pyproject.toml and poetry.lock and nothing else, so
+# what it writes is the same whatever poetry's own closure resolved to. It
+# still refuses a lock that no longer matches the manifest ("changed
+# significantly since poetry.lock was last generated"), so editing the manifest
+# without re-locking remains a build error rather than a silent re-resolution
+# nobody reviewed.
+FROM python:3.11-slim AS deps
+
+# `export` left poetry's core in 2.x, so the plugin that provides it is pinned
+# beside poetry rather than resolved at build time.
+RUN pip install --no-cache-dir poetry==2.4.1 poetry-plugin-export==1.9.0
WORKDIR /app
+COPY pyproject.toml poetry.lock ./
-RUN pip install --no-cache-dir poetry==2.4.1 && \
- poetry config virtualenvs.create false
+# `--only main` is exactly what `poetry install --only main --no-root`
+# installed: the main group, and not the project itself.
+RUN poetry export --only main --format requirements.txt --output /requirements.txt
-COPY pyproject.toml poetry.lock ./
-# Dependencies come from poetry.lock and nowhere else, so two builds of this
-# commit install byte-identical versions. `poetry install` refuses a lock that
-# no longer matches pyproject.toml ("changed significantly since poetry.lock
-# was last generated"), so editing the manifest without re-locking is a build
-# error rather than a silent re-resolution nobody reviewed. The matching
-# `poetry check --lock` runs in CI, where the README the check wants is on
-# disk; this layer has only the two files it installs from.
+# ── Stage 2: the runtime image ───────────────────────────────────────────────
+FROM python:3.11-slim
+
+WORKDIR /app
+
+COPY --from=deps /requirements.txt /requirements.txt
+
+# Every version in this image comes from poetry.lock by way of the stage above,
+# and `--require-hashes` makes that deterministic by construction rather than
+# by the timing of the build: pip refuses any requirement that is not pinned
+# with `==` and carrying a matching hash, so a re-published or substituted
+# artefact fails the build instead of shipping. Poetry is not installed here,
+# so its dependency closure is not in the image and cannot drift between two
+# builds of this commit.
#
# There is deliberately no pip fallback here. The one this replaced carried its
# own copy of the dependency list, drifted from pyproject.toml, and pinned
# versions no test ever ran. When a transient poetry failure triggered it on
# 2026-09-24 the api image shipped FastAPI 0.111.1 and died at import. A build
# that fails is recoverable; an image that boots on untested versions is not.
-RUN poetry install --no-interaction --no-ansi --only main --no-root
+RUN pip install --no-cache-dir --require-hashes -r /requirements.txt
+
+# The manifest and the lock stay in the image as the record of what it was
+# built from. The dependency layer above no longer reads them, so metadata
+# edits that change no resolved version no longer rebuild it.
+COPY pyproject.toml poetry.lock ./
COPY app/ ./app/
diff --git a/services/threatintel/Dockerfile b/services/threatintel/Dockerfile
index a6eed93c7..0e1938b82 100644
--- a/services/threatintel/Dockerfile
+++ b/services/threatintel/Dockerfile
@@ -1,3 +1,36 @@
+# ── Stage 1: turn the lock into a hash-pinned requirements file ──────────────
+#
+# Poetry runs here and nowhere else; nothing from this stage reaches the
+# runtime image except the file it writes.
+#
+# Poetry's version is pinned, its dependency closure is not. Installing it into
+# the runtime image under `virtualenvs.create false` put the ~35 packages
+# poetry itself depends on into the same site-packages as the application's, so
+# they shipped, and each of them moved whenever PyPI published a release. Two
+# builds of one commit straddling such a release were therefore different
+# images: issue #1217 was `platformdirs` 4.12.3 against 4.12.4.
+#
+# `poetry export` reads pyproject.toml and poetry.lock and nothing else, so
+# what it writes is the same whatever poetry's own closure resolved to. It
+# still refuses a lock that no longer matches the manifest ("changed
+# significantly since poetry.lock was last generated"), so editing the manifest
+# without re-locking remains a build error rather than a silent re-resolution
+# nobody reviewed.
+FROM python:3.11-slim AS deps
+
+# `export` left poetry's core in 2.x, so the plugin that provides it is pinned
+# beside poetry rather than resolved at build time.
+RUN pip install --no-cache-dir poetry==2.4.1 poetry-plugin-export==1.9.0
+
+WORKDIR /app
+COPY pyproject.toml poetry.lock ./
+
+# `--only main` is exactly what `poetry install --only main --no-root`
+# installed: the main group, and not the project itself.
+RUN poetry export --only main --format requirements.txt --output /requirements.txt
+
+
+# ── Stage 2: the runtime image ───────────────────────────────────────────────
FROM python:3.11-slim
WORKDIR /app
@@ -6,25 +39,27 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential curl \
&& rm -rf /var/lib/apt/lists/*
-RUN pip install --no-cache-dir poetry==2.4.1 \
- && poetry config virtualenvs.create false
+COPY --from=deps /requirements.txt /requirements.txt
-COPY pyproject.toml poetry.lock ./
-
-# Dependencies come from poetry.lock and nowhere else, so two builds of this
-# commit install byte-identical versions. `poetry install` refuses a lock that
-# no longer matches pyproject.toml ("changed significantly since poetry.lock
-# was last generated"), so editing the manifest without re-locking is a build
-# error rather than a silent re-resolution nobody reviewed. The matching
-# `poetry check --lock` runs in CI, where the README the check wants is on
-# disk; this layer has only the two files it installs from.
+# Every version in this image comes from poetry.lock by way of the stage above,
+# and `--require-hashes` makes that deterministic by construction rather than
+# by the timing of the build: pip refuses any requirement that is not pinned
+# with `==` and carrying a matching hash, so a re-published or substituted
+# artefact fails the build instead of shipping. Poetry is not installed here,
+# so its dependency closure is not in the image and cannot drift between two
+# builds of this commit.
#
# There is deliberately no pip fallback here. The one this replaced carried its
# own copy of the dependency list, drifted from pyproject.toml, and pinned
# versions no test ever ran. When a transient poetry failure triggered it on
# 2026-09-24 the api image shipped FastAPI 0.111.1 and died at import. A build
# that fails is recoverable; an image that boots on untested versions is not.
-RUN poetry install --no-interaction --no-ansi --only main --no-root
+RUN pip install --no-cache-dir --require-hashes -r /requirements.txt
+
+# The manifest and the lock stay in the image as the record of what it was
+# built from. The dependency layer above no longer reads them, so metadata
+# edits that change no resolved version no longer rebuild it.
+COPY pyproject.toml poetry.lock ./
COPY app ./app
diff --git a/services/ueba/Dockerfile b/services/ueba/Dockerfile
index 7ce8f612f..109324fac 100644
--- a/services/ueba/Dockerfile
+++ b/services/ueba/Dockerfile
@@ -1,3 +1,36 @@
+# ── Stage 1: turn the lock into a hash-pinned requirements file ──────────────
+#
+# Poetry runs here and nowhere else; nothing from this stage reaches the
+# runtime image except the file it writes.
+#
+# Poetry's version is pinned, its dependency closure is not. Installing it into
+# the runtime image under `virtualenvs.create false` put the ~35 packages
+# poetry itself depends on into the same site-packages as the application's, so
+# they shipped, and each of them moved whenever PyPI published a release. Two
+# builds of one commit straddling such a release were therefore different
+# images: issue #1217 was `platformdirs` 4.12.3 against 4.12.4.
+#
+# `poetry export` reads pyproject.toml and poetry.lock and nothing else, so
+# what it writes is the same whatever poetry's own closure resolved to. It
+# still refuses a lock that no longer matches the manifest ("changed
+# significantly since poetry.lock was last generated"), so editing the manifest
+# without re-locking remains a build error rather than a silent re-resolution
+# nobody reviewed.
+FROM python:3.11-slim AS deps
+
+# `export` left poetry's core in 2.x, so the plugin that provides it is pinned
+# beside poetry rather than resolved at build time.
+RUN pip install --no-cache-dir poetry==2.4.1 poetry-plugin-export==1.9.0
+
+WORKDIR /app
+COPY pyproject.toml poetry.lock ./
+
+# `--only main` is exactly what `poetry install --only main --no-root`
+# installed: the main group, and not the project itself.
+RUN poetry export --only main --format requirements.txt --output /requirements.txt
+
+
+# ── Stage 2: the runtime image ───────────────────────────────────────────────
FROM python:3.11-slim
WORKDIR /app
@@ -6,18 +39,27 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
-RUN pip install --no-cache-dir poetry==2.4.1 \
- && poetry config virtualenvs.create false
+COPY --from=deps /requirements.txt /requirements.txt
-COPY pyproject.toml poetry.lock ./
+# Every version in this image comes from poetry.lock by way of the stage above,
+# and `--require-hashes` makes that deterministic by construction rather than
+# by the timing of the build: pip refuses any requirement that is not pinned
+# with `==` and carrying a matching hash, so a re-published or substituted
+# artefact fails the build instead of shipping. Poetry is not installed here,
+# so its dependency closure is not in the image and cannot drift between two
+# builds of this commit.
+#
+# This layer reads only the exported requirements, so it still caches across
+# source edits — the reason the hand-written `pip install` list it replaces
+# existed at all. That list was a second copy of pyproject.toml maintained by a
+# comment asking for lockstep, and every one of the four had drifted from the
+# manifest it mirrored.
+RUN pip install --no-cache-dir --require-hashes -r /requirements.txt
-# Dependencies come from poetry.lock, so two builds of this commit install
-# byte-identical versions. This layer deliberately copies only the manifest
-# and the lock, so it still caches across source edits — the reason the
-# hand-written `pip install` list it replaces existed at all. That list was a
-# second copy of pyproject.toml maintained by a comment asking for lockstep,
-# and every one of the four had drifted from the manifest it mirrored.
-RUN poetry install --no-interaction --no-ansi --only main --no-root
+# The manifest and the lock stay in the image as the record of what it was
+# built from. The dependency layer above no longer reads them, so metadata
+# edits that change no resolved version no longer rebuild it.
+COPY pyproject.toml poetry.lock ./
COPY alembic.ini .
COPY alembic/ alembic/