Selaa lähdekoodia

unbound-sec 0.1.0: hardened Unbound 1.26.2 image, drop-in replacement for crazymax/unbound

- Unbound 1.26.2 from source (security release): fixes CVE-2026-96405/109125/50106/35501/97206
- no curl-stack (dns-root-hints dropped): fixes CVE-2026-58055 (nghttp2), CVE-2026-85091 (zlib)
- Alpine 3.24 expat 2.9.0: fixes CVE-2026-77214/93990/102633
- no SUID binaries (shadow removed from runtime)
- hide-identity/hide-version, non-root uid 1500, zero caps
- hardened compose template: read_only + tmpfs + no-new-privileges + cap_drop ALL
- test suite running fully inside Docker (14 test groups)
Bob 1 kuukausi sitten
commit
c78f6f6c30
11 muutettua tiedostoa jossa 673 lisäystä ja 0 poistoa
  1. 5 0
      .dockerignore
  2. 12 0
      .gitignore
  3. 34 0
      CHANGELOG.md
  4. 137 0
      Dockerfile
  5. 129 0
      README.md
  6. 29 0
      build.sh
  7. 49 0
      config/unbound.conf
  8. 33 0
      docker-compose.yml
  9. 12 0
      entrypoint.sh
  10. 39 0
      test/dns-check.py
  11. 194 0
      test/run-tests.sh

+ 5 - 0
.dockerignore

@@ -0,0 +1,5 @@
+test
+.git
+README.md
+CHANGELOG.md
+docker-compose.yml

+ 12 - 0
.gitignore

@@ -0,0 +1,12 @@
+# build artifacts
+*.img
+*.tar
+
+# test fixtures (generated at test run)
+test/fixture-config-ok/
+test/fixture-config-bad/
+
+# editor/OS
+.vscode/
+.idea/
+.DS_Store

+ 34 - 0
CHANGELOG.md

@@ -0,0 +1,34 @@
+# Changelog
+
+All notable changes to this project are documented here.
+
+## [0.1.0] - 2026-10-23
+
+### Added
+- Initial project: security-hardened Unbound Docker image as drop-in
+  replacement for `crazymax/unbound`.
+- Unbound 1.26.2 from source (security release 2026-10-21) on Alpine 3.24,
+  multi-stage xx cross-compile build, multi-arch capable.
+- ldns 1.9.2 with drill for the healthcheck.
+- Non-root user (uid/gid 1500), zero effective capabilities.
+- Base config with DNSSEC root anchor, DoT cert bundle, cachedb module,
+  `/config/*.conf` drop-in include, `hide-identity`/`hide-version`.
+- Hardened docker compose template: read-only root fs, tmpfs,
+  no-new-privileges, cap_drop ALL.
+- Test suite (runs fully inside Docker): build, healthcheck, version, DNS,
+  DNSSEC AD-bit, uid, CapEff, SUID scan, read-only fs, NoNewPrivs, seccomp,
+  hide-identity, drop-in include accept/reject, attack surface.
+- `build.sh` with cosign keyless signing.
+
+### Security fixes (vs. crazymax/unbound:latest audit, 2026-10-22/23)
+- CVE-2026-96405 (Medium, DoS): fixed by Unbound 1.26.2
+- CVE-2026-109125 (Medium, cache poisoning side channel): fixed by 1.26.2
+- CVE-2026-50106 (Medium, DNSSEC island bypass): fixed by 1.26.2
+- CVE-2026-35501 (Low, NSEC island bypass): fixed by 1.26.2
+- CVE-2026-97206 (High, DoQ UAF): fixed by 1.26.2; not reachable in this
+  image anyway (QUIC not compiled)
+- CVE-2026-77214 / CVE-2026-93990 / CVE-2026-102633 (expat): fixed by Alpine
+  3.24 expat 2.9.0
+- CVE-2026-58055 (nghttp2) + CVE-2026-85091 (zlib): library stack removed
+  (dns-root-hints dropped; Unbound has root servers built in)
+- SUID-root binaries removed (shadow package dropped from runtime)

+ 137 - 0
Dockerfile

@@ -0,0 +1,137 @@
+# 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 [""]

+ 129 - 0
README.md

@@ -0,0 +1,129 @@
+# unbound-sec
+
+Security-hardened Docker image for [Unbound](https://unbound.net/) (validating,
+recursive, caching DNS resolver). Direct drop-in replacement for
+`crazymax/unbound` — same port, same `/config` drop-in mechanism, same
+healthcheck — with the security findings from the 10/2026 audit of
+`crazymax/unbound:latest` fixed.
+
+## Why this project
+
+Audit results for `crazymax/unbound:latest` (Unbound 1.26.1, Alpine 3.24.1,
+built 2026-09-17):
+
+| Finding | Severity | Fix in this project |
+|---|---|---|
+| Unbound 1.26.1 behind security release 1.26.2 (CVE-2026-96405 Medium DoS, CVE-2026-109125 Medium, CVE-2026-50106 Medium, CVE-2026-35501 Low, CVE-2026-97206 High) | Med/High | Build Unbound **1.26.2** (CVE-2026-97206 not reachable anyway: DoQ not compiled) |
+| expat 2.8.4: CVE-2026-77214, CVE-2026-93990 (High), CVE-2026-102633 (Medium) | High | Current Alpine 3.24 **expat 2.9.0** |
+| nghttp2 1.69.0: CVE-2026-58055 (Medium) | Medium | **curl-stack removed** (see below) |
+| zlib 1.3.2: CVE-2026-85091 (Medium) | Medium | zlib gone with curl-stack |
+| No cosign signatures on image | Info | `build.sh` signs with cosign (keyless, GitHub OIDC) |
+| SUID-root binaries (shadow package: passwd, chsh, chfn, chage, expiry, gpasswd) | Low | `shadow` removed after user creation — **no SUID binaries** |
+| NoNewPrivs not set, writable root fs | Low | compose template: `no-new-privileges`, `read_only` + tmpfs |
+| Identity/version leak via CHAOS queries | Info | `hide-identity`, `hide-version` |
+
+Key attack-surface reduction: the `dns-root-hints` package (used by no one in
+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.
+
+## Features
+
+- Unbound **1.26.2** compiled from source on Alpine 3.24 (multi-stage, xx cross-compile)
+- ldns 1.9.2 with `drill` (used by the healthcheck)
+- 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
+  read-only root fs)
+- DoT capable (`tls-cert-bundle` set)
+- cachedb module compiled in (optional Redis auxiliary cache, same as crazymax)
+- Healthcheck: `drill -p 5053 unbound.net @127.0.0.1`
+- Port **5053/tcp+udp**, volume **/config** (drop-in `*.conf` include) —
+  identical to `crazymax/unbound`
+
+## Build
+
+```sh
+./build.sh            # build + cosign keyless sign (GHCR/Hub) — see below
+# or plain:
+docker build -t unbound-sec:latest .
+```
+
+## Run (hardened template)
+
+```sh
+docker compose up -d
+```
+
+The compose template enables: `read_only` root fs, tmpfs for `/tmp` and
+`/run/unbound`, `no-new-privileges`, `cap_drop: ALL`.
+
+Minimal (no hardening flags, still non-root):
+
+```sh
+docker run -d -p 5053:5053/udp -p 5053:5053/tcp -v ./config:/config:ro unbound-sec:latest
+```
+
+## Configuration
+
+Drop any `*.conf` file into `/config` — it is included by the base config
+(lexicographic order). Examples:
+
+```
+# /config/forward-records.conf — DoT forwarding
+forward-zone:
+  name: "."
+  forward-tls-upstream: yes
+  forward-addr: 1.1.1.1@853
+  forward-addr: 1.0.0.1@853
+
+# /config/cachedb.conf — Redis auxiliary cache
+cachedb:
+  backend: "redis"
+  secret-seed: "default"
+  redis-server-host: redis
+  redis-server-port: 6379
+```
+
+Config changes require a container restart. Full reference:
+[unbound.conf(5)](https://nlnetlabs.nl/documentation/unbound/unbound.conf/).
+
+## Tests
+
+The whole test suite runs inside Docker (runner = `docker:cli` container with
+the socket mounted; all assertions target containers):
+
+```sh
+./test/run-tests.sh
+```
+
+Covers: build, healthcheck, version pin, DNS resolution, DNSSEC AD-bit
+verification, non-root uid, CapEff=0, no SUID binaries, read-only root fs,
+no-new-privileges, seccomp, hide-identity, drop-in include (accept + reject),
+attack surface (no curl, no shadow).
+
+## Migrate from crazymax/unbound
+
+```diff
+- image: crazymax/unbound:latest
++ image: unbound-sec:latest
+```
+
+Port, volume, healthcheck and drop-in config are identical. Add the
+hardening options from `docker-compose.yml` (read_only, tmpfs,
+no-new-privileges, cap_drop).
+
+## Signing
+
+`build.sh` signs the image with cosign in keyless mode (GitHub OIDC token).
+Verify:
+
+```sh
+cosign verify --certificate-identity-regexp "https://token.actions.githubusercontent.com" \
+  --certificate-oidc-issuer-regexp "https://token.actions.githubusercontent.com" \
+  --certificate-github-workflow-repository <owner>/unbound-sec <image>
+```
+
+## License
+
+MIT

+ 29 - 0
build.sh

@@ -0,0 +1,29 @@
+#!/bin/sh
+# Build unbound-sec and (optionally) sign with cosign in keyless mode.
+#
+# Usage:
+#   ./build.sh                        # build only
+#   COSIGN_SIGN=1 ./build.sh          # build + cosign sign (needs keyless
+#                                     # capability: GHCR via GITHUB_TOKEN,
+#                                     # or local keyless via OIDC provider)
+set -eu
+
+IMAGE="${IMAGE:-unbound-sec:latest}"
+VERSION="${VERSION:-$(git describe --tags --always 2>/dev/null || echo dev)}"
+
+echo "==> building $IMAGE (version=$VERSION)"
+docker build \
+  --build-arg "COMMIT=${GITHUB_SHA:-$(git rev-parse HEAD 2>/dev/null || echo none)}" \
+  --label "org.opencontainers.image.version=$VERSION" \
+  --label "org.opencontainers.image.source=https://github.com/ric/unbound-sec" \
+  -t "$IMAGE" .
+
+if [ "${COSIGN_SIGN:-0}" = "1" ]; then
+  echo "==> cosign keyless sign"
+  cosign sign --yes \
+    --certificate-identity-regexp "https://token.actions.githubusercontent.com" \
+    --certificate-oidc-issuer-regexp "https://token.actions.githubusercontent.com" \
+    "$IMAGE"
+fi
+
+echo "==> done: $IMAGE"

+ 49 - 0
config/unbound.conf

@@ -0,0 +1,49 @@
+# unbound-sec base configuration
+# Drop-in overrides: any *.conf file in /config is included (lexicographic order).
+
+server:
+  verbosity: 1
+  module-config: "validator cachedb iterator"
+
+  statistics-interval: 600
+  statistics-cumulative: yes
+
+  # 0 avoids the cachedb warning about serve-expired for external cache entries
+  serve-expired-reply-ttl: 0
+
+  interface: 0.0.0.0@5053
+  do-ip4: yes
+  do-ip6: no
+  do-udp: yes
+  do-tcp: yes
+  so-sndbuf: 0
+
+  do-daemonize: no
+
+  # LAN + loopback by default (drop-in compatible with crazymax/unbound).
+  # Tighten via drop-in in /config for larger exposures, e.g.:
+  #   access-control: 10.0.0.0/8 refuse
+  access-control: 10.0.0.0/8 allow
+  access-control: 127.0.0.0/8 allow
+  access-control: 172.16.0.0/12 allow
+  access-control: 192.168.0.0/16 allow
+
+  # Never return these ranges in responses
+  private-address: 10.0.0.0/8
+  private-address: 169.254.0.0/16
+  private-address: 172.16.0.0/12
+  private-address: 192.168.0.0/16
+
+  # Do not leak software identity/version via CHAOS queries
+  hide-identity: yes
+  hide-version: yes
+
+  directory: "/etc/unbound"
+  logfile: ""
+  pidfile: "/run/unbound/unbound.pid"
+
+  identity: "unbound-sec"
+  auto-trust-anchor-file: "/run/unbound/root.key"
+  tls-cert-bundle: /etc/ssl/certs/ca-certificates.crt
+
+  include: "/config/*.conf"

+ 33 - 0
docker-compose.yml

@@ -0,0 +1,33 @@
+# Hardened run template for unbound-sec
+#
+# Security options enabled here:
+#   - read_only root filesystem (writable paths via tmpfs)
+#   - no-new-privileges (process can't gain privileges via setuid/setgid)
+#   - cap_drop ALL (non-root user: no capabilities anyway)
+#
+# Usage: docker compose up -d
+
+name: unbound-sec
+
+services:
+  unbound:
+    image: unbound-sec:latest
+    container_name: unbound
+    ports:
+      - target: 5053
+        published: 5053
+        protocol: tcp
+      - target: 5053
+        published: 5053
+        protocol: udp
+    volumes:
+      - "./config:/config:ro"
+    read_only: true
+    tmpfs:
+      - /tmp
+      - /run/unbound
+    security_opt:
+      - no-new-privileges:true
+    cap_drop:
+      - ALL
+    restart: always

+ 12 - 0
entrypoint.sh

@@ -0,0 +1,12 @@
+#!/bin/sh
+set -e
+
+# Copy the static root trust anchor into the writable run-dir.
+# unbound updates auto-trust-anchor-file in place (RFC5011 rollover), so it
+# must live on a writable filesystem (tmpfs when running with read_only).
+cp -f /etc/unbound/root.key /run/unbound/root.key
+
+# Fail fast on broken drop-in configs from /config before starting.
+unbound-checkconf /etc/unbound/unbound.conf
+
+exec unbound -d -c /etc/unbound/unbound.conf

+ 39 - 0
test/dns-check.py

@@ -0,0 +1,39 @@
+# Python container probe: raw DNS query against the unbound container.
+# Checks AD bit (DNSSEC validated) with and without DO bit, plus basic resolution.
+import socket
+import struct
+import sys
+
+server = sys.argv[1] if len(sys.argv) > 1 else "unbound"
+port = int(sys.argv[2]) if len(sys.argv) > 2 else 5053
+
+
+def query(name, do_bit):
+    flags = 0x0100 | (0x0020 if do_bit else 0)  # RD (+ DO)
+    header = struct.pack(">HHHHHH", 0x1234, flags, 1, 0, 0, 0)
+    qname = b"".join(bytes([len(p)]) + p.encode() for p in name.split(".")) + b"\x00"
+    q = header + qname + struct.pack(">HH", 1, 1)
+    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+    s.settimeout(10)
+    s.sendto(q, (server, port))
+    data, _ = s.recvfrom(4096)
+    s.close()
+    rf = struct.unpack(">H", data[2:4])[0]
+    an = struct.unpack(">H", data[6:8])[0]
+    return an, (rf >> 5) & 1, rf & 0xF
+
+
+ok = True
+for name in ("example.com", "unbound.net"):
+    an, ad, rc = query(name, do_bit=1)
+    good = an > 0 and ad == 1 and rc == 0
+    ok = ok and good
+    print(f"{name}: answers={an} AD={ad} rcode={rc} -> {'PASS' if good else 'FAIL'}")
+
+# plain query must also resolve
+an, ad, rc = query("example.com", do_bit=0)
+good = an > 0 and rc == 0
+ok = ok and good
+print(f"example.com (no DO): answers={an} rcode={rc} -> {'PASS' if good else 'FAIL'}")
+
+sys.exit(0 if ok else 1)

+ 194 - 0
test/run-tests.sh

@@ -0,0 +1,194 @@
+#!/bin/sh
+# unbound-sec test suite.
+#
+# Runs fully inside Docker: this script is executed in a docker:cli container
+# with the Docker socket mounted; every assertion targets containers.
+#
+# Usage (from repo root):
+#   docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \
+#     -v "$(pwd):/work" -w /work docker:cli sh test/run-tests.sh
+
+set -u
+
+IMAGE="unbound-sec:test"
+C1="ubsec-t1"          # main hardened container
+C2="ubsec-t2"          # valid drop-in container
+C3="ubsec-t3"          # broken drop-in container
+NET="ubsec-testnet"
+CFG1="$(pwd)/test/fixture-config-ok"
+CFG2="$(pwd)/test/fixture-config-bad"
+PASS=0
+FAIL=0
+
+say()  { printf '%s\n' "$*"; }
+ok()   { PASS=$((PASS+1)); say "  [PASS] $1"; }
+bad()  { FAIL=$((FAIL+1)); say "  [FAIL] $1"; }
+
+cleanup() {
+  docker rm -f "$C1" "$C2" "$C3" >/dev/null 2>&1
+  docker network rm "$NET" >/dev/null 2>&1
+}
+trap cleanup EXIT
+
+say "== 0. cleanup old artifacts =="
+cleanup
+
+say "== 1. build image =="
+if docker build -t "$IMAGE" . >/dev/null 2>&1; then
+  ok "docker build"
+else
+  bad "docker build"
+  say "ABORT: build failed"; exit 1
+fi
+
+say "== 2. start hardened container =="
+docker network create "$NET" >/dev/null
+docker run -d --name "$C1" --network "$NET" \
+  -p 5053:5053/udp -p 5053:5053/tcp \
+  --read-only \
+  --tmpfs /tmp --tmpfs /run/unbound \
+  --security-opt no-new-privileges:true \
+  --cap-drop ALL \
+  "$IMAGE" >/dev/null
+sleep 3
+
+if [ "$(docker inspect -f '{{.State.Running}}' "$C1" 2>/dev/null)" = "true" ]; then
+  ok "container running"
+else
+  bad "container running"; docker logs "$C1" 2>&1 | tail -5
+fi
+
+say "== 3. healthcheck =="
+healthy="no"
+i=0
+while [ $i -lt 12 ]; do
+  h="$(docker inspect -f '{{.State.Health.Status}}' "$C1" 2>/dev/null)"
+  [ "$h" = "healthy" ] && healthy="yes" && break
+  sleep 6
+  i=$((i+1))
+done
+if [ "$healthy" = "yes" ]; then
+  ok "healthcheck healthy"
+else
+  bad "healthcheck healthy (status=$h)"
+fi
+
+say "== 4. version =="
+v="$(docker exec "$C1" unbound -V 2>/dev/null | head -1)"
+case "$v" in
+  *1.26.2*) ok "unbound version 1.26.2 ($v)";;
+  *) bad "unbound version 1.26.2 (got: $v)";;
+esac
+
+say "== 5. DNS resolution =="
+if docker exec "$C1" drill -p 5053 example.com @127.0.0.1 2>/dev/null | grep -q "example.com"; then
+  ok "drill resolves example.com"
+else
+  bad "drill resolves example.com"
+fi
+
+say "== 6. DNSSEC (AD bit, DO query) =="
+if docker run --rm --network "$NET" -v "$(pwd)/test/dns-check.py:/probe.py:ro" python:3.20-alpine python /probe.py unbound 5053 | grep -q "FAIL\|Traceback"; then
+  bad "DNSSEC AD-bit probe"
+else
+  ok "DNSSEC AD-bit probe"
+fi
+
+say "== 7. non-root user =="
+uid="$(docker exec "$C1" sh -c 'id -u' 2>/dev/null)"
+if [ "$uid" = "1500" ]; then
+  ok "runs as uid 1500"
+else
+  bad "runs as uid 1500 (got: $uid)"
+fi
+
+say "== 8. capabilities =="
+capeff="$(docker exec "$C1" sh -c 'grep ^CapEff /proc/self/status' 2>/dev/null | awk '{print $2}')"
+if [ "$capeff" = "0000000000000000" ]; then
+  ok "CapEff = 0"
+else
+  bad "CapEff = 0 (got: $capeff)"
+fi
+
+say "== 9. no SUID binaries =="
+suid="$(docker exec "$C1" sh -c 'find / -perm -4000 -type f 2>/dev/null' 2>/dev/null)"
+if [ -z "$suid" ]; then
+  ok "no SUID-root binaries"
+else
+  bad "no SUID-root binaries (found: $suid)"
+fi
+
+say "== 10. read-only root filesystem =="
+if docker exec "$C1" sh -c 'touch /usr/writetest 2>/dev/null'; then
+  bad "root fs is read-only (write to /usr succeeded)"
+else
+  ok "root fs is read-only"
+fi
+if docker exec "$C1" sh -c 'touch /run/unbound/writetest && rm /run/unbound/writetest' 2>/dev/null; then
+  ok "/run/unbound writable (tmpfs)"
+else
+  bad "/run/unbound writable (tmpfs)"
+fi
+
+say "== 11. no-new-privileges + seccomp =="
+nnp="$(docker exec "$C1" sh -c 'grep ^NoNewPrivs /proc/self/status' 2>/dev/null | awk '{print $2}')"
+if [ "$nnp" = "1" ]; then
+  ok "NoNewPrivs = 1"
+else
+  bad "NoNewPrivs = 1 (got: $nnp)"
+fi
+sc="$(docker exec "$C1" sh -c 'grep ^Seccomp: /proc/self/status' 2>/dev/null | awk '{print $2}')"
+if [ "$sc" = "2" ]; then
+  ok "seccomp filter active"
+else
+  bad "seccomp filter active (got: $sc)"
+fi
+
+say "== 12. hide-identity / hide-version =="
+idout="$(docker exec "$C1" drill -p 5053 id.server. CHAOS TXT @127.0.0.1 2>/dev/null | grep -oE '"[^"]*"' | tr -d '"')"
+case "$idout" in
+  *1.26*) bad "identity leaks version ($idout)";;
+  "")     bad "identity query returned nothing";;
+  *)      ok "identity does not leak version ($idout)";;
+esac
+
+say "== 13. drop-in config include =="
+mkdir -p "$CFG1" "$CFG2"
+printf 'server:\n  verbosity: 2\n' > "$CFG1/99-test.conf"
+printf 'server:\n  this-is-not-a-valid-option: 1\n' > "$CFG2/99-broken.conf"
+
+docker run -d --name "$C2" --network "$NET" -v "$CFG1:/config:ro" "$IMAGE" >/dev/null
+sleep 3
+if [ "$(docker inspect -f '{{.State.Running}}' "$C2" 2>/dev/null)" = "true" ]; then
+  ok "valid drop-in config accepted (include works)"
+else
+  bad "valid drop-in config accepted"
+fi
+
+docker run -d --name "$C3" --network "$NET" -v "$CFG2:/config:ro" "$IMAGE" >/dev/null
+sleep 3
+if [ "$(docker inspect -f '{{.State.Running}}' "$C3" 2>/dev/null)" = "false" ]; then
+  ok "broken drop-in config rejects start (checkconf)"
+else
+  bad "broken drop-in config rejects start"
+fi
+
+say "== 14. package attack surface =="
+has_curl="$(docker exec "$C1" sh -c 'test -x /usr/bin/curl && echo yes' 2>/dev/null)"
+if [ "$has_curl" = "yes" ]; then
+  bad "curl not in runtime image"
+else
+  ok "no curl in runtime image"
+fi
+has_shadow="$(docker exec "$C1" sh -c 'test -x /usr/bin/chsh && echo yes' 2>/dev/null)"
+if [ "$has_shadow" = "yes" ]; then
+  bad "shadow package not removed"
+else
+  ok "shadow package removed"
+fi
+
+say ""
+say "=================================================="
+say "RESULT: $PASS passed, $FAIL failed"
+say "=================================================="
+[ $FAIL -eq 0 ]