Dockerfile 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. # syntax=docker/dockerfile:1
  2. #
  3. # unbound-sec: security-hardened Unbound Docker image (crazymax/unbound replacement)
  4. #
  5. # Security deltas vs. crazymax/unbound:
  6. # - Unbound 1.26.2 (security release; fixes CVE-2026-97206, CVE-2026-96405,
  7. # CVE-2026-109125, CVE-2026-50106, CVE-2026-35501)
  8. # - no dns-root-hints package -> no curl/nghttp2/zlib/c-ares/brotli in runtime
  9. # (fixes CVE-2026-58055, CVE-2026-85091; unbound has root servers built in)
  10. # - current Alpine 3.24 expat 2.9.0 (fixes CVE-2026-77214, CVE-2026-93990,
  11. # CVE-2026-102633)
  12. # - shadow package removed after user creation -> no SUID-root binaries
  13. # - hide-identity / hide-version enabled (no version leak via CHAOS queries)
  14. #
  15. # Improvements adopted from the 10/2026 comparison with other unbound images
  16. # (mvance/unbound, klutchell/unbound, madnuttah/unbound — see README):
  17. # - source tarballs: SHA256 check + GPG signature (NLnet Labs release key G2)
  18. # - base images pinned by digest (reproducible builds)
  19. # - binary hardening: --enable-pie --enable-relro-now
  20. # - features: --enable-subnet (EDNS Client Subnet), TFO server + client
  21. ARG UNBOUND_VERSION=1.26.2
  22. ARG UNBOUND_SHA256=d8ee7aa6bbb3ff1be7d9e57637d0d0ec2f18273a8efff1a0afe2c665858b96f7
  23. ARG LDNS_VERSION=1.9.2
  24. ARG LDNS_SHA256=b524fa21994b6e834200ceb8c27f1b84bda5982fe35706f058196c079db94d5d
  25. ARG XX_VERSION=1.9.0
  26. ARG XX_DIGEST=sha256:c64defb9ed5a91eacb37f96ccc3d4cd72521c4bd18d5442905b95e2226b0e707
  27. ARG ALPINE_VERSION=3.24
  28. ARG ALPINE_DIGEST=sha256:71e9b7bae160ba167fa17414401b94cbcdaf3c32feeab9298bd794a2a0614c35
  29. FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION}@${XX_DIGEST} AS xx
  30. FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION}@${ALPINE_DIGEST} AS base
  31. COPY --from=xx / /
  32. RUN apk --update --no-cache add binutils clang curl file gnupg make pkgconf tar tree xz
  33. FROM base AS base-build
  34. ENV XX_CC_PREFER_LINKER=ld
  35. ARG TARGETPLATFORM
  36. RUN xx-apk --no-cache add gcc g++ expat-dev hiredis hiredis-dev libevent-dev libcap libpcap-dev openssl-dev perl \
  37. && xx-clang --setup-target-triple
  38. FROM base AS unbound-src
  39. WORKDIR /src/unbound
  40. ARG UNBOUND_VERSION
  41. ARG UNBOUND_SHA256
  42. # CACHEBUST: test suite passes a timestamp so integrity verification (SHA256 +
  43. # GPG) re-runs on every test run even when the build stages are cached.
  44. ARG CACHEBUST
  45. RUN set -eux \
  46. && echo "cachebust=$CACHEBUST" \
  47. && curl -sSL "https://unbound.net/downloads/unbound-${UNBOUND_VERSION}.tar.gz" -o unbound.tar.gz \
  48. && curl -sSL "https://unbound.net/downloads/unbound-${UNBOUND_VERSION}.tar.gz.asc" -o unbound.tar.gz.asc \
  49. && echo "${UNBOUND_SHA256} unbound.tar.gz" | sha256sum -c - \
  50. && export GNUPGHOME="$(mktemp -d)" \
  51. && curl -sSL "https://nlnetlabs.nl/downloads/keys/releases-g2.asc" -o "$GNUPGHOME/releases-g2.asc" \
  52. && gpg --no-tty --import "$GNUPGHOME/releases-g2.asc" \
  53. && gpg --batch --verify unbound.tar.gz.asc unbound.tar.gz \
  54. && tar xzf unbound.tar.gz --strip 1
  55. FROM base AS ldns-src
  56. WORKDIR /src/ldns
  57. ARG LDNS_VERSION
  58. ARG LDNS_SHA256
  59. ARG CACHEBUST
  60. RUN set -eux \
  61. && echo "cachebust=$CACHEBUST" \
  62. && curl -sSL "https://nlnetlabs.nl/downloads/ldns/ldns-${LDNS_VERSION}.tar.gz" -o ldns.tar.gz \
  63. && curl -sSL "https://nlnetlabs.nl/downloads/ldns/ldns-${LDNS_VERSION}.tar.gz.asc" -o ldns.tar.gz.asc \
  64. && echo "${LDNS_SHA256} ldns.tar.gz" | sha256sum -c - \
  65. && export GNUPGHOME="$(mktemp -d)" \
  66. && curl -sSL "https://nlnetlabs.nl/downloads/keys/releases-g2.asc" -o "$GNUPGHOME/releases-g2.asc" \
  67. && gpg --no-tty --import "$GNUPGHOME/releases-g2.asc" \
  68. && gpg --batch --verify ldns.tar.gz.asc ldns.tar.gz \
  69. && tar xzf ldns.tar.gz --strip 1
  70. FROM base-build AS unbound-build
  71. WORKDIR /src/unbound
  72. RUN --mount=type=bind,from=unbound-src,source=/src/unbound,target=.,rw <<EOT
  73. set -ex
  74. CC=xx-clang CXX=xx-clang++ ./configure \
  75. --host=$(xx-clang --print-target-triple) \
  76. --prefix=/usr \
  77. --sysconfdir=/etc \
  78. --mandir=/usr/share/man \
  79. --localstatedir=/var \
  80. --with-chroot-dir="" \
  81. --with-pidfile=/var/run/unbound/unbound.pid \
  82. --with-run-dir=/var/run/unbound \
  83. --with-username="" \
  84. --disable-flto \
  85. --disable-rpath \
  86. --disable-shared \
  87. --enable-cachedb \
  88. --enable-event-api \
  89. --enable-subnet \
  90. --enable-tfo-server \
  91. --enable-tfo-client \
  92. --enable-pie \
  93. --enable-relro-now \
  94. --with-pthreads \
  95. --with-libhiredis=$(xx-info sysroot)usr \
  96. --with-libexpat=$(xx-info sysroot)usr \
  97. --with-libevent=$(xx-info sysroot)usr \
  98. --with-ssl=$(xx-info sysroot)usr
  99. make DESTDIR=/out install
  100. make DESTDIR=/out unbound-event-install
  101. install -Dm755 contrib/update-anchor.sh /out/usr/share/unbound/update-anchor.sh
  102. xx-verify /out/usr/sbin/unbound
  103. xx-verify /out/usr/sbin/unbound-anchor
  104. xx-verify /out/usr/sbin/unbound-checkconf
  105. xx-verify /out/usr/sbin/unbound-control
  106. xx-verify /out/usr/sbin/unbound-host
  107. # build-log evidence for the test suite (asserts "pie executable")
  108. file /out/usr/sbin/unbound
  109. EOT
  110. FROM base-build AS ldns-build
  111. WORKDIR /src/ldns
  112. RUN --mount=type=bind,from=ldns-src,source=/src/ldns,target=.,rw <<EOT
  113. set -ex
  114. CC=xx-clang CXX=xx-clang++ CPPFLAGS=-I/src/ldns/ldns ./configure \
  115. --host=$(xx-clang --print-target-triple) \
  116. --prefix=/usr \
  117. --sysconfdir=/etc \
  118. --mandir=/usr/share/man \
  119. --infodir=/usr/share/info \
  120. --localstatedir=/var \
  121. --disable-gost \
  122. --disable-rpath \
  123. --disable-shared \
  124. --with-drill \
  125. --with-ssl=$(xx-info sysroot)usr
  126. make DESTDIR=/out install
  127. xx-verify /out/usr/bin/drill
  128. file /out/usr/bin/drill
  129. EOT
  130. FROM alpine:${ALPINE_VERSION}@${ALPINE_DIGEST}
  131. COPY --from=unbound-build /out /
  132. COPY --from=ldns-build /out /
  133. # Runtime deps only. No dns-root-hints (would pull curl+nghttp2+zlib; unbound
  134. # has root servers built in), no shadow (only needed at build for adduser).
  135. RUN apk --update --no-cache add \
  136. ca-certificates \
  137. dnssec-root \
  138. expat \
  139. hiredis \
  140. libevent \
  141. libpcap \
  142. openssl \
  143. && mkdir -p /run/unbound \
  144. && unbound -V \
  145. && ldns-config --version
  146. COPY entrypoint.sh /entrypoint.sh
  147. COPY config/unbound.conf /etc/unbound/unbound.conf
  148. RUN chmod 755 /entrypoint.sh \
  149. && mkdir -p /config \
  150. && addgroup -g 1500 unbound \
  151. && adduser -D -H -u 1500 -G unbound -s /bin/sh unbound \
  152. && chown -R unbound:unbound /etc/unbound /run/unbound \
  153. && apk del --no-cache shadow \
  154. && rm -rf /tmp/* /var/cache/apk/*
  155. USER unbound
  156. EXPOSE 5053/tcp
  157. EXPOSE 5053/udp
  158. VOLUME ["/config"]
  159. HEALTHCHECK --interval=30s --timeout=10s \
  160. CMD drill -p 5053 unbound.net @127.0.0.1
  161. ENTRYPOINT ["sh", "/entrypoint.sh"]
  162. CMD [""]