Dockerfile 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. ARG UNBOUND_VERSION=1.26.2
  15. ARG LDNS_VERSION=1.9.2
  16. ARG XX_VERSION=1.9.0
  17. ARG ALPINE_VERSION=3.24
  18. FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
  19. FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION} AS base
  20. COPY --from=xx / /
  21. RUN apk --update --no-cache add binutils clang curl file make pkgconf tar tree xz
  22. FROM base AS base-build
  23. ENV XX_CC_PREFER_LINKER=ld
  24. ARG TARGETPLATFORM
  25. RUN xx-apk --no-cache add gcc g++ expat-dev hiredis hiredis-dev libevent-dev libcap libpcap-dev openssl-dev perl \
  26. && xx-clang --setup-target-triple
  27. FROM base AS unbound-src
  28. WORKDIR /src/unbound
  29. ARG UNBOUND_VERSION
  30. RUN curl -sSL "https://unbound.net/downloads/unbound-${UNBOUND_VERSION}.tar.gz" | tar xz --strip 1
  31. FROM base AS ldns-src
  32. WORKDIR /src/ldns
  33. ARG LDNS_VERSION
  34. RUN curl -sSL "https://nlnetlabs.nl/downloads/ldns/ldns-${LDNS_VERSION}.tar.gz" | tar xz --strip 1
  35. FROM base-build AS unbound-build
  36. WORKDIR /src/unbound
  37. RUN --mount=type=bind,from=unbound-src,source=/src/unbound,target=.,rw <<EOT
  38. set -ex
  39. CC=xx-clang CXX=xx-clang++ ./configure \
  40. --host=$(xx-clang --print-target-triple) \
  41. --prefix=/usr \
  42. --sysconfdir=/etc \
  43. --mandir=/usr/share/man \
  44. --localstatedir=/var \
  45. --with-chroot-dir="" \
  46. --with-pidfile=/var/run/unbound/unbound.pid \
  47. --with-run-dir=/var/run/unbound \
  48. --with-username="" \
  49. --disable-flto \
  50. --disable-rpath \
  51. --disable-shared \
  52. --enable-cachedb \
  53. --enable-event-api \
  54. --with-pthreads \
  55. --with-libhiredis=$(xx-info sysroot)usr \
  56. --with-libexpat=$(xx-info sysroot)usr \
  57. --with-libevent=$(xx-info sysroot)usr \
  58. --with-ssl=$(xx-info sysroot)usr
  59. make DESTDIR=/out install
  60. make DESTDIR=/out unbound-event-install
  61. install -Dm755 contrib/update-anchor.sh /out/usr/share/unbound/update-anchor.sh
  62. xx-verify /out/usr/sbin/unbound
  63. xx-verify /out/usr/sbin/unbound-anchor
  64. xx-verify /out/usr/sbin/unbound-checkconf
  65. xx-verify /out/usr/sbin/unbound-control
  66. xx-verify /out/usr/sbin/unbound-host
  67. file /out/usr/sbin/unbound
  68. EOT
  69. FROM base-build AS ldns-build
  70. WORKDIR /src/ldns
  71. RUN --mount=type=bind,from=ldns-src,source=/src/ldns,target=.,rw <<EOT
  72. set -ex
  73. CC=xx-clang CXX=xx-clang++ CPPFLAGS=-I/src/ldns/ldns ./configure \
  74. --host=$(xx-clang --print-target-triple) \
  75. --prefix=/usr \
  76. --sysconfdir=/etc \
  77. --mandir=/usr/share/man \
  78. --infodir=/usr/share/info \
  79. --localstatedir=/var \
  80. --disable-gost \
  81. --disable-rpath \
  82. --disable-shared \
  83. --with-drill \
  84. --with-ssl=$(xx-info sysroot)usr
  85. make DESTDIR=/out install
  86. xx-verify /out/usr/bin/drill
  87. file /out/usr/bin/drill
  88. EOT
  89. FROM alpine:${ALPINE_VERSION}
  90. COPY --from=unbound-build /out /
  91. COPY --from=ldns-build /out /
  92. # Runtime deps only. No dns-root-hints (would pull curl+nghttp2+zlib; unbound
  93. # has root servers built in), no shadow (only needed at build for adduser).
  94. RUN apk --update --no-cache add \
  95. ca-certificates \
  96. dnssec-root \
  97. expat \
  98. hiredis \
  99. libevent \
  100. libpcap \
  101. openssl \
  102. && mkdir -p /run/unbound \
  103. && unbound -V \
  104. && ldns-config --version
  105. COPY entrypoint.sh /entrypoint.sh
  106. COPY config/unbound.conf /etc/unbound/unbound.conf
  107. RUN chmod 755 /entrypoint.sh \
  108. && mkdir -p /config \
  109. && addgroup -g 1500 unbound \
  110. && adduser -D -H -u 1500 -G unbound -s /bin/sh unbound \
  111. && chown -R unbound:unbound /etc/unbound /run/unbound \
  112. && apk del --no-cache shadow \
  113. && rm -rf /tmp/* /var/cache/apk/*
  114. USER unbound
  115. EXPOSE 5053/tcp
  116. EXPOSE 5053/udp
  117. VOLUME ["/config"]
  118. HEALTHCHECK --interval=30s --timeout=10s \
  119. CMD drill -p 5053 unbound.net @127.0.0.1
  120. ENTRYPOINT ["sh", "/entrypoint.sh"]
  121. CMD [""]