Browse Source

v0.2.0: adopt improvements from unbound image comparison (GPG+SHA256, digest pins, PIE/RELRO, ECS, TFO)

ric 1 month ago
parent
commit
7e560b09b2
5 changed files with 174 additions and 14 deletions
  1. 18 0
      CHANGELOG.md
  2. 47 6
      Dockerfile
  3. 48 1
      README.md
  4. 21 6
      docs/vanilla-deviations.md
  5. 40 1
      test/run-tests.sh

+ 18 - 0
CHANGELOG.md

@@ -2,6 +2,24 @@
 
 All notable changes to this project are documented here.
 
+## [0.2.0] - 2026-10-23
+
+### Added (adopted from comparison with mvance/klutchell/madnuttah unbound images)
+- Supply chain: source tarballs (unbound + ldns) verified by SHA256 (pinned
+  in Dockerfile) **and GPG signature** (NLnet Labs releases key G2) before
+  extraction.
+- Base images pinned by digest (`alpine:3.24`, `tonistiigi/xx:1.9.0`) →
+  reproducible builds.
+- Binary hardening: `--enable-pie --enable-relro-now`.
+- `--enable-subnet` (EDNS Client Subnet, inactive by default — opt in via
+  config) and `--enable-tfo-server --enable-tfo-client` (TCP Fast Open).
+- Test suite extended: 19 → 27 assertions (GPG/SHA256 build-log evidence
+  with per-run cache-bust, PIE via ELF e_type of the final binary,
+  compiled feature flags via `unbound -V` configure line).
+- README: comparison table of the relevant unbound images on Docker Hub,
+  adopted vs. deliberately skipped improvements (DNSCrypt/libsodium, DoH/
+  nghttp2, DNSTAP/protobuf-c, distroless final stage).
+
 ## [0.1.0] - 2026-10-23
 
 ### Added

+ 47 - 6
Dockerfile

@@ -11,17 +11,28 @@
 #     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} AS xx
+FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION}@${XX_DIGEST} AS xx
 
-FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION} AS base
+FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION}@${ALPINE_DIGEST} AS base
 COPY --from=xx / /
-RUN apk --update --no-cache add binutils clang curl file make pkgconf tar tree xz
+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
@@ -32,12 +43,36 @@ RUN xx-apk --no-cache add gcc g++ expat-dev hiredis hiredis-dev libevent-dev lib
 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
+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
-RUN curl -sSL "https://nlnetlabs.nl/downloads/ldns/ldns-${LDNS_VERSION}.tar.gz" | tar xz --strip 1
+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
@@ -58,6 +93,11 @@ RUN --mount=type=bind,from=unbound-src,source=/src/unbound,target=.,rw <<EOT
     --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 \
@@ -71,6 +111,7 @@ RUN --mount=type=bind,from=unbound-src,source=/src/unbound,target=.,rw <<EOT
   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
 
@@ -95,7 +136,7 @@ RUN --mount=type=bind,from=ldns-src,source=/src/ldns,target=.,rw <<EOT
   file /out/usr/bin/drill
 EOT
 
-FROM alpine:${ALPINE_VERSION}
+FROM alpine:${ALPINE_VERSION}@${ALPINE_DIGEST}
 COPY --from=unbound-build /out /
 COPY --from=ldns-build /out /
 

+ 48 - 1
README.md

@@ -30,10 +30,54 @@ this image — Unbound has root servers built in) pulls in curl, nghttp2, zlib,
 c-ares, brotli and friends. It is dropped, so the runtime image carries none
 of that stack.
 
+## Comparison with other unbound images (10/2026)
+
+Docker Hub query + source analysis of the most relevant alternatives
+(2026-10-23): `mvance/unbound` (22.9M pulls), `klutchell/unbound`
+(12.8M), `sapcc/unbound` (5.8M), `mailcow/unbound` (25.5M),
+`madnuttah/unbound` (distroless, security-focused),
+`alpinelinux/unbound` (official Alpine package image).
+
+| Aspect | unbound-sec | mvance | klutchell | madnuttah |
+|---|---|---|---|---|
+| Unbound version | **1.26.2** | 1.21.1 (2024-10) | 1.26.2 | 1.26.x |
+| Base | Alpine 3.24, digest-pinned | Debian bookworm | Alpine 3.24.2, digest-pinned | distroless (FROM scratch) |
+| Tarball SHA256 + GPG | **yes** | SHA256 only | SHA256 only | SHA256 + GPG |
+| Base image digest pin | **yes** | no | yes | no (own buildenv image) |
+| Non-root, no SUID | yes | yes | yes | yes |
+| EDNS Client Subnet | **yes** | yes | yes | yes |
+| TFO | **yes** | yes | yes | yes |
+| DNSCrypt (libsodium) | no | no | yes | yes |
+| DoH (nghttp2) | no | yes | yes | yes |
+| DNSTAP (protobuf-c) | no | yes | no | yes |
+| cachedb (hiredis) | yes | no | yes | yes |
+| Binary PIE + RELRO-now | **yes** | no | no | yes |
+| Port | 5053 (crazymax-compat) | 53 | 53 | 53 |
+
+**Adopted** (no runtime-dependency cost, all test-covered):
+- SHA256 + GPG verification of both source tarballs (NLnet Labs key G2)
+- digest pinning of base images (reproducible builds)
+- `--enable-pie --enable-relro-now` (explicit binary hardening)
+- `--enable-subnet` (EDNS Client Subnet — multi-WAN/split-horizon capable)
+- `--enable-tfo-server --enable-tfo-client` (TCP Fast Open)
+
+**Deliberately NOT adopted** (surface-area trade-offs against this
+project's minimal-runtime goal):
+- DNSCrypt → would pull libsodium into the runtime (DoT/DoH cover the use case)
+- DoH server mode → would re-add the nghttp2 stack we removed for CVE-2026-58055
+- DNSTAP → would pull libprotobuf-c; observability value low for a LAN resolver
+- `FROM scratch` final stage (klutchell/madnuttah) → manual .so copying,
+  no apk-based updates; our Alpine final stage already has 12 packages
+- port 53 → 5053 kept for one-line crazymax replacement
+
 ## Features
 
 - Unbound **1.26.2** compiled from source on Alpine 3.24 (multi-stage, xx cross-compile)
+- Source integrity: SHA256 + GPG (NLnet Labs release key) for both tarballs;
+  base images pinned by digest
+- Binary hardening: PIE + full RELRO (bind now)
 - ldns 1.9.2 with `drill` (used by the healthcheck)
+- EDNS Client Subnet + TCP Fast Open compiled in (inactive by default)
 - Non-root user `unbound` (uid/gid 1500), **zero effective capabilities**
 - DNSSEC out of the box: root trust anchor from `dnssec-root` package,
   `auto-trust-anchor-file` in writable run-dir (RFC5011 rollover works with
@@ -104,7 +148,10 @@ Covers: build, healthcheck, version pin, DNS resolution, DNSSEC AD-bit
 verification (raw DO-bit queries), non-root uid, CapEff=0, no SUID binaries,
 read-only root fs, no-new-privileges, seccomp, hide-identity (with control
 container proving the identity is revealed when the flag is off), drop-in
-include (accept + reject), attack surface (no curl, no shadow).
+include (accept + reject), attack surface (no curl, no shadow), supply chain
+(GPG signatures + SHA256 in build log, cache-bust per run), PIE (ELF
+e_type of the final binary), compiled feature flags (configure line of
+`unbound -V`).
 
 ## Migrate from crazymax/unbound
 

+ 21 - 6
docs/vanilla-deviations.md

@@ -23,18 +23,32 @@ Vanilla `./configure` with no options vs. our Dockerfile build stage:
 | `--with-libhiredis` | off → cachedb module off | on → `--enable-cachedb` | Redis auxiliary cache available (drop-in compatible with crazymax) |
 | `--with-libexpat` | off (fails build if missing in this version) | on | required by `unbound-anchor` (RFC5011/XML); expat 2.9.0, no open CVEs |
 | `--enable-event-api` | off | on | experimental pluggable event API header installed (parity) |
+| `--enable-subnet` | off | on | EDNS Client Subnet support (no extra runtime dependency; adopted from klutchell/mvance/madnuttah images) |
+| `--enable-tfo-server` | off | on | TCP Fast Open for DNS over TCP (no extra dependency) |
+| `--enable-tfo-client` | off | on | TCP Fast Open for outgoing queries (no extra dependency) |
+| `--enable-pie` | off (autodetected) | on | Position-Independent Executable, explicit (adopted from madnuttah) |
+| `--enable-relro-now` | partial RELRO | full RELRO (bind now) | explicit full relocation binding at load time (adopted from madnuttah) |
 | `--disable-shared` | shared libs | static | no extra runtime .so dependencies |
 | `--disable-rpath` | on | off | deterministic linking |
 | `--disable-flto` | on | off | faster build, negligible runtime difference |
 
 Not compiled (vanilla default = off, kept off):
-DNS-over-QUIC (`--with-quic`, would pull libuv/libnghttp2), DNSCrypt,
-DNSTAP, GeoIP, Python control scripts, libcurl (unbound-anchor uses raw
-OpenSSL, no curl needed).
+DNS-over-QUIC (`--with-quic`, would pull libuv/libnghttp2), DNSCrypt
+(would pull libsodium), DNSTAP (would pull libprotobuf-c), GeoIP, Python
+control scripts, libcurl (unbound-anchor uses raw OpenSSL, no curl needed),
+DoH server mode (`--with-libnghttp2`, would re-add the nghttp2 stack that
+was deliberately removed).
+
+Supply chain (adopted from klutchell + madnuttah images):
+- source tarballs are verified by **SHA256** (pinned in the Dockerfile)
+  **and GPG signature** (NLnet Labs releases key G2,
+  `nlnetlabs.nl/downloads/keys/releases-g2.asc`) before extraction
+- base images are **pinned by digest** (`alpine:3.24@sha256:71e9b7ba…`,
+  `tonistiigi/xx:1.9.0@sha256:c64defb9…`) → reproducible builds
 
 Result (verified via `unbound -V` in the built image):
-`Linked modules: dns64 cachedb respip validator iterator`,
-`libevent 2.1.13-stable`, `OpenSSL 3.5.x`.
+`Linked modules: dns64 cachedb subnetcache respip validator iterator`,
+`TCP Fastopen feature available`, `libevent 2.1.13-stable`, `OpenSSL 3.5.9`.
 
 Added on top of Unbound (not part of it):
 - ldns 1.9.2 with `drill` — used by the image healthcheck
@@ -88,6 +102,7 @@ Unchanged from vanilla (explicitly set for clarity): `verbosity: 1`,
 
 - Query behavior stays vanilla: no ratelimits, no prefetch tuning, no
   `local-zone`/`local-data`, no EDNS changes — a drop-in replacement, not a
-  re-tuned resolver.
+  re-tuned resolver. (ECS/TFO are compiled in but inactive by default;
+  opt in via config when needed.)
 - `access-control` stays as wide as crazy-max's (RFC1918), to keep
   migration a one-line change.

+ 40 - 1
test/run-tests.sh

@@ -32,6 +32,7 @@ cleanup() {
   docker rm -f "$C1" "$C2" "$C3" "$C4" >/dev/null 2>&1
   docker network rm "$NET" >/dev/null 2>&1
   rm -rf "$(pwd)/test/fixture-identity" 2>/dev/null
+  rm -f "$(pwd)/test/build.log" 2>/dev/null
 }
 trap cleanup EXIT
 
@@ -39,10 +40,15 @@ say "== 0. cleanup old artifacts =="
 cleanup
 
 say "== 1. build image =="
-if docker build -t "$IMAGE" . >/dev/null 2>&1; then
+BUILDLOG="$(pwd)/test/build.log"
+# CACHEBUST forces the src stages (SHA256 + GPG verification) to re-run on
+# every test run so the build log always contains fresh evidence; the slow
+# compile stages stay cached.
+if docker build --build-arg CACHEBUST="$(date +%s)" -t "$IMAGE" . >"$BUILDLOG" 2>&1; then
   ok "docker build"
 else
   bad "docker build"
+  tail -15 "$BUILDLOG"
   say "ABORT: build failed"; exit 1
 fi
 
@@ -213,6 +219,39 @@ else
   ok "shadow package removed"
 fi
 
+say "== 15. supply chain: GPG + SHA256 of source tarballs =="
+sigs="$(grep -c "Good signature" "$BUILDLOG" 2>/dev/null)"
+if [ "$sigs" -ge 2 ]; then
+  ok "GPG: Good signature x$sigs (unbound + ldns tarballs)"
+else
+  bad "GPG: Good signature (found: $sigs, need >= 2)"
+fi
+if grep -E "unbound\.tar\.gz: OK|ldns\.tar\.gz: OK" "$BUILDLOG" >/dev/null 2>&1; then
+  ok "SHA256: tarball checksums OK"
+else
+  bad "SHA256: tarball checksums OK"
+fi
+
+say "== 16. binary hardening: PIE =="
+# ELF e_type: 3 = ET_DYN (PIE/shared). Read from the final binary itself,
+# so this works even on cached builds.
+etype="$(docker exec "$C1" sh -c 'od -An -N32 -td2 /usr/sbin/unbound' 2>/dev/null | awk 'NR==2{print $1}')"
+if [ "$etype" = "3" ]; then
+  ok "unbound binary is PIE (ELF e_type=ET_DYN)"
+else
+  bad "unbound binary is PIE (ELF e_type=$etype, expected 3)"
+fi
+
+say "== 17. features compiled in (configure line) =="
+confline="$(docker exec "$C1" unbound -V 2>/dev/null | grep -i 'configure line')"
+for flag in --enable-subnet --enable-tfo-server --enable-tfo-client --enable-pie --enable-relro-now; do
+  if printf '%s' "$confline" | grep -q -- "$flag"; then
+    ok "compiled with $flag"
+  else
+    bad "compiled with $flag"
+  fi
+done
+
 say ""
 say "=================================================="
 say "RESULT: $PASS passed, $FAIL failed"