The compose scenes now name the policy they stand on, and prove their sources

The ban scene failed on the first Linux rehearsal and passed on the macOS
host, and the difference was not the platform: the read scene above it drops
policy_settings and recreates it empty, so once the reload succeeds against
the empty table the operator's overrides are gone and the policy is back to
the configured defaults — streakThreshold 10, trustProxyHeaders false. With
proxy headers untrusted, every "new source" in the write and ban scenes is
the same docker bridge address, the ban is never attempted, and the log line
the scene waits for never appears. Which policy is in force after that
restore is a timing question, so the scene passed on one machine and failed
on the other for a reason that had nothing to do with what it asserts.

Both scenes now PUT the policy they depend on before they generate traffic,
and both prove the sources they claim were seen are really in the live
streak map — three distinct keys in the write scene, the scanner's own key in
the ban scene — so the scene cannot pass by counting one address three times.

The streaks fetch is polled rather than sampled once: the first attempt right
after a burst answered a completely empty body while the next answered
complete, and an assertion on one instant is not a contract.

Gate on the host at this commit: 74 passed, 0 failed (was 72 + the 2 new).
This commit is contained in:
Pavlo Ratushnyi
2026-10-02 09:46:05 +02:00
parent 3f24c5d31c
commit 12ccb55423
+47
View File
@@ -40,6 +40,32 @@ jget() { python3 -c "import json,sys
d=json.load(sys.stdin)
for o in d:
if $1: print(o.get('$2') or ''); break"; }
# /admin-api/streaks answers with an OBJECT that wraps the list, so a predicate
# written for jcount walks the object's keys instead and compares strings to
# dicts. streaks_where runs the predicate over the wrapped list and answers -1
# for a body it cannot parse, so a broken fetch shows up as a wrong number
# rather than as a python traceback in the middle of the gate.
streaks_where() { python3 -c "import json,sys
try:
d=json.load(sys.stdin); print(sum(1 for b in d['streaks'] if $1))
except Exception:
print(-1)"; }
# Fetched with polling, not sampled once: the first attempt right after a burst
# has been measured answering a completely empty body while the next answered
# complete, and an assertion on one instant is not a contract.
streaks_fetch() {
STREAKS_JSON=''
for _ in $(seq 1 6); do
STREAKS_JSON=$(admin "$EDGE/admin-api/streaks?limit=1000")
[ -n "$STREAKS_JSON" ] && break
sleep 2
done
}
streaks_info() {
printf ' info the live streak map: %s tracked, %s standing\n' \
"$(printf '%s' "$STREAKS_JSON" | jval trackedSources)" \
"$(printf '%s' "$STREAKS_JSON" | jval standingStreaks)"
}
code() { curl -s -m 10 -o /dev/null -w '%{http_code}' "$@"; }
hdr() { curl -s -m 10 -D - -o /dev/null "$@" | tr -d '\r'; }
xff() { printf 'X-Forwarded-For: %s' "$1"; }
@@ -361,6 +387,16 @@ echo '- a pillar that cannot write says so'
# "AlertWriter: could not persist…". A trigger, not a dropped table, on purpose:
# a missing table breaks the listing too, and a broken listing is honest about
# being broken. The lie this asserts is the 200 that stays complete-looking.
# State the policy this scene depends on, and prove the source keys it claims
# are real. The read scene above drops policy_settings and recreates it empty,
# which erases the operator's overrides: once the reload succeeds against the
# empty table the policy reverts to the configured defaults, and with
# trustProxyHeaders back to false every "new source" below is the same docker
# bridge address and the scene passes for the wrong reason. Which policy is in
# force after that restore is not deterministic across runs — the first Linux
# rehearsal of the ban scene failed exactly there.
admin -X PUT -H 'Content-Type: application/json' \
-d '{"streakThreshold":3,"trustProxyHeaders":true}' "$EDGE/admin-api/policy" >/dev/null
TOTAL_BEFORE=$(hdr -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" "$EDGE/admin-api/observations?limit=1" \
| grep -i '^x-total-count:' | tr -d '\r' | awk '{print $2}')
sidecar <<'PYSQL'
@@ -393,6 +429,12 @@ TOTAL_AFTER=$(hdr -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" "$EDGE/admin-api/obse
| grep -i '^x-total-count:' | tr -d '\r' | awk '{print $2}')
printf ' info X-Total-Count across the break: %s -> %s (three new sources saw, none stored)\n' "$TOTAL_BEFORE" "$TOTAL_AFTER"
check 'the listing still answers with the count it had before the break' "$TOTAL_BEFORE" "$TOTAL_AFTER"
# Not vacuous: the three sources this scene says were seen are in the live
# streak map, so they really were three distinct sources and not one bridge
# address wearing a header nobody trusted.
streaks_fetch; streaks_info
check 'the sources this scene lost were really three distinct sources' '3' \
"$(printf '%s' "$STREAKS_JSON" | streaks_where "b['sourceKey'] in ('203.0.113.201','203.0.113.202','203.0.113.203')")"
check 'the failure it reports is the real reason, not an EF wrapper' 'yes' \
"$(admin "$EDGE/admin-api/state" | jval observationLastWriteError | grep -qi 'durable write blocked' && echo yes || echo no)"
# Reporting-path failures are stated, not gated. The first version of this gate
@@ -444,6 +486,8 @@ for op in ("INSERT", "UPDATE"):
"BEGIN SELECT RAISE(ABORT, 'gate: ban write blocked'); END")
print("triggers:", [r[0] for r in c.execute("SELECT name FROM sqlite_master WHERE type='trigger'")])
PYSQL
admin -X PUT -H 'Content-Type: application/json' \
-d '{"streakThreshold":3,"trustProxyHeaders":true}' "$EDGE/admin-api/policy" >/dev/null
BAN_SRC=203.0.113.241
# Counted before and after, not in total: an earlier scene in this same run may
# legitimately have produced a race line, and a total would blame this scene for
@@ -453,6 +497,9 @@ BAN_CODES=""
for i in $(seq 1 5); do BAN_CODES="$BAN_CODES $(code -H "$(xff "$BAN_SRC")" "$EDGE/unbanned-$i")"; done
printf ' info answers from a scanner at threshold 3 while ban writes are blocked:%s\n' "$BAN_CODES"
check 'the scanner is never banned while the ban write fails' '404 404 404 404 404' "${BAN_CODES# }"
streaks_fetch; streaks_info
check 'the scanner really was one source the edge tracked' 'yes' \
"$(printf '%s' "$STREAKS_JSON" | streaks_where "b['sourceKey']=='$BAN_SRC'" | awk '{exit ($1+0>=1)?0:1}' && echo yes || echo no)"
check 'and no engine ban for it reached storage' 'yes' \
"$(admin "$EDGE/admin-api/blocks?source=engine" | jcount "b['sourceKey']=='$BAN_SRC'" | awk '{exit ($1+0==0)?0:1}' && echo yes || echo no)"
check 'the state counts the ban write that failed' 'yes' \