The policy bounds and the status a ban answers with are now proven against the shipped image, not only the source tree

OPEN-20's guard had never been driven from the image: the compose gate
wrote policy values but never an out-of-range one, and no gate had ever
asked whether a VALID engineBlockStatus reaches the visitor. Seven
assertions close that: 400 for engineBlockStatus=1000 naming the range
400..599, the policy unchanged after the refusal, the same for
ipv4KeyPrefixLength=0 against 8..32, a banned visitor answering 451
while the operator asked for 451, and the original status back in force
afterwards.

Teeth measured, then reverted: with PolicyProblem's answer discarded,
PolicyValidationTests answer 16 failed / 2 passed and the compose gate
answers 104 passed / 3 failed on a rebuilt image. The 451 assertion
stays green under that mutation, which is the right split — it tests the
valid half, not the guard.
This commit is contained in:
Pavlo Ratushnyi
2026-10-02 17:29:39 +02:00
parent fe9b09f683
commit 24e329d2e1
+50
View File
@@ -419,6 +419,56 @@ check 'the curl-friendly ?token= still works on a write' '200' \
"$(code "$EDGE/admin-api/blocks?token=$OPENWAF_ADMIN_TOKEN&source=operator")"
admin -X DELETE "$EDGE/admin-api/blocks?source=operator" >/dev/null
echo '- a policy value outside its bounds is refused, and a valid one reaches the wire'
# OPEN-20 measured this on the shipped image: PUT {"engineBlockStatus":1000}
# answered 200, the value was stored, and the next banned visitor got no HTTP
# status at all — curl reported "Unsupported HTTP/1 subversion in response" and
# the connection closed. PUT {"ipv4KeyPrefixLength":0} answered 200 and collapsed
# every IPv4 address onto the literal key "*": one 404 from one address banned
# the next three on their first request. The integration suite proves the guard;
# what is proven here is that the image an operator deploys carries it, and that
# the half nobody tested — a VALID status reaching enforcement — really works.
ENGINE_BEFORE=$(admin "$EDGE/admin-api/policy" | jval engineBlockStatus)
PREFIX_BEFORE=$(admin "$EDGE/admin-api/policy" | jval ipv4KeyPrefixLength)
printf ' info the policy in force before the refused writes: engineBlockStatus=%s ipv4KeyPrefixLength=%s\n' \
"$ENGINE_BEFORE" "$PREFIX_BEFORE"
REFUSED_BODY=$(admin -X PUT -H 'Content-Type: application/json' \
-d '{"engineBlockStatus":1000}' "$EDGE/admin-api/policy")
check 'a policy value outside its bounds is a 400, not a 200 that changed nothing' '400' \
"$(code -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -X PUT -H 'Content-Type: application/json' \
-d '{"engineBlockStatus":1000}' "$EDGE/admin-api/policy")"
check 'and the refusal names the key and the range it is outside' 'yes' \
"$(printf '%s' "$REFUSED_BODY" | grep -q 'engineBlockStatus must be 400..599; got 1000' && echo yes || echo no)"
check 'the policy it refused is the policy it had before the refusal' "$ENGINE_BEFORE" \
"$(admin "$EDGE/admin-api/policy" | jval engineBlockStatus)"
check 'a second out-of-range key is refused with its own range' 'yes' \
"$(admin -X PUT -H 'Content-Type: application/json' \
-d '{"ipv4KeyPrefixLength":0}' "$EDGE/admin-api/policy" \
| grep -q 'ipv4KeyPrefixLength must be 8..32; got 0' && echo yes || echo no)"
check 'and the granularity in force is the one it had, not the one it was asked for' "$PREFIX_BEFORE" \
"$(admin "$EDGE/admin-api/policy" | jval ipv4KeyPrefixLength)"
# The valid half of the contract, which no gate had ever driven: the operator is
# allowed to choose the status a ban answers with, and the choice has to be what
# the visitor actually receives. Threshold 3 is already in force from the scene
# above, so four refusals from a fresh address is one ban.
admin -X PUT -H 'Content-Type: application/json' -d '{"engineBlockStatus":451}' \
"$EDGE/admin-api/policy" >/dev/null
STATUS_SRC=203.0.113.245
for _ in 1 2 3 4; do code -H "$(xff "$STATUS_SRC")" "$EDGE/no-such-page" >/dev/null; done
BAN_STATUS=000
for _ in $(seq 1 12); do
BAN_STATUS=$(code -H "$(xff "$STATUS_SRC")" "$EDGE/no-such-page")
[ "$BAN_STATUS" = "451" ] && break
sleep 2
done
printf ' info what a banned visitor answers while engineBlockStatus is 451: %s\n' "$BAN_STATUS"
check 'a valid engineBlockStatus reaches enforcement on the wire, from the shipped image' '451' "$BAN_STATUS"
admin -X PUT -H 'Content-Type: application/json' -d "{\"engineBlockStatus\":$ENGINE_BEFORE}" \
"$EDGE/admin-api/policy" >/dev/null
admin -X DELETE "$EDGE/admin-api/blocks?source=engine" >/dev/null
check 'and putting the original status back is reflected in the policy read' "$ENGINE_BEFORE" \
"$(admin "$EDGE/admin-api/policy" | jval engineBlockStatus)"
echo '- a pillar that stops reading its table says so'
# Measured on the shipped image before this was fixed: with policy_settings
# dropped out from under a running edge, GET /admin-api/policy kept answering the