| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- # syntax=docker/dockerfile:1
- #
- # unbound-sec: security-hardened Unbound Docker image (crazymax/unbound replacement)
- #
- # Security deltas vs. crazymax/unbound:
- # - Unbound 1.26.2 (security release; fixes CVE-2026-97206, CVE-2026-96405,
- # CVE-2026-109125, CVE-2026-50106, CVE-2026-35501)
- # - no dns-root-hints package -> no curl/nghttp2/zlib/c-ares/brotli in runtime
- # (fixes CVE-2026-58055, CVE-2026-85091; unbound has root servers built in)
- # - current Alpine 3.24 expat 2.9.0 (fixes CVE-2026-77214, CVE-2026-93990,
- # CVE-2026-102633)
- # - shadow package removed after user creation -> no SUID-root binaries
- # - hide-identity / hide-version enabled (no version leak via CHAOS queries)
- #
- # Improvements adopted from the 10/2026 comparison with other unbound images
- # (mvance/unbound, klutchell/unbound, madnuttah/unbound — see README):
- # - source tarballs: SHA256 check + GPG signature (NLnet Labs release key G2)
- # - base images pinned by digest (reproducible builds)
- # - binary hardening: --enable-pie --enable-relro-now
- # - features: --enable-subnet (EDNS Client Subnet), TFO server + client
- ARG UNBOUND_VERSION=1.26.2
- ARG UNBOUND_SHA256=d8ee7aa6bbb3ff1be7d9e57637d0d0ec2f18273a8efff1a0afe2c665858b96f7
- ARG LDNS_VERSION=1.9.2
- ARG LDNS_SHA256=b524fa21994b6e834200ceb8c27f1b84bda5982fe35706f058196c079db94d5d
- ARG XX_VERSION=1.9.0
- ARG XX_DIGEST=sha256:c64defb9ed5a91eacb37f96ccc3d4cd72521c4bd18d5442905b95e2226b0e707
- ARG ALPINE_VERSION=3.24
- ARG ALPINE_DIGEST=sha256:71e9b7bae160ba167fa17414401b94cbcdaf3c32feeab9298bd794a2a0614c35
- FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION}@${XX_DIGEST} AS xx
- FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION}@${ALPINE_DIGEST} AS base
- COPY --from=xx / /
- RUN apk --update --no-cache add binutils clang curl file gnupg make pkgconf tar tree xz
- FROM base AS base-build
- ENV XX_CC_PREFER_LINKER=ld
- ARG TARGETPLATFORM
- RUN xx-apk --no-cache add gcc g++ expat-dev hiredis hiredis-dev libevent-dev libcap libpcap-dev openssl-dev perl \
- && xx-clang --setup-target-triple
- FROM base AS unbound-src
- WORKDIR /src/unbound
- ARG UNBOUND_VERSION
- ARG UNBOUND_SHA256
- # CACHEBUST: test suite passes a timestamp so integrity verification (SHA256 +
- # GPG) re-runs on every test run even when the build stages are cached.
- ARG CACHEBUST
- RUN set -eux \
- && echo "cachebust=$CACHEBUST" \
- && curl -sSL "https://unbound.net/downloads/unbound-${UNBOUND_VERSION}.tar.gz" -o unbound.tar.gz \
- && curl -sSL "https://unbound.net/downloads/unbound-${UNBOUND_VERSION}.tar.gz.asc" -o unbound.tar.gz.asc \
- && echo "${UNBOUND_SHA256} unbound.tar.gz" | sha256sum -c - \
- && export GNUPGHOME="$(mktemp -d)" \
- && curl -sSL "https://nlnetlabs.nl/downloads/keys/releases-g2.asc" -o "$GNUPGHOME/releases-g2.asc" \
- && gpg --no-tty --import "$GNUPGHOME/releases-g2.asc" \
- && gpg --batch --verify unbound.tar.gz.asc unbound.tar.gz \
- && tar xzf unbound.tar.gz --strip 1
- FROM base AS ldns-src
- WORKDIR /src/ldns
- ARG LDNS_VERSION
- ARG LDNS_SHA256
- ARG CACHEBUST
- RUN set -eux \
- && echo "cachebust=$CACHEBUST" \
- && curl -sSL "https://nlnetlabs.nl/downloads/ldns/ldns-${LDNS_VERSION}.tar.gz" -o ldns.tar.gz \
- && curl -sSL "https://nlnetlabs.nl/downloads/ldns/ldns-${LDNS_VERSION}.tar.gz.asc" -o ldns.tar.gz.asc \
- && echo "${LDNS_SHA256} ldns.tar.gz" | sha256sum -c - \
- && export GNUPGHOME="$(mktemp -d)" \
- && curl -sSL "https://nlnetlabs.nl/downloads/keys/releases-g2.asc" -o "$GNUPGHOME/releases-g2.asc" \
- && gpg --no-tty --import "$GNUPGHOME/releases-g2.asc" \
- && gpg --batch --verify ldns.tar.gz.asc ldns.tar.gz \
- && tar xzf ldns.tar.gz --strip 1
- FROM base-build AS unbound-build
- WORKDIR /src/unbound
- RUN --mount=type=bind,from=unbound-src,source=/src/unbound,target=.,rw <<EOT
- set -ex
- CC=xx-clang CXX=xx-clang++ ./configure \
- --host=$(xx-clang --print-target-triple) \
- --prefix=/usr \
- --sysconfdir=/etc \
- --mandir=/usr/share/man \
- --localstatedir=/var \
- --with-chroot-dir="" \
- --with-pidfile=/var/run/unbound/unbound.pid \
- --with-run-dir=/var/run/unbound \
- --with-username="" \
- --disable-flto \
- --disable-rpath \
- --disable-shared \
- --enable-cachedb \
- --enable-event-api \
- --enable-subnet \
- --enable-tfo-server \
- --enable-tfo-client \
- --enable-pie \
- --enable-relro-now \
- --with-pthreads \
- --with-libhiredis=$(xx-info sysroot)usr \
- --with-libexpat=$(xx-info sysroot)usr \
- --with-libevent=$(xx-info sysroot)usr \
- --with-ssl=$(xx-info sysroot)usr
- make DESTDIR=/out install
- make DESTDIR=/out unbound-event-install
- install -Dm755 contrib/update-anchor.sh /out/usr/share/unbound/update-anchor.sh
- xx-verify /out/usr/sbin/unbound
- xx-verify /out/usr/sbin/unbound-anchor
- xx-verify /out/usr/sbin/unbound-checkconf
- xx-verify /out/usr/sbin/unbound-control
- xx-verify /out/usr/sbin/unbound-host
- # build-log evidence for the test suite (asserts "pie executable")
- file /out/usr/sbin/unbound
- EOT
- FROM base-build AS ldns-build
- WORKDIR /src/ldns
- RUN --mount=type=bind,from=ldns-src,source=/src/ldns,target=.,rw <<EOT
- set -ex
- CC=xx-clang CXX=xx-clang++ CPPFLAGS=-I/src/ldns/ldns ./configure \
- --host=$(xx-clang --print-target-triple) \
- --prefix=/usr \
- --sysconfdir=/etc \
- --mandir=/usr/share/man \
- --infodir=/usr/share/info \
- --localstatedir=/var \
- --disable-gost \
- --disable-rpath \
- --disable-shared \
- --with-drill \
- --with-ssl=$(xx-info sysroot)usr
- make DESTDIR=/out install
- xx-verify /out/usr/bin/drill
- file /out/usr/bin/drill
- EOT
- FROM alpine:${ALPINE_VERSION}@${ALPINE_DIGEST}
- COPY --from=unbound-build /out /
- COPY --from=ldns-build /out /
- # Runtime deps only. No dns-root-hints (would pull curl+nghttp2+zlib; unbound
- # has root servers built in), no shadow (only needed at build for adduser).
- RUN apk --update --no-cache add \
- ca-certificates \
- dnssec-root \
- expat \
- hiredis \
- libevent \
- libpcap \
- openssl \
- && mkdir -p /run/unbound \
- && unbound -V \
- && ldns-config --version
- COPY entrypoint.sh /entrypoint.sh
- COPY config/unbound.conf /etc/unbound/unbound.conf
- RUN chmod 755 /entrypoint.sh \
- && mkdir -p /config \
- && addgroup -g 1500 unbound \
- && adduser -D -H -u 1500 -G unbound -s /bin/sh unbound \
- && chown -R unbound:unbound /etc/unbound /run/unbound \
- && apk del --no-cache shadow \
- && rm -rf /tmp/* /var/cache/apk/*
- USER unbound
- EXPOSE 5053/tcp
- EXPOSE 5053/udp
- VOLUME ["/config"]
- HEALTHCHECK --interval=30s --timeout=10s \
- CMD drill -p 5053 unbound.net @127.0.0.1
- ENTRYPOINT ["sh", "/entrypoint.sh"]
- CMD [""]
|