Measured on the shipped image (openwaf:c28, the head tree), one allow entry
written for one minute against an operator block on the same address:
03:58:16 POST /admin-api/allow {"match":"192.168.65.1","expiresInMinutes":1} -> 204
03:58:20 GET /whatever -> 502 (passed to the upstream: the exemption is in force)
03:59:38 GET /whatever -> 301 (the minute has passed; the block is back)
03:59:39 GET /admin-api/allow -> 200, the row still listed, no liveness field
GET /admin-api/state -> "allowEntries":1
The engine was right and the surface was wrong: the operator's table said
"exempted" a minute after the edge stopped honouring it, and the pill's number
was a count of rows rather than a count of exemptions in force. Nothing prunes
those rows either — retention ages out observations, engine bans and alerts, and
an operator's own writes are not the machine's to delete — so the dead ones
accumulate exactly where they cannot be told apart from the live ones.
The same endpoint was also the last listing with no ceiling: 1,101 rows came back
in 130,386 bytes with no X-Total-Count and no X-Truncated, and every paging
parameter was ignored — ?limit=10, ?offset=1000, ?limit=0 and ?limit=100000 each
answered all 1,101.
Now: GET /admin-api/allow takes live (default true, live=false means "do not
filter", the same shape as /blocks), limit 1..2000 and offset, refuses a limit
nobody meant by name, and carries X-Total-Count and X-Truncated computed from the
same predicate as the rows. Each row carries live, computed from the same rule
the engine applies (AllowEntry.IsLive), and /state answers allowEntries as the
live count with allowEntriesExpired beside it. The page fetches live=false, marks
a dead row "EXPIRED, the edge no longer honours it", counts them under the table,
and its pill says "0 live - 1 expired".
Teeth, in this order: AllowListingHonestyTests (4) written first and run against
the unfixed tree — 4 failed, 0 passed, including "allowEntries expected 1, got 2"
and "X-Total-Count expected 5, got null". The wire assertions in the second test
passed before the fix and after it: the engine already knew. The console gate
seeds an allow entry with a one-minute TTL ahead of the waits it already pays, so
the expired state arrives for free, and asserts the dead row is listed and marked,
the live one is not, and the line under the table counts them; the two existing
row deletes are now aimed at a match instead of clicking the first remove button,
which with a second row in the table would have deleted whatever sorted first.
Numbers on this tree: host — build 0 warnings, unit 128/128, integration 113/113,
smoke 22 passed / 0 failed, compose 47 passed / 0 failed, console 50 assertions /
0 failed, image 261 MB. Linux rehearsal, each stage on its own — source in
mcr.microsoft.com/dotnet/sdk:10.0 (Ubuntu 24.04.5, SDK 10.0.401): unit 128/128,
integration 113/113, smoke 22/0; compose in docker:cli: 47/0, enforcement lag
11 ms; console in mcr.microsoft.com/playwright:v1.63.0-noble: 50/0.
142 lines
6.5 KiB
Bash
Executable File
142 lines
6.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# End-to-end smoke test against a real edge and a real upstream.
|
|
#
|
|
# The integration tests prove the decision logic in isolation; this proves the
|
|
# deployed shape: the binary starts, proxies to an upstream it knows nothing
|
|
# about, bans a source that drew enough refusals, answers the way the design
|
|
# says it should, and healthchecks itself the way a shell-less distroless image
|
|
# needs.
|
|
#
|
|
# Sources are simulated with X-Forwarded-For and TrustProxyHeaders=on. That is
|
|
# not a shortcut: it is the only way to exercise "this source is banned, that
|
|
# one is not" over a loopback connection, and it doubles as a check that the
|
|
# trusted-proxy path is wired.
|
|
set -uo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
EDGE_PORT=${EDGE_PORT:-18088}
|
|
UP_PORT=${UP_PORT:-18900}
|
|
DB=/tmp/openwaf-smoke-$$.db
|
|
TOKEN=smoketoken
|
|
BIN="$ROOT/dotnet/OpenWaf.Edge/bin/Release/net10.0/OpenWaf.Edge.dll"
|
|
[ -f "$BIN" ] || BIN="$ROOT/dotnet/OpenWaf.Edge/bin/Debug/net10.0/OpenWaf.Edge.dll"
|
|
|
|
export HEALTHCHECK_PORT="$EDGE_PORT"
|
|
|
|
SCANNER=203.0.113.66
|
|
OFFICER=198.51.100.7
|
|
Bystander=198.51.100.99
|
|
|
|
# Payloads live in single-quoted variables: embedding them in the command
|
|
# substitutions below with escaped quotes is exactly the kind of thing that
|
|
# silently truncates a body.
|
|
BLOCK_JSON='{"ip":"198.51.100.7","reason":"confirmed scraper","redirectTo":"https://honeypot.example.org/"}'
|
|
ALLOW_JSON='{"match":"198.51.100.0/24","note":"office"}'
|
|
POLICY_OFF_JSON='{"mode":"Off"}'
|
|
|
|
|
|
cleanup() {
|
|
[ -n "${EDGE_PID:-}" ] && kill "$EDGE_PID" 2>/dev/null
|
|
[ -n "${UP_PID:-}" ] && kill "$UP_PID" 2>/dev/null
|
|
rm -f "$DB" "$DB-shm" "$DB-wal"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
mkdir -p /tmp/openwaf-upstream
|
|
python3 -m http.server "$UP_PORT" --bind 127.0.0.1 -d /tmp/openwaf-upstream >/dev/null 2>&1 &
|
|
UP_PID=$!
|
|
|
|
rm -f "$DB"
|
|
ASPNETCORE_URLS="http://127.0.0.1:$EDGE_PORT" \
|
|
OPENWAF_ADMIN_TOKEN="$TOKEN" \
|
|
ConnectionStrings__OpenWaf="Data Source=$DB" \
|
|
OpenWaf__Policy__StreakThreshold=3 \
|
|
OpenWaf__Policy__Mode=Enforce \
|
|
OpenWaf__Policy__BanDuration="00:00:06" \
|
|
OpenWaf__Policy__TrustProxyHeaders=true \
|
|
ReverseProxy__Clusters__upstream__Destinations__upstream1__Address="http://127.0.0.1:$UP_PORT/" \
|
|
dotnet "$BIN" >/tmp/openwaf-smoke.log 2>&1 &
|
|
EDGE_PID=$!
|
|
|
|
for _ in $(seq 1 60); do
|
|
curl -fsS "http://127.0.0.1:$EDGE_PORT/healthz" >/dev/null 2>&1 && break
|
|
sleep 0.25
|
|
done
|
|
|
|
pass=0; fail=0
|
|
check() {
|
|
if [ "$2" = "$3" ]; then pass=$((pass+1)); printf ' ok %-56s %s\n' "$1" "$3"
|
|
else fail=$((fail+1)); printf ' FAIL %-56s expected %s, got %s\n' "$1" "$2" "$3"; fi
|
|
}
|
|
code() { curl -s -o /dev/null -w '%{http_code}' "$@"; }
|
|
from() { printf 'http://127.0.0.1:%s/%s' "$EDGE_PORT" "$1"; } # usage: from path + -H "X-Forwarded-For: ip"
|
|
|
|
echo "edge :$EDGE_PORT upstream :$UP_PORT db $DB"
|
|
|
|
echo '- streak ban'
|
|
for i in 1 2 3; do
|
|
check "probe $i from the scanner reaches the upstream" 404 \
|
|
"$(code -H "X-Forwarded-For: $SCANNER" "$(from wp-admin)")"
|
|
done
|
|
check '4th request from the scanner is refused by the edge' 403 \
|
|
"$(code -H "X-Forwarded-For: $SCANNER" "$(from anything)")"
|
|
check 'a bystander is untouched' 404 \
|
|
"$(code -H "X-Forwarded-For: $Bystander" "$(from anything)")"
|
|
check 'the refusal explains itself' blocked_by_policy \
|
|
"$(curl -s -H "X-Forwarded-For: $SCANNER" "$(from anything)" | python3 -c 'import sys,json;print(json.load(sys.stdin)["error"])')"
|
|
check 'the ban carries a Retry-After' yes \
|
|
"$(curl -s -D- -o /dev/null -H "X-Forwarded-For: $SCANNER" "$(from anything)" | grep -qi '^retry-after:' && echo yes || echo no)"
|
|
|
|
echo '- operator list'
|
|
check 'add an operator block' 204 \
|
|
"$(code -X POST -H "X-Admin-Token: $TOKEN" -H 'Content-Type: application/json' \
|
|
--data-binary "$BLOCK_JSON" \
|
|
"http://127.0.0.1:$EDGE_PORT/admin-api/blocks")"
|
|
check 'an operator block answers 301 with Location' https://honeypot.example.org/ \
|
|
"$(curl -s -o /dev/null -w '%{redirect_url}' -H "X-Forwarded-For: $OFFICER" "$(from anything)")"
|
|
|
|
echo '- allowlist outranks everything'
|
|
check 'allow the office range' 204 \
|
|
"$(code -X POST -H "X-Admin-Token: $TOKEN" -H 'Content-Type: application/json' \
|
|
--data-binary "$ALLOW_JSON" \
|
|
"http://127.0.0.1:$EDGE_PORT/admin-api/allow")"
|
|
check 'the blocked office address gets through' 404 \
|
|
"$(code -H "X-Forwarded-For: $OFFICER" "$(from anything)")"
|
|
check 'the scanner outside that range stays banned' 403 \
|
|
"$(code -H "X-Forwarded-For: $SCANNER" "$(from anything)")"
|
|
# The exemption listing used to be the only listing with no ceiling: every paging
|
|
# parameter was ignored and the response said nothing about how many rows there
|
|
# were. Measured on the shipped image: 1101 rows, 130,386 bytes, no X-Total-Count,
|
|
# and ?limit=10 answered all 1101.
|
|
check 'the allow listing says how many rows there are' yes \
|
|
"$(curl -s -D- -o /dev/null -H "X-Admin-Token: $TOKEN" \
|
|
"http://127.0.0.1:$EDGE_PORT/admin-api/allow" | grep -qi '^x-total-count:' && echo yes || echo no)"
|
|
check 'the allow listing refuses a limit nobody meant' 400 \
|
|
"$(code -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/allow?limit=0")"
|
|
check 'a page of one is a page of one' 1 \
|
|
"$(curl -s -H "X-Admin-Token: $TOKEN" \
|
|
"http://127.0.0.1:$EDGE_PORT/admin-api/allow?limit=1" | python3 -c 'import sys,json;print(len(json.load(sys.stdin)))')"
|
|
|
|
echo '- expiry and clearing'
|
|
sleep 7
|
|
check 'the engine ban lifted itself' 404 "$(code -H "X-Forwarded-For: $SCANNER" "$(from wp-admin)")"
|
|
check 'clearing engine bans leaves operator rows' '{"deleted":1}' \
|
|
"$(curl -s -X DELETE -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/blocks?source=engine" | tr -d ' ')"
|
|
check 'an operator row survives it' 1 \
|
|
"$(curl -s -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/blocks?source=operator" | python3 -c 'import sys,json;print(len(json.load(sys.stdin)))')"
|
|
|
|
echo '- admin surface'
|
|
check 'no token is refused' 401 "$(code "http://127.0.0.1:$EDGE_PORT/admin-api/blocks")"
|
|
check 'the policy is readable' Enforce \
|
|
"$(curl -s -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/policy" | python3 -c 'import sys,json;print(json.load(sys.stdin)["mode"])')"
|
|
check 'switching the engine off is accepted' Off \
|
|
"$(curl -s -X PUT -H "X-Admin-Token: $TOKEN" -H 'Content-Type: application/json' --data-binary "$POLICY_OFF_JSON" \
|
|
"http://127.0.0.1:$EDGE_PORT/admin-api/policy" | python3 -c 'import sys,json;print(json.load(sys.stdin)["mode"])')"
|
|
|
|
echo '- healthcheck mode (a shell-less image can only ask the binary)'
|
|
dotnet "$BIN" --healthcheck; check 'healthcheck exit code' 0 "$?"
|
|
|
|
echo
|
|
echo "passed $pass, failed $fail"
|
|
[ "$fail" -eq 0 ]
|