diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1d5faf2..015c129 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -267,7 +267,7 @@ jobs: - name: README assertion counts match what the gate ran run: ./scripts/ci-gates.sh readme-counts scripts/compose-smoke.sh - # The same stack, the same 373 assertions, and an image whose base is nothing: + # The same stack, the same 375 assertions, and an image whose base is nothing: # scratch plus the shared objects the program was linked against, the NSS # modules getaddrinfo needs, OpenSSL, and the CA bundle. This is the job that # answers "will it behave on a production host" for that shape — the first diff --git a/README.md b/README.md index e95e292..3c3901c 100644 --- a/README.md +++ b/README.md @@ -333,7 +333,7 @@ after a rebuild**. Measured on 2026-10-01: the same rebuilt image reported `docker volume rm openwaf_openwaf-geoip`. That is the command to reach for when the pin moves. -### Two images, one program, and the same 373 assertions against both +### Two images, one program, and the same 375 assertions against both `Dockerfile` ships the edge on `aspnet:10.0-noble-chiseled`: a distroless runtime, no shell, no package manager. `Dockerfile.scratch` ships the same @@ -350,8 +350,8 @@ same **12** shared objects and **19.9 MB**, scratch **218 MB** against chiseled **258 MB**. `scripts/compose-smoke.sh` runs unchanged against either image — the only change is the `docker-compose.scratch.yml` override — and it answered **368 passed, 0 failed** on both architectures. Re-measured on the same arm64 -host the evening of 2026-10-06, against the 373-assertion version of this gate: -**373 passed, 0 failed** against the chiseled image and **373 passed, 0 failed** +host the evening of 2026-10-06, against the 375-assertion version of this gate: +**375 passed, 0 failed** against the chiseled image and **375 passed, 0 failed** against scratch. The assertions are the reason the second Dockerfile is worth having, and the @@ -368,7 +368,7 @@ by application code."* A healthy container was not a working edge. ``` scripts/ci-gates.sh scratch-image # build it, print both images' sizes -scripts/ci-gates.sh scratch-smoke # the 373, against it +scripts/ci-gates.sh scratch-smoke # the 375, against it ``` And the fully static shape, measured the same day rather than argued: @@ -1745,7 +1745,7 @@ cannot mean different things. ``` scripts/ci-gates.sh all # restore, build, unit, integration, smoke, both images, both smokes -scripts/ci-gates.sh scratch-smoke # the 373, against the image with no base +scripts/ci-gates.sh scratch-smoke # the 375, against the image with no base scripts/ci-gates.sh unit # or any one gate on its own scripts/ci-gates.sh console # the page, in a real Chromium (not part of `all`) ``` @@ -1869,6 +1869,30 @@ mean: a read that did not parse prints `-1` where a real zero would sit, and bot of those runs printed `0`, so in the first the reads answered and agreed — what was missing was the requests, or the rows, not the parse. +A write that never reached the edge is now retried, and the retry is said out +loud. `code`'s `000` is the gate failing to reach the stack (OPEN-39), and for a +write that is worse than a wrong number: every assertion after it measures a +scene that never happened. Measured the same day (`/tmp/compose-diag.log`, the +run named above): one `POST` of a `/29` answered `000` while the container +reported `running/healthy`, and four range assertions went red about a row that +was never written — one of them a Python `StopIteration` from a bare `next()` +over a listing that held no such row. Writes now go through `admin_write`: a +non-answer is retried three times with the container's own state printed each +time, and a refusal is an answer, so `400` and `403` come back after one attempt +untouched. Retrying a write that got no response is safe on this surface because +every write it takes is keyed and idempotent — the six-parallel-POSTs scene +asserts that one address lands as one row, the transfer scene asserts that +importing the same document twice adds nothing — and the retry is bounded, so a +surface that is really closed still goes red. Measured against a stubbed `code` +that answers `000` twice and then `204`: the write returns `204` after three +attempts with two retry lines in the log, and a `400` comes back after one +attempt with none. The dead-edge scene asserts both halves against a container +that is really stopped — the write still answers `000`, and it says so three +times — because neither green run printed a retry line at all: the host was +quiet, and a rule like this is gated by a scene that makes the condition happen, +not by waiting to catch one. Two assertions, three bare `next()` reads given the +sentinel treatment OPEN-48 wrote for `jval`, and the gate's total is **375**. + The README's own numbers became a gate. `scripts/ci-gates.sh readme-counts scripts/` compares the assertion count the README prints for a gate with the total that gate recorded in this run — each gate writes its total into @@ -2301,7 +2325,7 @@ dotnet/ OpenWaf.Tests.Unit/ 378 tests over the decision logic, the budget window, the refusal wording, the schema baseline and the durability counters OpenWaf.Tests.Integration/ 405 tests driving the real pipeline against a fake upstream scripts/smoke.sh 256 assertions against a running edge + a real upstream -scripts/compose-smoke.sh 373 assertions against the built image (compose + nginx) +scripts/compose-smoke.sh 375 assertions against the built image (compose + nginx) scripts/console-check.cjs 168 assertions against the page, in a real Chromium scripts/geo-db-freshness.sh the pinned geo database vs the vendor (0/1/2) .github/workflows/ci.yml runs the gates on every push diff --git a/scripts/ci-gates.sh b/scripts/ci-gates.sh index f259a34..4e1e0ea 100755 --- a/scripts/ci-gates.sh +++ b/scripts/ci-gates.sh @@ -268,7 +268,7 @@ case "${1:-all}" in # same invocation. export GATE_TOTALS_DIR="${GATE_TOTALS_DIR:-$(mktemp -d)}" restore; build; unit; integration; schema-script; smoke; image; compose_smoke - # The scratch image and the same 373 assertions against it. It is in `all` + # The scratch image and the same 375 assertions against it. It is in `all` # because it is the shipped shape, not an experiment: the only difference a # caller can see is what is under the program. scratch_image; scratch_smoke diff --git a/scripts/compose-smoke.sh b/scripts/compose-smoke.sh index 52edd3e..7a872c6 100755 --- a/scripts/compose-smoke.sh +++ b/scripts/compose-smoke.sh @@ -137,6 +137,31 @@ code() { printf '%s' "$http_code" } dead_codes() { wc -l < "$DEAD_LOG" | tr -d ' '; } +# An admin write, differing from `code` in exactly one case. A 000 is the gate +# failing to reach the stack, not an answer from the edge (OPEN-39) — and for a +# write that is worse than a wrong number, because every assertion after it +# measures a scene that never happened. Measured 2026-10-06 (/tmp/compose-diag.log, +# recorded in the README): one POST of a /29 answered 000 while the container +# reported running/healthy — another project's dotnet suite was running on the +# same daemon — and four range assertions went red about a row that was never +# written. So the write is retried, three times, and every retry is printed. +# Retrying a write that got no response is safe on this surface because every +# write it takes is keyed and idempotent: the six-parallel-POSTs scene asserts +# that one address lands as one row, and the transfer scene asserts that +# importing the same document twice adds nothing. A refusal is an answer, so 400 +# and 403 come back untouched; only the non-answer is retried. +admin_write() { + local n=0 out + out=$(code "$@") + while [ "$out" = 000 ] && [ "$n" -lt 3 ]; do + n=$((n + 1)) + printf ' info the write reached nothing: attempt %s of 4, the edge reports %s\n' \ + "$n" "$(edge_state)" >&2 + sleep 2 + out=$(code "$@") + done + printf '%s' "$out" +} hdr() { curl -s -m 10 -D - -o /dev/null "$@" | tr -d '\r'; } xff() { printf 'X-Forwarded-For: %s' "$1"; } # One scalar field out of a JSON object, for the endpoints that answer with an @@ -1566,7 +1591,7 @@ check 'and it refuses the path on the restarted edge' '403' \ "$(code -H "X-Forwarded-For: $OPEN55_IP" "$EDGE/upgrade-check")" OPEN55_RULE=$(admin "$EDGE/admin-api/rules" | jget "o['pattern']=='/upgrade-check*'" id) check 'and the rule is removable again, so the volume is left clean' '204' \ - "$(code -X DELETE -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" "$EDGE/admin-api/rules/$OPEN55_RULE")" + "$(admin_write -X DELETE -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" "$EDGE/admin-api/rules/$OPEN55_RULE")" echo "- the edge's own numbers leave in Prometheus format" # OPEN-58. The smoke gate proves the endpoint against a process built from this @@ -1608,14 +1633,14 @@ OPEN59_DECIDE=$(admin "$EDGE/admin-api/decide?ip=$OPEN59_IP&path=/preview-only") check 'the preview answers with the verdict the wire would give' block_rule \ "$(printf '%s' "$OPEN59_DECIDE" | python3 -c 'import sys,json;print(json.load(sys.stdin)["verdict"])')" check 'and names the pillar that spoke' requestRule \ - "$(printf '%s' "$OPEN59_DECIDE" | python3 -c 'import sys,json;p=json.load(sys.stdin)["pillars"];print(next(r["pillar"] for r in p if r["outcome"]=="answered"))')" + "$(printf '%s' "$OPEN59_DECIDE" | python3 -c 'import sys,json;p=json.load(sys.stdin)["pillars"];print(next((r["pillar"] for r in p if r["outcome"]=="answered"), "no-pillar"))')" check 'and echoes the rule it matched, pattern and all' '/preview-only*' \ "$(printf '%s' "$OPEN59_DECIDE" | python3 -c 'import sys,json;print(json.load(sys.stdin)["rule"]["pattern"])')" check 'and refuses an address that is not an address rather than answering pass' '400' \ "$(code -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" "$EDGE/admin-api/decide?ip=203.0.113&path=/preview-only")" OPEN59_RULE=$(admin "$EDGE/admin-api/rules" | jget "o['pattern']=='/preview-only*'" id) check 'and the rule is removable again, so the volume is left clean' '204' \ - "$(code -X DELETE -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" "$EDGE/admin-api/rules/$OPEN59_RULE")" + "$(admin_write -X DELETE -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" "$EDGE/admin-api/rules/$OPEN59_RULE")" echo "- the operator's config leaves the shipped edge as one document (OPEN-61)" # The transfer on the image an operator would deploy. The in-process suite proves @@ -1650,9 +1675,9 @@ check 'a document from another version is refused naming the version' 'yes' \ "$(admin -X POST -H 'Content-Type: application/json' -d '{"version":999,"blocks":[]}' "$EDGE/admin-api/import" \ | grep -q '999' && echo yes || echo no)" check 'and the closed surface stays closed over it' '401' \ - "$(code -X POST -H 'Content-Type: application/json' -d '{"version":1}' "$EDGE/admin-api/import")" + "$(admin_write -X POST -H 'Content-Type: application/json' -d '{"version":1}' "$EDGE/admin-api/import")" check 'the transfer row is removable again, so the volume is left clean' '200' \ - "$(code -X DELETE -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" \ + "$(admin_write -X DELETE -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" \ "$EDGE/admin-api/blocks?source=operator&key=$OPEN61_IP")" echo '- a second token that can look but not change' @@ -1673,7 +1698,7 @@ RO_WRITE=$(curl -s -m 10 -X POST -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" \ -H 'Content-Type: application/json' -d '{"ip":"203.0.113.181","reason":"must not land"}' \ "$EDGE/admin-api/blocks") check 'a read-only token cannot write a block on the shipped image' '403' \ - "$(code -X POST -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" -H 'Content-Type: application/json' \ + "$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" -H 'Content-Type: application/json' \ -d '{"ip":"203.0.113.181","reason":"must not land"}' "$EDGE/admin-api/blocks")" check 'the refusal says the token is read-only, not unknown' 'yes' \ "$(printf '%s' "$RO_WRITE" | grep -q 'read-only' && echo yes || echo no)" @@ -1682,7 +1707,7 @@ check 'and it names the key that would grant the write' 'yes' \ check 'the refused write left no row behind' '0' \ "$(admin "$EDGE/admin-api/blocks?live=false" | jcount 'b["sourceKey"]=="203.0.113.181"')" check 'a read-only token cannot change the shipped policy' '403' \ - "$(code -X PUT -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" -H 'Content-Type: application/json' \ + "$(admin_write -X PUT -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" -H 'Content-Type: application/json' \ -d '{"mode":"Off"}' "$EDGE/admin-api/policy")" check 'a read-only token cannot read the shipped export' '403' \ "$(code -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" "$EDGE/admin-api/export")" @@ -1690,13 +1715,13 @@ check 'and the refusal says the document is a capability' 'yes' \ "$(curl -s -m 10 -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" "$EDGE/admin-api/export" \ | grep -q 'capability' && echo yes || echo no)" check 'a read-only token cannot import a document' '403' \ - "$(code -X POST -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" -H 'Content-Type: application/json' \ + "$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" -H 'Content-Type: application/json' \ -d '{"version":1,"blocks":[]}' "$EDGE/admin-api/import")" check 'the admin token still writes on the shipped image' '204' \ - "$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ + "$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ -d '{"ip":"203.0.113.182","reason":"written by the admin token"}' "$EDGE/admin-api/blocks")" check 'and that row is removable again, so the volume stays clean' '200' \ - "$(code -X DELETE -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" \ + "$(admin_write -X DELETE -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" \ "$EDGE/admin-api/blocks?source=operator&key=203.0.113.182")" check 'an unknown token is still 401 on the shipped image' '401' \ "$(code -H "X-Admin-Token: not-a-token" "$EDGE/admin-api/state")" @@ -1772,7 +1797,7 @@ check 'an operator block lands a record naming the address' 'yes' \ check 'the record carries the operator sentence' 'yes' \ "$(printf '%s' "$CHANGES" | python3 -c "import sys,json;print('yes' if any('shipped image record' in (c.get('detail') or '') for c in json.load(sys.stdin)) else 'no')")" check 'it names the surface, never a person' 'operator' \ - "$(printf '%s' "$CHANGES" | python3 -c "import sys,json;print(next(c['actor'] for c in json.load(sys.stdin) if c['target']=='$CH_IP'))")" + "$(printf '%s' "$CHANGES" | python3 -c "import sys,json;print(next((c['actor'] for c in json.load(sys.stdin) if c['target']=='$CH_IP'), 'no-record'))")" check 'no record claims to come from the engine' '0' \ "$(admin "$EDGE/admin-api/changes" | python3 -c 'import sys,json;print(len([c for c in json.load(sys.stdin) if c["actor"]=="engine"]))')" check 'the read-only token can read the log' '200' \ @@ -1790,11 +1815,11 @@ check 'an import is recorded per section, not per row' 'yes' \ check 'and the import record says so' 'import' \ "$(admin "$EDGE/admin-api/changes?section=country" | python3 -c 'import sys,json;d=[c for c in json.load(sys.stdin) if c["action"]=="imported"];print(d[0]["actor"] if d else "none")')" check 'a removal is recorded as a removal' 'yes' \ - "$(code -X DELETE -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" \ + "$(admin_write -X DELETE -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" \ "$EDGE/admin-api/blocks?source=operator&key=$CH_IP" >/dev/null; \ admin "$EDGE/admin-api/changes?section=block" | python3 -c "import sys,json;print('yes' if any(c['target']=='$CH_IP' and c['action']=='removed' for c in json.load(sys.stdin)) else 'no')")" check 'the country rule the import wrote is removable, so the volume stays clean' '204' \ - "$(code -X DELETE -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" "$EDGE/admin-api/countries/fr")" + "$(admin_write -X DELETE -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" "$EDGE/admin-api/countries/fr")" echo '- an operator bans a range on the shipped image' # The same feature on the deployed image (OPEN-66): the operator's block control @@ -1809,21 +1834,21 @@ RANGE_OUTSIDE="203.0.113.$(( RANGE_BASE + 8 ))" # variable, not with escaped quotes inside a command substitution. RANGE_JSON="{\"ip\":\"$RANGE_NET\",\"reason\":\"shipped netblock\"}" check 'the shipped edge takes a CIDR as a block' '204' \ - "$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ + "$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ --data-binary "$RANGE_JSON" "$EDGE/admin-api/blocks")" check 'a source inside the range is refused on the wire' '301' \ "$(code -H "X-Forwarded-For: $RANGE_INSIDE" "$EDGE/anything")" check 'a source one address past its end is served' '404' \ "$(code -H "X-Forwarded-For: $RANGE_OUTSIDE" "$EDGE/anything")" check 'the shipped listing says which shape the row is' 'range' \ - "$(admin "$EDGE/admin-api/blocks" | python3 -c "import sys,json;print(next(c['kind'] for c in json.load(sys.stdin) if c['sourceKey']=='$RANGE_NET'))")" + "$(admin "$EDGE/admin-api/blocks" | python3 -c "import sys,json;print(next((c['kind'] for c in json.load(sys.stdin) if c['sourceKey']=='$RANGE_NET'), 'no-such-row'))")" check 'a range over every address is refused on the shipped image' '400' \ - "$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ + "$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ -d '{"ip":"0.0.0.0/0","reason":"shutdown"}' "$EDGE/admin-api/blocks")" check 'the shipped state counts ranges apart' 'yes' \ "$(admin "$EDGE/admin-api/state" | python3 -c "import sys,json;print('yes' if json.load(sys.stdin).get('operatorRanges') == 1 else 'no')")" check 'the range is removable by its name, so the volume stays clean' '404' \ - "$(code -X DELETE -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" \ + "$(admin_write -X DELETE -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" \ "$EDGE/admin-api/blocks?source=operator&key=$RANGE_NET" >/dev/null; \ code -H "X-Forwarded-For: $RANGE_INSIDE" "$EDGE/anything")" echo '- the shipped edge notices a netblock behind its bans' @@ -1857,7 +1882,7 @@ check 'the offer counts only the bans inside that block' '2' \ check 'an offer is not a ban: a fresh source inside it is served' '404' \ "$(code -H "X-Forwarded-For: $NET_FRESH" "$EDGE/anything")" check 'the shipped edge takes the offer with the block form' '204' \ - "$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ + "$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ --data-binary "$NET_RANGE_JSON" "$EDGE/admin-api/blocks")" check 'the taken range refuses a source the engine never saw' '301' \ "$(code -H "X-Forwarded-For: $NET_FRESH" "$EDGE/anything")" @@ -1883,7 +1908,7 @@ admin -X DELETE "$EDGE/admin-api/blocks?source=engine" >/dev/null admin -X PUT -H 'Content-Type: application/json' --data-binary "$PATH_BUDGET_ON_JSON" \ "$EDGE/admin-api/policy" >/dev/null check 'the shipped edge takes a path budget' '204' \ - "$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ + "$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ --data-binary "$PATH_BUDGET_JSON" "$EDGE/admin-api/rate-rules")" check 'the first two requests on that path are proxied' '404 404' \ "$(code -H "X-Forwarded-For: $PATH_BUDGET_IP" "$EDGE/budgeted") $(code -H "X-Forwarded-For: $PATH_BUDGET_IP" "$EDGE/budgeted")" @@ -1911,7 +1936,7 @@ DRY_RULE_JSON='{"pattern":"/dryrun*","limitPerWindow":2,"windowSeconds":120}' DRY_IP=198.51.100.92 admin -X PUT -H 'Content-Type: application/json' --data-binary "$DRY_ON_JSON" \ "$EDGE/admin-api/policy" >/dev/null -code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ +admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ --data-binary "$DRY_RULE_JSON" "$EDGE/admin-api/rate-rules" >/dev/null check 'the shipped preview answers the volume pillar for a source with nothing counted' 'yes' \ "$(admin "$EDGE/admin-api/decide?ip=$DRY_IP&path=/dryrun" | python3 -c 'import sys,json;v=json.load(sys.stdin)["volume"];print("yes" if v["verdict"]=="would_be_counted" and v["edgeBudget"] is None and v["pathBudgets"][0]["counted"] is False else "no")')" @@ -1940,9 +1965,9 @@ DOS_NET=198.51.100.144/29 # .144 - .151 DOS_INSIDE=198.51.100.147 DOS_OUTSIDE=198.51.100.152 check 'the shipped edge takes an address block and a range block' '204 204' \ - "$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ + "$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ --data-binary '{"ip":"'"$DOS_IP"'","reason":"dossier scene"}' "$EDGE/admin-api/blocks") \ -$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ +$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ --data-binary '{"ip":"'"$DOS_NET"'","reason":"dossier range"}' "$EDGE/admin-api/blocks")" check 'the shipped dossier answers on the key and names the row behind it' 'yes' \ "$(admin "$EDGE/admin-api/source?ip=$DOS_IP" | python3 -c 'import sys,json;d=json.load(sys.stdin);b=d["operatorBlock"];print("yes" if d["verdict"]=="block_operator" and d["sourceKey"]=="'"$DOS_IP"'" and b and not b["cameFromRange"] and b["live"] else "no")')" @@ -1972,7 +1997,7 @@ BUD_IP=198.51.100.161 BUD_IP2=198.51.100.162 admin -X PUT -H 'Content-Type: application/json' --data-binary "$DRY_ON_JSON" \ "$EDGE/admin-api/policy" >/dev/null -code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ +admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ --data-binary '{"pattern":"/budgeted*","limitPerWindow":2,"windowSeconds":300,"note":"who scene"}' \ "$EDGE/admin-api/rate-rules" >/dev/null BUD_RULE_ID="$(admin "$EDGE/admin-api/rate-rules" | python3 -c 'import sys,json;print([r["id"] for r in json.load(sys.stdin) if r["pattern"]=="/budgeted*"][0])')" @@ -1992,7 +2017,7 @@ check 'the let-out source is served again, the neighbour is still paused' '404 4 $(code -H "X-Forwarded-For: $BUD_IP2" "$EDGE/budgeted")" check 'the shipped read-only token reads the list and cannot clear it' '200 403' \ "$(code -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" "$EDGE/admin-api/rate-rules/$BUD_RULE_ID/sources") \ -$(code -X DELETE -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" \ +$(admin_write -X DELETE -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" \ "$EDGE/admin-api/rate-rules/$BUD_RULE_ID/sources?source=$BUD_IP2")" check 'the scene cleans itself' 0 \ "$(admin -X DELETE "$EDGE/admin-api/rate-rules/$BUD_RULE_ID" >/dev/null; \ @@ -2008,11 +2033,11 @@ HOR_IP=198.51.100.171 HOR_NET=198.51.100.176/29 # .176 - .183 HOR_INSIDE=198.51.100.179 check 'the shipped edge takes a block, a range and an allow that all expire today' '204 204 204' \ - "$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ + "$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ --data-binary '{"ip":"'"$HOR_IP"'","reason":"horizon block","expiresInMinutes":45}' "$EDGE/admin-api/blocks") \ -$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ +$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ --data-binary '{"ip":"'"$HOR_NET"'","reason":"horizon range","expiresInMinutes":20}' "$EDGE/admin-api/blocks") \ -$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ +$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ --data-binary '{"match":"'"$HOR_INSIDE"'","note":"horizon allow","expiresInMinutes":60}' "$EDGE/admin-api/allow")" check 'the shipped horizon lists them nearest first and says the range refuses once the allow ages out' yes \ "$(admin "$EDGE/admin-api/expiring?within=90" | python3 -c ' @@ -2053,11 +2078,11 @@ HIS_IP=198.51.100.187 HIS_NET=198.51.100.184/29 # .184 - .191 HIS_NONE=192.31.196.7 # outside every range this run writes check 'the shipped edge bans the network, the address inside it, then exempts it' '204 204 204' \ - "$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ + "$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ --data-binary '{"ip":"'"$HIS_NET"'","reason":"history netblock"}' "$EDGE/admin-api/blocks") \ -$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ +$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ --data-binary '{"ip":"'"$HIS_IP"'","reason":"history address"}' "$EDGE/admin-api/blocks") \ -$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ +$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ --data-binary '{"match":"'"$HIS_IP"'","note":"history allow","expiresInMinutes":60}' "$EDGE/admin-api/allow")" check 'the shipped story names the block, the covering range and the exemption, oldest first' yes \ "$(admin "$EDGE/admin-api/history?ip=$HIS_IP" | python3 -c ' @@ -2102,11 +2127,11 @@ FND_IP=198.51.100.195 FND_NET=198.51.100.192/29 # .192 - .199 findq() { admin "$EDGE/admin-api/find?q=$1${2:+&$2}"; } check 'the shipped edge writes the same phrase into three stores' '204 204 204' \ - "$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ + "$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ --data-binary '{"ip":"'"$FND_IP"'","reason":"ticket 441 closed"}' "$EDGE/admin-api/blocks") \ -$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ +$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ --data-binary '{"match":"'"$FND_NET"'","note":"ticket 441 window"}' "$EDGE/admin-api/allow") \ -$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ +$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ --data-binary '{"pattern":"/find-gate*","action":"block","note":"ticket 441 path"}' "$EDGE/admin-api/rules")" check 'the shipped query comes back from every store that holds it' '1 1 1' \ "$(findq 'ticket%20441' | python3 -c ' @@ -2114,7 +2139,7 @@ import sys,json c=json.load(sys.stdin)["counts"] print(c["block"], c["allow"], c["pathRule"])')" check 'the shipped search treats "100%" as text, not as LIKE grammar' yes \ - "$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ + "$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ --data-binary '{"ip":"198.51.100.196","reason":"100% sure"}' "$EDGE/admin-api/blocks" >/dev/null; \ findq '100%25' | python3 -c ' import sys,json @@ -2193,7 +2218,7 @@ check 'the shipped preview refuses a /0 in the writes words' yes \ admin "$EDGE/admin-api/impact?match=198.51.100.0/0" \ | python3 -c 'import json,sys;print("yes" if "shutdown, not a ban" in json.load(sys.stdin)["error"] else "no")')" check 'the shipped preview says an exemption over the whole match makes the ban refuse nobody' yes \ - "$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ + "$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \ --data-binary '{"match":"'"$IMP_NET"'","note":"the block is exempt"}' "$EDGE/admin-api/allow" >/dev/null; \ impactq "$IMP_NET_Q" | python3 -c ' import json,sys @@ -2204,7 +2229,7 @@ print("yes" if d["changesNothing"] and not d["wouldRefuse"] and out==["198.51.10 check 'the shipped preview is a read: the wire still answers the upstream' 404 \ "$(code -H "X-Forwarded-For: $IMP_A" "$EDGE/imp-c")" check 'the scene cleans itself' 0 \ - "$(code -X DELETE -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" \ + "$(admin_write -X DELETE -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" \ "$EDGE/admin-api/allow/$(admin "$EDGE/admin-api/allow?live=false" \ | python3 -c 'import sys,json;print(next((a["id"] for a in json.load(sys.stdin) if a["match"]=="'"$IMP_NET"'"), 0))')" >/dev/null; \ admin "$EDGE/admin-api/allow?live=false" \ @@ -2319,7 +2344,19 @@ check 'and the list-field read says the same thing in the other helper' 'NO_JSON check 'a comparison on a value that was never read answers no' 'no' "$DEAD_CMP" check 'and none of those reads or comparisons wrote a line to stderr' '0' \ "$(wc -l < "$DEAD_READS" | tr -d ' ')" -rm -f "$DEAD_READS" +# A write aimed at that same stopped edge, so the retry rule above is a measured +# behaviour and not a comment: three retries, said out loud, and the answer the +# scene gets is still the honest 000 rather than a code that would let the rest +# of a scene read as if its seed had landed. +DEAD_WRITE_ERR=$(mktemp "${TMPDIR:-/tmp}/openwaf-dead-write.XXXXXX") +DEAD_WRITE=$(admin_write -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" \ + -H 'Content-Type: application/json' \ + -d '{"ip":"203.0.113.253","reason":"a write that cannot land"}' \ + "$EDGE/admin-api/blocks" 2>"$DEAD_WRITE_ERR") +check 'a write aimed at a dead edge is retried and still answers nothing' '000' "$DEAD_WRITE" +check 'and the retries are said out loud, three of them' '3' \ + "$(grep -c 'the write reached nothing' "$DEAD_WRITE_ERR")" +rm -f "$DEAD_WRITE_ERR" docker compose start edge >/dev/null 2>&1 ALIVE_STATE='none' for _ in $(seq 1 90); do