Files
pruefwerk/Dockerfile.agent
T
Sharang ParnerkarandClaude Opus 5.5 fe53d0a447
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 6m5s
feat(sast): C/C++ SAST for microcontroller firmware (#334)
C/C++ trees got only `semgrep --config=auto`, which returned nothing for
firmware code, and a failed semgrep run read as clean code.

- cppcheck (bookworm package) runs on C/C++ trees with the project's include
  directories, and its findings carry CWE, file:line and a snippet.
- Our own CRA C rules: unbounded string functions, scanf %s, non-literal
  format strings, hard-coded credentials, broken hashes/ciphers and rand()
  for keys and nonces, bound to cra-ai-8/13/16/20 in the control map, with
  cppcheck's memory-safety CWEs under cra-ai-20.
- Vendor SDK code (STM32Cube Drivers/, CMSIS, *_HAL_Driver, third_party) is
  left out of SAST and the run records which directories; the SBOM still
  covers it. A customer's own drivers/ and Zephyr's boards/vendor are kept.
- semgrep: --jobs 2; a run with no report becomes a recorded skipped stage;
  paths are relative to the tree, and snippets are read from the file
  (open-source semgrep only returns "requires login").
- Nightly fixture fw-c-sensor-node: every planted flaw is found, and the
  strcpy in the vendored HAL is not.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
2026-09-23 12:56:56 +02:00

119 lines
5.3 KiB
Docker

# Pinned versions of every tool the agent runs. They are also written to
# /opt/pruefwerk/tool-versions.json, so evidence can name the tool that
# produced a finding. Bump a version together with its checksum.
ARG RUST_VERSION=1.98.1
ARG CARGO_AUDIT_VERSION=0.22.2
ARG SYFT_VERSION=1.52.0
ARG SYFT_SHA256=caeedb81fb0491615f1ebd1761e4145d41ee86dd2cc7bf80669f9f5ad9d6133d
ARG GITLEAKS_VERSION=8.21.2
ARG GITLEAKS_SHA256=5bc41815076e6ed6ef8fbecc9d9b75bcae31f39029ceb55da08086315316e3ba
ARG SEMGREP_VERSION=1.177.0
ARG RUFF_VERSION=0.16.8
FROM rust:1.94-bookworm AS builder
WORKDIR /app
COPY . .
# compliance-agent depends on the private firmwerk git repo (platform/firmwerk). Authenticate
# the fetch with a PAT passed as a BuildKit secret (never baked into a layer).
# Build with: DOCKER_BUILDKIT=1 docker build --secret id=git_token,env=PLATFORM_CI_TOKEN ...
RUN --mount=type=secret,id=git_token \
if [ -s /run/secrets/git_token ]; then \
git config --global \
url."https://platform-ci:$(cat /run/secrets/git_token)@git.breakpilot.com/".insteadOf \
"ssh://git@git.breakpilot.com:22222/"; \
fi && \
CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --release -p compliance-agent
# cargo-audit is compiled here, where a C toolchain exists, so the runtime image
# needs none.
FROM rust:1.94-bookworm AS cargo-audit
ARG CARGO_AUDIT_VERSION
RUN cargo install cargo-audit --version "${CARGO_AUDIT_VERSION}" --locked
# The runtime without the agent binary: every scanner, pinned. Buildable on its
# own (`--target tools`), which is how the tool installs are tested.
FROM debian:bookworm-slim AS tools
ARG RUST_VERSION
ARG CARGO_AUDIT_VERSION
ARG SYFT_VERSION
ARG SYFT_SHA256
ARG GITLEAKS_VERSION
ARG GITLEAKS_SHA256
ARG SEMGREP_VERSION
ARG RUFF_VERSION
# No recommended packages: python3-pip would otherwise pull in a full C
# toolchain, which nothing at runtime needs.
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates libssl3 git curl python3 python3-pip npm cppcheck \
&& rm -rf /var/lib/apt/lists/*
# Cargo resolves Rust lockfiles and metadata for the SBOM stage. Installed
# system-wide so the unprivileged user can run it; its caches go to the user's
# CARGO_HOME below.
ENV RUSTUP_HOME=/usr/local/rustup \
PATH=/usr/local/cargo/bin:${PATH}
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
| CARGO_HOME=/usr/local/cargo sh -s -- -y --no-modify-path --profile minimal \
--default-toolchain "${RUST_VERSION}"
RUN curl -sSfL -o /tmp/syft.tar.gz \
"https://github.com/anchore/syft/releases/download/v${SYFT_VERSION}/syft_${SYFT_VERSION}_linux_amd64.tar.gz" \
&& echo "${SYFT_SHA256} /tmp/syft.tar.gz" | sha256sum -c - \
&& tar -xzf /tmp/syft.tar.gz -C /usr/local/bin syft \
&& rm /tmp/syft.tar.gz
RUN curl -sSfL -o /tmp/gitleaks.tar.gz \
"https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" \
&& echo "${GITLEAKS_SHA256} /tmp/gitleaks.tar.gz" | sha256sum -c - \
&& tar -xzf /tmp/gitleaks.tar.gz -C /usr/local/bin gitleaks \
&& rm /tmp/gitleaks.tar.gz
RUN pip3 install --break-system-packages --no-cache-dir \
"semgrep==${SEMGREP_VERSION}" "ruff==${RUFF_VERSION}"
RUN mkdir -p /opt/pruefwerk \
&& printf '{"rust":"%s","cargo-audit":"%s","syft":"%s","gitleaks":"%s","semgrep":"%s","ruff":"%s","cppcheck":"%s"}\n' \
"${RUST_VERSION}" "${CARGO_AUDIT_VERSION}" "${SYFT_VERSION}" "${GITLEAKS_VERSION}" \
"${SEMGREP_VERSION}" "${RUFF_VERSION}" "$(cppcheck --version | cut -d' ' -f2)" \
> /opt/pruefwerk/tool-versions.json
# The agent runs unprivileged. It writes only to its home (tool caches), the
# data root (uploaded artifacts, the OSCAL snapshot; mount a volume there) and
# /tmp (git checkouts), so the rest of the filesystem can be read-only.
RUN useradd --uid 10001 --user-group --create-home --home-dir /home/app --shell /usr/sbin/nologin app \
&& mkdir -p /data/compliance-scanner/artifacts /data/compliance-scanner/oscal \
&& chown -R app:app /data/compliance-scanner
ENV HOME=/home/app \
CARGO_HOME=/home/app/.cargo \
ARTIFACT_STORE_BASE_PATH=/data/compliance-scanner/artifacts \
BREAKPILOT_SNAPSHOT_DIR=/data/compliance-scanner/oscal
FROM tools
COPY --from=cargo-audit /usr/local/cargo/bin/cargo-audit /usr/local/cargo/bin/cargo-audit
COPY --from=builder /app/target/release/compliance-agent /usr/local/bin/compliance-agent
COPY --chmod=0755 docker/agent-entrypoint.sh /usr/local/bin/agent-entrypoint.sh
# OSCAL control-catalog snapshot: lets control mapping run without the
# breakpilot-compliance backend. The entrypoint seeds it into
# BREAKPILOT_SNAPSHOT_DIR on start (copy-if-absent).
COPY --from=builder /app/compliance-agent/controls/snapshot /opt/breakpilot/oscal-snapshot
# Copy documentation for the help chat assistant
COPY --from=builder /app/README.md /app/README.md
COPY --from=builder /app/docs /app/docs
ENV HELP_DOCS_PATH=/app
USER app
EXPOSE 3001 3002
# Liveness from the agent's own health endpoint (#262 makes it report its
# dependencies too).
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
CMD curl -fsS "http://127.0.0.1:${AGENT_PORT:-3001}/api/v1/health" || exit 1
# Checks the data directories are writable, seeds the OSCAL snapshot, then runs
# the agent.
ENTRYPOINT ["/usr/local/bin/agent-entrypoint.sh"]