| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- # 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)
- ARG UNBOUND_VERSION=1.26.2
- ARG LDNS_VERSION=1.9.2
- ARG XX_VERSION=1.9.0
- ARG ALPINE_VERSION=3.24
- FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
- FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION} AS base
- COPY --from=xx / /
- RUN apk --update --no-cache add binutils clang curl file 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
- RUN curl -sSL "https://unbound.net/downloads/unbound-${UNBOUND_VERSION}.tar.gz" | tar xz --strip 1
- FROM base AS ldns-src
- WORKDIR /src/ldns
- ARG LDNS_VERSION
- RUN curl -sSL "https://nlnetlabs.nl/downloads/ldns/ldns-${LDNS_VERSION}.tar.gz" | tar xz --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 \
- --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
- 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}
- 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 [""]
|