fix(security): minimize runtime images and enforce complete vulnerability scans
This commit is contained in:
1 parent
0c1fb38e31
commit
f685616ae8
13 files changed
+2736
-37
No files matched your search
+29
-10
@@ -15,33 +15,52 @@ RUN --mount=type=cache,id=crank-admin-cargo-registry,target=/usr/local/cargo/reg
|
||||
&& cp /app/target/release/admin-api /tmp/admin-api \
|
||||
&& cp /app/target/release/crank-migrate /tmp/crank-migrate
|
||||
|
||||
FROM debian:bookworm-slim
|
||||
# Trusted CA bundle source for the package stage. The slim image ships no CA
|
||||
# certificates, so the HTTPS Debian mirror can only be reached after seeding
|
||||
# them; the Rust base image provides the bundle without rebuilding the app.
|
||||
FROM rust:1.96.1-bookworm AS ca-bundle
|
||||
|
||||
RUN test -s /etc/ssl/certs/ca-certificates.crt
|
||||
|
||||
# Package stage: install the security-refreshed Debian packages, then assemble
|
||||
# the minimal runtime rootfs. Kept independent of the Rust builder so it can be
|
||||
# built and reviewed on its own.
|
||||
FROM debian:bookworm-slim AS runtime-rootfs
|
||||
|
||||
ARG CRANK_SECURITY_REFRESH
|
||||
|
||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||
COPY --from=ca-bundle /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||
COPY scripts/prepare-runtime-rootfs.sh /usr/local/bin/prepare-runtime-rootfs
|
||||
|
||||
RUN sed -i 's|http://deb.debian.org|https://deb.debian.org|g' /etc/apt/sources.list.d/debian.sources \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y --no-install-recommends --only-upgrade libpcre2-8-0 perl-base \
|
||||
&& apt-get install -y --no-install-recommends --only-upgrade \
|
||||
base-files libc6 libgcc-s1 gcc-12-base bash dash libtinfo6 libselinux1 libpcre2-8-0 coreutils \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& dpkg --compare-versions "$(dpkg-query -W -f='${Version}' libpcre2-8-0)" ge '10.42-1+deb12u2' \
|
||||
&& dpkg --compare-versions "$(dpkg-query -W -f='${Version}' perl-base)" ge '5.36.0-7+deb12u4' \
|
||||
&& sh /usr/local/bin/prepare-runtime-rootfs /runtime \
|
||||
&& echo "crank-security-refresh=${CRANK_SECURITY_REFRESH}"
|
||||
|
||||
WORKDIR /app
|
||||
COPY apps/admin-api/docker-entrypoint.sh /runtime/usr/local/bin/crank-admin-entrypoint
|
||||
COPY scripts/docker-http-healthcheck.sh /runtime/usr/local/bin/crank-http-healthcheck
|
||||
|
||||
RUN chmod 0755 /runtime/usr/local/bin/crank-admin-entrypoint \
|
||||
&& chmod 0755 /runtime/usr/local/bin/crank-http-healthcheck
|
||||
|
||||
FROM scratch
|
||||
|
||||
COPY --from=ca-bundle /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||
COPY --from=runtime-rootfs /runtime /
|
||||
|
||||
COPY --from=builder /tmp/admin-api /usr/local/bin/admin-api
|
||||
COPY --from=builder /tmp/crank-migrate /usr/local/bin/crank-migrate
|
||||
COPY apps/admin-api/docker-entrypoint.sh /usr/local/bin/crank-admin-entrypoint
|
||||
COPY scripts/docker-http-healthcheck.sh /usr/local/bin/crank-http-healthcheck
|
||||
|
||||
RUN test -s /etc/ssl/certs/ca-certificates.crt \
|
||||
&& chmod 0755 /usr/local/bin/crank-admin-entrypoint /usr/local/bin/crank-http-healthcheck
|
||||
|
||||
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
ENV CRANK_ADMIN_BIND=0.0.0.0:3001
|
||||
ENV CRANK_STORAGE_ROOT=/var/lib/crank/storage
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
EXPOSE 3001
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/crank-admin-entrypoint"]
|
||||
|
||||
@@ -4,7 +4,7 @@ set -eu
|
||||
# Docker creates a fresh named volume as root:root 0755. The artifact store
|
||||
# deliberately rejects that mode: before starting the API, provision exactly
|
||||
# the private root its pinned-directory checks require.
|
||||
if [ "$#" -gt 0 ] && [ "$1" = "admin-api" ]; then
|
||||
provision_storage_root() {
|
||||
storage_root="${CRANK_STORAGE_ROOT:-/var/lib/crank/storage}"
|
||||
case "$storage_root" in
|
||||
/*) ;;
|
||||
@@ -20,6 +20,17 @@ if [ "$#" -gt 0 ] && [ "$1" = "admin-api" ]; then
|
||||
umask 077
|
||||
mkdir -p -- "$storage_root"
|
||||
chmod 0700 -- "$storage_root"
|
||||
}
|
||||
|
||||
# The dedicated init service calls this entrypoint as `crank-storage-init`; it
|
||||
# provisions the artifact root and exits without running a server binary.
|
||||
if [ "${1:-}" = "crank-storage-init" ]; then
|
||||
provision_storage_root
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "${1:-}" = "admin-api" ]; then
|
||||
provision_storage_root
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
Reference in new issue
Block a user