|
@@ -4,9 +4,10 @@
|
|
|
# Runs fully inside Docker: this script is executed in a docker:cli container
|
|
# Runs fully inside Docker: this script is executed in a docker:cli container
|
|
|
# with the Docker socket mounted; every assertion targets containers.
|
|
# 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
|
|
|
|
|
|
|
+# Usage:
|
|
|
|
|
+# ./test/run.sh (host wrapper; recommended)
|
|
|
|
|
+# or directly in a docker:cli container with the socket + repo mounted
|
|
|
|
|
+# at the same absolute path as on the host (REPO_PATH set).
|
|
|
|
|
|
|
|
set -u
|
|
set -u
|
|
|
|
|
|
|
@@ -14,9 +15,12 @@ IMAGE="unbound-sec:test"
|
|
|
C1="ubsec-t1" # main hardened container
|
|
C1="ubsec-t1" # main hardened container
|
|
|
C2="ubsec-t2" # valid drop-in container
|
|
C2="ubsec-t2" # valid drop-in container
|
|
|
C3="ubsec-t3" # broken drop-in container
|
|
C3="ubsec-t3" # broken drop-in container
|
|
|
|
|
+C4="ubsec-t4" # identity control container
|
|
|
NET="ubsec-testnet"
|
|
NET="ubsec-testnet"
|
|
|
-CFG1="$(pwd)/test/fixture-config-ok"
|
|
|
|
|
-CFG2="$(pwd)/test/fixture-config-bad"
|
|
|
|
|
|
|
+# 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"
|
|
|
|
|
+CFG2="${REPO_PATH:-$(pwd)}/test/fixture-config-bad"
|
|
|
PASS=0
|
|
PASS=0
|
|
|
FAIL=0
|
|
FAIL=0
|
|
|
|
|
|
|
@@ -25,8 +29,9 @@ ok() { PASS=$((PASS+1)); say " [PASS] $1"; }
|
|
|
bad() { FAIL=$((FAIL+1)); say " [FAIL] $1"; }
|
|
bad() { FAIL=$((FAIL+1)); say " [FAIL] $1"; }
|
|
|
|
|
|
|
|
cleanup() {
|
|
cleanup() {
|
|
|
- docker rm -f "$C1" "$C2" "$C3" >/dev/null 2>&1
|
|
|
|
|
|
|
+ docker rm -f "$C1" "$C2" "$C3" "$C4" >/dev/null 2>&1
|
|
|
docker network rm "$NET" >/dev/null 2>&1
|
|
docker network rm "$NET" >/dev/null 2>&1
|
|
|
|
|
+ rm -rf "$(pwd)/test/fixture-identity" 2>/dev/null
|
|
|
}
|
|
}
|
|
|
trap cleanup EXIT
|
|
trap cleanup EXIT
|
|
|
|
|
|
|
@@ -46,7 +51,7 @@ docker network create "$NET" >/dev/null
|
|
|
docker run -d --name "$C1" --network "$NET" \
|
|
docker run -d --name "$C1" --network "$NET" \
|
|
|
-p 5053:5053/udp -p 5053:5053/tcp \
|
|
-p 5053:5053/udp -p 5053:5053/tcp \
|
|
|
--read-only \
|
|
--read-only \
|
|
|
- --tmpfs /tmp --tmpfs /run/unbound \
|
|
|
|
|
|
|
+ --tmpfs /tmp --tmpfs "/run/unbound:uid=1500,gid=1500" \
|
|
|
--security-opt no-new-privileges:true \
|
|
--security-opt no-new-privileges:true \
|
|
|
--cap-drop ALL \
|
|
--cap-drop ALL \
|
|
|
"$IMAGE" >/dev/null
|
|
"$IMAGE" >/dev/null
|
|
@@ -88,8 +93,11 @@ else
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
say "== 6. DNSSEC (AD bit, DO query) =="
|
|
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
|
|
|
|
|
|
|
+probe_out="$(docker run --rm --network "$NET" -v "$(pwd)/test/dns-check.py:/probe.py:ro" python:alpine python /probe.py "$C1" 5053 2>&1)"
|
|
|
|
|
+probe_rc=$?
|
|
|
|
|
+if [ $probe_rc -ne 0 ] || printf '%s' "$probe_out" | grep -q "FAIL"; then
|
|
|
bad "DNSSEC AD-bit probe"
|
|
bad "DNSSEC AD-bit probe"
|
|
|
|
|
+ printf '%s\n' "$probe_out" | sed 's/^/ /'
|
|
|
else
|
|
else
|
|
|
ok "DNSSEC AD-bit probe"
|
|
ok "DNSSEC AD-bit probe"
|
|
|
fi
|
|
fi
|
|
@@ -145,17 +153,35 @@ else
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
say "== 12. hide-identity / hide-version =="
|
|
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
|
|
|
|
|
|
|
+id_out="$(docker run --rm --network "$NET" -v "$(pwd)/test/chaos-check.py:/probe.py:ro" python:alpine python /probe.py "$C1" 5053 id.server. empty 2>&1)"
|
|
|
|
|
+id_rc=$?
|
|
|
|
|
+if [ $id_rc -ne 0 ] || printf '%s' "$id_out" | grep -q "FAIL"; then
|
|
|
|
|
+ bad "hide-identity: id.server. answer is empty"
|
|
|
|
|
+ printf '%s\n' "$id_out" | sed 's/^/ /'
|
|
|
|
|
+else
|
|
|
|
|
+ ok "hide-identity: id.server. answer is empty"
|
|
|
|
|
+fi
|
|
|
|
|
+
|
|
|
|
|
+# Control: same image with hide-identity switched off must reveal the identity.
|
|
|
|
|
+CFG_ID="${REPO_PATH:-$(pwd)}/test/fixture-identity"
|
|
|
|
|
+mkdir -p "$CFG_ID"
|
|
|
|
|
+printf 'server:\n hide-identity: no\n' > "$CFG_ID/00-identity.conf"
|
|
|
|
|
+docker run -d --name "$C4" --network "$NET" -v "$CFG_ID:/config:ro" "$IMAGE" >/dev/null
|
|
|
|
|
+sleep 3
|
|
|
|
|
+id2_out="$(docker run --rm --network "$NET" -v "$(pwd)/test/chaos-check.py:/probe.py:ro" python:alpine python /probe.py "$C4" 5053 id.server. unbound-sec 2>&1)"
|
|
|
|
|
+id2_rc=$?
|
|
|
|
|
+if [ $id2_rc -ne 0 ] || printf '%s' "$id2_out" | grep -q "FAIL"; then
|
|
|
|
|
+ bad "identity control: hide-identity:no reveals identity"
|
|
|
|
|
+ printf '%s\n' "$id2_out" | sed 's/^/ /'
|
|
|
|
|
+else
|
|
|
|
|
+ ok "identity control: hide-identity:no reveals identity"
|
|
|
|
|
+fi
|
|
|
|
|
|
|
|
say "== 13. drop-in config include =="
|
|
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"
|
|
|
|
|
|
|
+# Fixtures are created on the host by test/run.sh (host paths required).
|
|
|
|
|
+if [ ! -f "$CFG1/99-test.conf" ] || [ ! -f "$CFG2/99-broken.conf" ]; then
|
|
|
|
|
+ bad "test fixtures missing (run via test/run.sh)"
|
|
|
|
|
+fi
|
|
|
|
|
|
|
|
docker run -d --name "$C2" --network "$NET" -v "$CFG1:/config:ro" "$IMAGE" >/dev/null
|
|
docker run -d --name "$C2" --network "$NET" -v "$CFG1:/config:ro" "$IMAGE" >/dev/null
|
|
|
sleep 3
|
|
sleep 3
|