build: bake the pinned nuclei template set into the image

nuclei carries no templates in the binary: on first run it clones
projectdiscovery/nuclei-templates into $HOME/nuclei-templates. Where the process
cannot reach github.com that install fails softly. It logs

    nuclei-templates are not installed, installing...
    Could not find template '.../nuclei-templates': no templates found in path

and exits 0, so a scan starts against an empty template set and looks like a
broken tool rather than a missing one. Egress to github.com is exactly what an
allowlist blocks, and an agent-run scan never has the root home the image is
built with: the executor's HOME is /app/data/exec-home (server/execpriv_unix.go).

Bake the set in the tools stage at a fixed path, pinned by tag and asserted by
commit so a moved tag fails the build, and point NUCLEI_TEMPLATES_DIR at it in
the runtime stage. The lookup then does not depend on HOME or on the user the
process runs as, and no runtime egress is needed.

v10.5.1 is 14,104 YAML templates / 84 MB on disk, against the image's current
~6.5 GB. The build now asserts the count twice: more than 10,000 files in the
tools stage, and a non-empty `nuclei -tl -silent` listing in the runtime stage,
which is what catches the env var being dropped later.
This commit is contained in:
Pedro Gomes
2026-11-20 09:25:18 +00:00
parent ab40834567
commit 176e1c85af
+35 -2
View File
@@ -102,6 +102,30 @@ RUN set -eux; \
if [ "$commit" != "$SQLMAP_COMMIT" ]; then echo "sqlmap commit mismatch: want $SQLMAP_COMMIT got $commit" >&2; exit 1; fi; \
rm -rf /opt/sqlmap/.git
# -------------------------------------------------------- nuclei templates ---
# nuclei ships no templates in the binary: on first run it clones
# projectdiscovery/nuclei-templates into $HOME/nuclei-templates. Where the process
# cannot reach github.com that install fails softly — it logs "nuclei-templates are
# not installed, installing...", then "no templates found in path", and exits 0, so a
# scan starts with an empty template set and looks like a broken tool. That is the
# normal case behind an egress allowlist, and the case for every agent-run scan: the
# executor's HOME is /app/data/exec-home, not the root-owned home the image is
# built with. Bake the set at a fixed path instead, and point nuclei at it with
# NUCLEI_TEMPLATES_DIR in the runtime stage, so the lookup does not depend on HOME or
# on which user the process runs as. Tag and commit are both pinned and asserted: a
# moved tag fails the build rather than silently changing the template set.
ARG NUCLEI_TEMPLATES_VERSION=v10.5.1
ARG NUCLEI_TEMPLATES_COMMIT=79fb682760ab3d5b0e22afbb44709353cbebf023
RUN set -eux; \
git clone --quiet --depth 1 --branch "$NUCLEI_TEMPLATES_VERSION" \
https://github.com/projectdiscovery/nuclei-templates /opt/nuclei-templates; \
commit="$(git -C /opt/nuclei-templates rev-parse HEAD)"; \
if [ "$commit" != "$NUCLEI_TEMPLATES_COMMIT" ]; then echo "nuclei-templates commit mismatch: want $NUCLEI_TEMPLATES_COMMIT got $commit" >&2; exit 1; fi; \
rm -rf /opt/nuclei-templates/.git; \
count="$(find /opt/nuclei-templates -name '*.yaml' | wc -l)"; \
echo "baked nuclei templates: $count"; \
test "$count" -gt 10000
# ---------------------------------------------------------------- runtime ---
FROM python:3.12-slim-bookworm
ARG TARGETARCH
@@ -131,13 +155,22 @@ RUN set -eux; \
tar -xJf "/tmp/$asset" -C /usr/local --strip-components=1 --no-same-owner; \
rm -f "/tmp/$asset" /tmp/SHASUMS256.txt; \
node --version; npm --version
# Pinned, checksum-verified recon binaries and the sqlmap checkout from the tools stage.
# Pinned, checksum-verified recon binaries and the sqlmap checkout from the tools stage,
# plus the baked nuclei template set (see the tools stage for why it is baked).
COPY --from=tools /out/ /usr/local/bin/
COPY --from=tools /opt/sqlmap /opt/sqlmap
COPY --from=tools /opt/nuclei-templates /opt/nuclei-templates
# Read by nuclei in preference to $HOME/nuclei-templates, so root and the executor
# resolve the same set. The directory stays root-owned and world-readable; scans
# never need to write to it.
ENV NUCLEI_TEMPLATES_DIR=/opt/nuclei-templates
RUN set -eux; \
ln -s /opt/sqlmap/sqlmap.py /usr/local/bin/sqlmap; \
nuclei -version >/dev/null; httpx -version; subfinder -version; katana -version; \
ffuf -V >/dev/null; dalfox --version >/dev/null; sqlmap --version >/dev/null
ffuf -V >/dev/null; dalfox --version >/dev/null; sqlmap --version >/dev/null; \
templates="$(nuclei -tl -silent | wc -l)"; \
echo "nuclei templates visible at build time: $templates"; \
test "$templates" -gt 10000
# bbot recursive recon orchestrator (#117): blacklanternsecurity/bbot, AGPL-3.0
# (same license as ARTEX; standalone CLI dependency, not linked code). Pinned