|
|
@@ -17,7 +17,14 @@ C2="ubsec-t2" # valid drop-in container
|
|
|
C3="ubsec-t3" # broken drop-in container
|
|
|
C4="ubsec-t4" # identity control container
|
|
|
C5="ubsec-t5" # anchor persistence container
|
|
|
+C6="ubsec-t6" # DNSSEC negative-test unbound (forward-zone)
|
|
|
+RESP="ubsec-t6-resp" # static DNS responder for the negative test
|
|
|
NET="ubsec-testnet"
|
|
|
+# The compose template is tested under a DEDICATED project name so the test
|
|
|
+# never touches a production deployment of the same template on this daemon
|
|
|
+# (its own container, network, and volume unbound-sec-test_unbound_anchor).
|
|
|
+PROJ_TEST="unbound-sec-test"
|
|
|
+C6_CONT="${PROJ_TEST}-unbound-1" # compose auto-name for the test project
|
|
|
# Fixtures must use HOST paths (bind mounts are resolved by the daemon).
|
|
|
# run.sh sets REPO_PATH to the host repo path and pre-creates the fixtures.
|
|
|
CFG1="${REPO_PATH:-$(pwd)}/test/fixture-config-ok"
|
|
|
@@ -25,20 +32,36 @@ CFG2="${REPO_PATH:-$(pwd)}/test/fixture-config-bad"
|
|
|
ANCHOR_DIR="${REPO_PATH:-$(pwd)}/test/fixture-anchor"
|
|
|
PASS=0
|
|
|
FAIL=0
|
|
|
+NOTVERIFIED=0 # checks that could not be run (infrastructure, e.g. timeout)
|
|
|
|
|
|
say() { printf '%s\n' "$*"; }
|
|
|
ok() { PASS=$((PASS+1)); say " [PASS] $1"; }
|
|
|
bad() { FAIL=$((FAIL+1)); say " [FAIL] $1"; }
|
|
|
+# A security probe that could not be executed (timeout / network) — NOT a
|
|
|
+# content finding, but must be visible in the result.
|
|
|
+nv() { NOTVERIFIED=$((NOTVERIFIED+1)); say " [NOT VERIFIED] $1"; }
|
|
|
# Resolve a container's IP on $NET so probes can address it directly
|
|
|
# (avoids depending on Docker's embedded DNS inside the probe container).
|
|
|
ip_of() { docker inspect -f '{{(index .NetworkSettings.Networks "'"$NET"').IPAddress}}' "$1" 2>/dev/null; }
|
|
|
|
|
|
+# Test-only compose invocation (dedicated project + test-image override;
|
|
|
+# see test/compose.test.yml). A function (not an array) for POSIX sh.
|
|
|
+compose_test() {
|
|
|
+ (cd "${REPO_PATH:-$(pwd)}" && docker compose -p "$PROJ_TEST" \
|
|
|
+ -f docker-compose.yml -f test/compose.test.yml "$@")
|
|
|
+}
|
|
|
+
|
|
|
cleanup() {
|
|
|
- docker rm -f "$C1" "$C2" "$C3" "$C4" "$C5" >/dev/null 2>&1
|
|
|
- docker rm -f unbound >/dev/null 2>&1
|
|
|
- (cd "${REPO_PATH:-$(pwd)}" && docker compose -f docker-compose.yml down --remove-orphans --volumes >/dev/null 2>&1)
|
|
|
+ # Remove ONLY resources this test run created. The fixed container name
|
|
|
+ # "unbound" is gone from the template, so we no longer rm a name that a
|
|
|
+ # production deployment might use.
|
|
|
+ docker rm -f "$C1" "$C2" "$C3" "$C4" "$C5" "$C6" "$RESP" >/dev/null 2>&1
|
|
|
+ compose_test down --remove-orphans --volumes >/dev/null 2>&1
|
|
|
docker network rm "$NET" >/dev/null 2>&1
|
|
|
+ docker network rm "ubsec-negnet" >/dev/null 2>&1
|
|
|
rm -rf "$(pwd)/test/fixture-identity" 2>/dev/null
|
|
|
+ rm -rf "$(pwd)/test/fixture-broken-fwd" 2>/dev/null
|
|
|
+ rm -f "$(pwd)/test/.broken-zone.bin" 2>/dev/null
|
|
|
rm -rf "$ANCHOR_DIR" 2>/dev/null
|
|
|
rm -f "$(pwd)/test/build.log" 2>/dev/null
|
|
|
}
|
|
|
@@ -54,10 +77,9 @@ BUILDLOG="$(pwd)/test/build.log"
|
|
|
# compile stages stay cached.
|
|
|
if docker build --build-arg CACHEBUST="$(date +%s)" -t "$IMAGE" . >"$BUILDLOG" 2>&1; then
|
|
|
ok "docker build"
|
|
|
- # The compose template references unbound-sec:latest (the production
|
|
|
- # tag from build.sh); tag the test image accordingly so test 19 can use
|
|
|
- # it without pulling from a registry.
|
|
|
- docker tag "$IMAGE" unbound-sec:latest >/dev/null 2>&1
|
|
|
+ # NOTE: we deliberately do NOT tag unbound-sec:latest here. The compose
|
|
|
+ # template is exercised through test/compose.test.yml, which pins the test
|
|
|
+ # image — so the production tag is left untouched.
|
|
|
else
|
|
|
bad "docker build"
|
|
|
tail -15 "$BUILDLOG"
|
|
|
@@ -126,17 +148,18 @@ else
|
|
|
printf '%s\n' "$ad_out" | sed 's/^/ /'
|
|
|
fi
|
|
|
# Secondary check: raw EDNS-0 DO probe from an external container (also
|
|
|
-# verifies the no-DO -> no-AD behavior). Best-effort: the WSL overlay
|
|
|
-# network can hiccup, so a timeout here is not treated as a validation
|
|
|
-# failure (the loopback check above already proved validation).
|
|
|
+# verifies the no-DO -> no-AD behavior). The probe distinguishes content
|
|
|
+# deviations (exit 1 -> FAIL) from infrastructure timeouts (exit 2 -> NOT
|
|
|
+# VERIFIED). The loopback check above is the deterministic primary proof.
|
|
|
probe_out="$(docker run --rm --network "$NET" -v "$(pwd)/test/dns-check.py:/probe.py:ro" python:alpine python /probe.py "$(ip_of "$C1")" 5053 2>&1)"
|
|
|
probe_rc=$?
|
|
|
-if [ $probe_rc -ne 0 ] || printf '%s' "$probe_out" | grep -q "FAIL"; then
|
|
|
- say " [warn] external EDNS-DO probe flaky (loopback check passed):"
|
|
|
- printf '%s\n' "$probe_out" | sed 's/^/ /'
|
|
|
-else
|
|
|
- ok "external EDNS-DO probe (AD=1 with DO, AD=0 without)"
|
|
|
-fi
|
|
|
+case $probe_rc in
|
|
|
+ 0) ok "external EDNS-DO probe (AD=1 with DO, AD=0 without)";;
|
|
|
+ 1) bad "external EDNS-DO probe: CONTENT deviation"
|
|
|
+ printf '%s\n' "$probe_out" | sed 's/^/ /';;
|
|
|
+ *) nv "external EDNS-DO probe (timeout; loopback check is the proof)"
|
|
|
+ printf '%s\n' "$probe_out" | sed 's/^/ /';;
|
|
|
+esac
|
|
|
|
|
|
say "== 7. non-root user =="
|
|
|
uid="$(docker exec "$C1" sh -c 'id -u' 2>/dev/null)"
|
|
|
@@ -189,19 +212,20 @@ else
|
|
|
fi
|
|
|
|
|
|
say "== 12. hide-identity / hide-version (CHAOS) =="
|
|
|
-# CHAOS id.server/version.server probes. The only reliable CHAOS query tool
|
|
|
-# here is the Python probe (drill/unbound-host in this image can't set the
|
|
|
-# CHAOS class). It runs from a side container over the Docker overlay
|
|
|
-# network, which can hiccup on WSL — so a timeout is reported as a warning,
|
|
|
-# not a failure (the config value is asserted separately below).
|
|
|
+# CHAOS id.server/version.server probes. The Python probe distinguishes
|
|
|
+# content deviations (exit 1 -> FAIL, e.g. an identity string leaked) from
|
|
|
+# infrastructure timeouts (exit 2 -> NOT VERIFIED). A leaked identity is a
|
|
|
+# real finding and MUST fail the run; a network hiccup is visible but not a
|
|
|
+# failure. The config value is asserted separately below (deterministic).
|
|
|
id_out="$(docker run --rm --network "$NET" -v "$(pwd)/test/chaos-check.py:/probe.py:ro" python:alpine python /probe.py "$(ip_of "$C1")" 5053 id.server. empty 2>&1)"
|
|
|
id_rc=$?
|
|
|
-if [ $id_rc -ne 0 ] || printf '%s' "$id_out" | grep -q "FAIL"; then
|
|
|
- say " [warn] hide-identity CHAOS probe flaky/failed (WSL overlay):"
|
|
|
- printf '%s\n' "$id_out" | sed 's/^/ /'
|
|
|
-else
|
|
|
- ok "hide-identity: id.server. answer is empty"
|
|
|
-fi
|
|
|
+case $id_rc in
|
|
|
+ 0) ok "hide-identity: id.server. answer is empty";;
|
|
|
+ 1) bad "hide-identity: id.server. answer is empty (CONTENT deviation)"
|
|
|
+ printf '%s\n' "$id_out" | sed 's/^/ /';;
|
|
|
+ *) nv "hide-identity CHAOS probe (timeout; config asserted below)"
|
|
|
+ printf '%s\n' "$id_out" | sed 's/^/ /';;
|
|
|
+esac
|
|
|
# Config-level assertion (deterministic): the base config must set it.
|
|
|
if docker exec "$C1" grep -q "hide-identity: yes" /etc/unbound/unbound.conf 2>/dev/null; then
|
|
|
ok "config: hide-identity: yes in base config"
|
|
|
@@ -217,12 +241,13 @@ docker run -d --name "$C4" --network "$NET" -v "$CFG_ID:/config:ro" "$IMAGE" >/d
|
|
|
sleep 3
|
|
|
id2_out="$(docker run --rm --network "$NET" -v "$(pwd)/test/chaos-check.py:/probe.py:ro" python:alpine python /probe.py "$(ip_of "$C4")" 5053 id.server. unbound-sec 2>&1)"
|
|
|
id2_rc=$?
|
|
|
-if [ $id2_rc -ne 0 ] || printf '%s' "$id2_out" | grep -q "FAIL"; then
|
|
|
- say " [warn] identity-control CHAOS probe flaky/failed (WSL overlay):"
|
|
|
- printf '%s\n' "$id2_out" | sed 's/^/ /'
|
|
|
-else
|
|
|
- ok "identity control: hide-identity:no reveals identity"
|
|
|
-fi
|
|
|
+case $id2_rc in
|
|
|
+ 0) ok "identity control: hide-identity:no reveals identity";;
|
|
|
+ 1) bad "identity control: hide-identity:no reveals identity (CONTENT deviation)"
|
|
|
+ printf '%s\n' "$id2_out" | sed 's/^/ /';;
|
|
|
+ *) nv "identity-control CHAOS probe (timeout)"
|
|
|
+ printf '%s\n' "$id2_out" | sed 's/^/ /';;
|
|
|
+esac
|
|
|
|
|
|
say "== 13. drop-in config include =="
|
|
|
# Fixtures are created on the host by test/run.sh (host paths required).
|
|
|
@@ -380,12 +405,15 @@ say "== 19. compose template starts (no recursive include) =="
|
|
|
# Regression test for the audit P1 finding: the template must start cleanly
|
|
|
# with the ACTUAL docker-compose.yml (old version mounted ./config over
|
|
|
# itself -> recursive include -> start aborted).
|
|
|
-REPO="${REPO_PATH:-$(pwd)}"
|
|
|
-if (cd "$REPO" && docker compose -f docker-compose.yml up -d >/dev/null 2>&1); then
|
|
|
+#
|
|
|
+# It runs under the dedicated test project (PROJ_TEST) with the test-image
|
|
|
+# override, so it creates only its own container/network/volume and never
|
|
|
+# touches a production deployment of the template.
|
|
|
+if compose_test up -d >/dev/null 2>&1; then
|
|
|
hc="no"
|
|
|
i=0
|
|
|
while [ $i -lt 20 ]; do
|
|
|
- h="$(docker inspect -f '{{.State.Health.Status}}' unbound 2>/dev/null)"
|
|
|
+ h="$(docker inspect -f '{{.State.Health.Status}}' "$C6_CONT" 2>/dev/null)"
|
|
|
[ "$h" = "healthy" ] && hc="yes" && break
|
|
|
sleep 6
|
|
|
i=$((i+1))
|
|
|
@@ -394,16 +422,95 @@ if (cd "$REPO" && docker compose -f docker-compose.yml up -d >/dev/null 2>&1); t
|
|
|
ok "compose template starts + healthy (no ports, conf.d + anchor volume)"
|
|
|
else
|
|
|
bad "compose template starts + healthy (status=$h)"
|
|
|
- docker logs unbound 2>&1 | tail -5 | sed 's/^/ /'
|
|
|
+ docker logs "$C6_CONT" 2>&1 | tail -5 | sed 's/^/ /'
|
|
|
fi
|
|
|
else
|
|
|
bad "compose template starts"
|
|
|
- (cd "$REPO" && docker compose -f docker-compose.yml up -d 2>&1 | tail -5) | sed 's/^/ /'
|
|
|
+ compose_test up -d 2>&1 | tail -5 | sed 's/^/ /'
|
|
|
fi
|
|
|
-(cd "$REPO" && docker compose -f docker-compose.yml down --remove-orphans --volumes >/dev/null 2>&1)
|
|
|
+compose_test down --remove-orphans --volumes >/dev/null 2>&1
|
|
|
+
|
|
|
+say "== 20. DNSSEC negative test: invalid signature -> SERVFAIL =="
|
|
|
+# Controlled zone "broken.example" served by a static responder: a
|
|
|
+# well-formed RRSIG whose DNSKEY cannot be anchored in the trust chain (no
|
|
|
+# parent DS). A validating resolver must reject it with SERVFAIL (without
|
|
|
+# CD). This catches regressions like val-permissive-mode: yes, which would
|
|
|
+# still validate good answers but let broken ones through.
|
|
|
+#
|
|
|
+# 1) generate the zone packet (fresh RRSIG timestamps) in a python container
|
|
|
+# 2) start a static UDP responder serving it
|
|
|
+# 3) start a test unbound with a forward-zone to the responder
|
|
|
+# 4) query www.broken.example A with DO -> expect SERVFAIL (rcode=2)
|
|
|
+#
|
|
|
+# RESP and C6 get their OWN network (not $NET), so they can't be affected by
|
|
|
+# the other test containers and the test stays deterministic.
|
|
|
+REPO="${REPO_PATH:-$(pwd)}"
|
|
|
+NEG_NET="ubsec-negnet"
|
|
|
+docker network create "$NEG_NET" >/dev/null 2>&1
|
|
|
+BZBIN="$(pwd)/test/.broken-zone.bin"
|
|
|
+# Remove any stale BZBIN first: if a previous run left a DIRECTORY there (Docker
|
|
|
+# creates a dir when mounting a missing file), the generator would fail with
|
|
|
+# IsADirectoryError.
|
|
|
+rm -rf "$BZBIN"
|
|
|
+docker run --rm -v "$REPO/test/make-broken-zone.py:/m.py:ro" -v "$(pwd)/test:/o" \
|
|
|
+ python:alpine sh -c "pip install -q dnspython cryptography 2>/dev/null; python /m.py /o/.broken-zone.bin" >/dev/null 2>&1
|
|
|
+if [ ! -f "$BZBIN" ]; then
|
|
|
+ bad "generate broken.example zone packet"
|
|
|
+else
|
|
|
+ ok "generate broken.example zone packet"
|
|
|
+fi
|
|
|
+docker run -d --name "$RESP" --network "$NEG_NET" \
|
|
|
+ -v "$BZBIN:/p.bin:ro" -v "$REPO/test/broken-zone-responder.py:/r.py:ro" \
|
|
|
+ python:alpine python /r.py /p.bin 5353 >/dev/null
|
|
|
+# Get the responder's IP from ITS OWN log (it prints its container IP). This
|
|
|
+# is more reliable than `docker inspect` from the host, which can be empty
|
|
|
+# while the container is starting on a slow WSL daemon.
|
|
|
+RESP_IP=""; i=0
|
|
|
+while [ $i -lt 15 ]; do
|
|
|
+ RESP_IP="$(docker logs "$RESP" 2>&1 | grep -oE 'responder ip=[0-9.]+' | head -1 | cut -d= -f2)"
|
|
|
+ [ -n "$RESP_IP" ] && [ "$RESP_IP" != "0.0.0.0" ] && break
|
|
|
+ sleep 2; i=$((i+1))
|
|
|
+done
|
|
|
+# Fallback to docker inspect if the log didn't yield an IP.
|
|
|
+if [ -z "$RESP_IP" ] || [ "$RESP_IP" = "0.0.0.0" ]; then
|
|
|
+ RESP_IP="$(docker inspect -f '{{(index .NetworkSettings.Networks "'"$NEG_NET"').IPAddress}}' "$RESP" 2>/dev/null)"
|
|
|
+fi
|
|
|
+[ -n "$RESP_IP" ] || { bad "negative-test responder has an IP (got empty)"
|
|
|
+ docker logs "$RESP" 2>&1 | tail -3 | sed 's/^/ /'
|
|
|
+ say " networks: $(docker inspect -f '{{json .NetworkSettings.Networks}}' "$RESP" 2>/dev/null)"
|
|
|
+ say " state: $(docker inspect -f '{{.State.Running}} exit={{.State.ExitCode}}' "$RESP" 2>/dev/null)"; }
|
|
|
+FWD_DIR="$(pwd)/test/fixture-broken-fwd"
|
|
|
+rm -rf "$FWD_DIR"; mkdir -p "$FWD_DIR"; chmod 755 "$FWD_DIR"
|
|
|
+printf 'forward-zone:\n name: "broken.example"\n forward-addr: %s@5353\n' "$RESP_IP" > "$FWD_DIR/99-broken.conf"
|
|
|
+chmod 644 "$FWD_DIR/99-broken.conf"
|
|
|
+docker run -d --name "$C6" --network "$NEG_NET" -v "$FWD_DIR:/config:ro" "$IMAGE" >/dev/null
|
|
|
+# wait for readiness: unbound is ready when it answers the (broken) query at
|
|
|
+# all — a SERVFAIL is a valid response, so we check for ANY rcode, not a
|
|
|
+# successful (exit 0) drill.
|
|
|
+ready="no"; i=0
|
|
|
+while [ $i -lt 15 ]; do
|
|
|
+ if docker exec "$C6" drill -p 5053 -D www.broken.example A @127.0.0.1 2>/dev/null | grep -q "rcode:"; then
|
|
|
+ ready="yes"; break
|
|
|
+ fi
|
|
|
+ sleep 2; i=$((i+1))
|
|
|
+done
|
|
|
+[ "$ready" = "yes" ] || bad "negative-test resolver ready"
|
|
|
+sf_out="$(docker exec "$C6" drill -p 5053 -D www.broken.example A @127.0.0.1 2>/dev/null)"
|
|
|
+if printf '%s' "$sf_out" | grep -q "rcode: SERVFAIL"; then
|
|
|
+ ok "invalid signature -> SERVFAIL (no CD; validator rejects unanchorable DNSKEY)"
|
|
|
+else
|
|
|
+ bad "invalid signature -> SERVFAIL (got: $(printf '%s' "$sf_out" | grep rcode | head -1))"
|
|
|
+ printf '%s\n' "$sf_out" | sed 's/^/ /'
|
|
|
+fi
|
|
|
+rm -rf "$FWD_DIR"
|
|
|
|
|
|
say ""
|
|
|
say "=================================================="
|
|
|
-say "RESULT: $PASS passed, $FAIL failed"
|
|
|
+say "RESULT: $PASS passed, $FAIL failed, $NOTVERIFIED not verified"
|
|
|
+if [ "$NOTVERIFIED" -gt 0 ]; then
|
|
|
+ say "(not verified = infrastructure timeout, not a content finding; re-run to clear)"
|
|
|
+fi
|
|
|
say "=================================================="
|
|
|
+# A content finding (FAIL) fails the run. Not-verified checks are visible but
|
|
|
+# do not fail the run on their own (they are infrastructure, re-run to clear).
|
|
|
[ $FAIL -eq 0 ]
|