The page could clear engine bans and switch the mode. During an incident the two
things an operator actually reaches for are: put one address behind a block with
a reason, and pull one customer range back out from under the bans. Both
endpoints already existed (`POST /admin-api/blocks`, `POST /admin-api/allow`,
`DELETE /admin-api/blocks?key=`, `DELETE /admin-api/allow/{id}`,
`PUT /admin-api/countries/{code}?allowed=`); the page just did not expose them.
Now it does: a block form, an allow form with an optional expiry, a delete on
every ban row, a remove on every allow row, and a rule toggle on every country
row. Row buttons carry their key in a data attribute and one delegated handler
reads it, so nothing is spliced into an inline onclick string. Still no decision
logic on the page — every control is exactly one call.
The gate now checks the write on the wire, not just in the table, and that is
where the two findings were:
- An operator block answers **301 with the policy's redirect Location**
(`OperatorBlockStatus=301`, `DefaultRedirectTargets=[iana example]`), not 403.
A `fetch` that follows redirects walks out to the public internet and comes
back **200** — which is how the new assertion first reported "the ban drawn on
the page is not enforced" while the edge had been refusing that client with a
301 from the start. The probe uses `redirect: 'manual'` now. The same trap
would catch anyone writing a smoke check against this edge, so it is a comment
in the gate and a sentence in the README.
- The baseline probe in my own gate ran *after* the block was written, so it
asserted "reaches the upstream" about an address that was already blocked.
Caught because the numbers disagreed with each other, not because I re-read
the code.
Sequence the gate now proves end to end: address answers 404 → page writes a ban
→ same address answers 301 with a Location → per-row delete removes that one row
→ address answers 404 again; an allow entry appears with an expiry and can be
removed; a country rule is set to denied and put back. There is no DELETE for a
country rule, so "put back" is `PUT ?allowed=true` and the row stays behind
meaning "not denied" — documented rather than papered over. `console-smoke.sh`
now also clears allow entries on teardown, so a run that dies halfway cannot
leave an allowlist behind in the data volume and quietly change the next run.
The fast suite notices the controls too: one integration test asserts the write
controls are in the served page, so their removal fails in seconds rather than
waiting for the browser gate.
Gates on this commit: build 0 warnings / 0 errors, unit 54/54, integration
**28/28**, smoke 19/19, image 261 MB, compose-smoke 27/27, console **24/24**
(wire sequence above, phone pass at 375 px dark: scrollWidth 375, contrast
11.85:1, bars 67 px), actionlint 0, shellcheck 0. Unchanged and said plainly:
no job has ever run on a runner — the repository has no remote.
71 lines
3.5 KiB
Bash
Executable File
71 lines
3.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# The console gate: start the stack, seed the two things the page has to show
|
|
# (a source sitting at 2 of a threshold of 3, and an operator block with a
|
|
# reason), drive the page in a real Chromium, tear the stack down.
|
|
#
|
|
# Needs docker and playwright-core. Set PLAYWRIGHT_CORE=/path/to/playwright-core
|
|
# if it is not installed locally. The script does not skip when playwright is
|
|
# missing — it exits non-zero, because a gate that reports success having
|
|
# asserted nothing is worse than no gate.
|
|
#
|
|
# OPENWAF_ADMIN_TOKEN=… SCREENSHOT=/tmp/console.png ./scripts/console-smoke.sh
|
|
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
|
|
export OPENWAF_ADMIN_TOKEN="${OPENWAF_ADMIN_TOKEN:?set OPENWAF_ADMIN_TOKEN before running, or run scripts/ci-gates.sh (it defaults a throwaway for the stack it starts itself)}"
|
|
EDGE=http://127.0.0.1:8080
|
|
SEED_SOURCE=203.0.113.55
|
|
SEED_BLOCK=203.0.113.77
|
|
export EDGE_URL="$EDGE" SEED_SOURCE SEED_BLOCK
|
|
|
|
admin() { curl -s -m 10 -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" "$@"; }
|
|
|
|
cleanup() {
|
|
admin -X PUT -H 'Content-Type: application/json' \
|
|
-d '{"mode":"Enforce","geo":"Off","streakThreshold":10,"trustProxyHeaders":false}' "$EDGE/admin-api/policy" >/dev/null 2>&1
|
|
admin -X DELETE "$EDGE/admin-api/blocks?source=operator" >/dev/null 2>&1
|
|
# The page can write allow entries. The gate removes the one it added, but if
|
|
# it failed before that step the entry would outlive the run inside the data
|
|
# volume and quietly change the next run — so clear them here too.
|
|
for id in $(admin "$EDGE/admin-api/allow" | tr ',' '\n' | sed -n 's/.*"id":\([0-9]*\).*/\1/p'); do
|
|
admin -X DELETE "$EDGE/admin-api/allow/$id" >/dev/null 2>&1
|
|
done
|
|
# A country rule set by the gate cannot be deleted, only overwritten: the API
|
|
# has PUT /countries/{code}?allowed= and no DELETE. The gate puts US back to
|
|
# allowed=true, so the residue is a row that means "not denied", not a policy
|
|
# change — but it is residue, and the row outlives `compose down` because it
|
|
# lives in the data volume.
|
|
[ "${KEEP_UP:-0}" = 1 ] || docker compose down >/dev/null 2>&1
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
echo '- starting the stack'
|
|
docker compose up -d --build >/dev/null 2>&1 || { echo 'compose up failed'; exit 1; }
|
|
for _ in $(seq 1 120); do
|
|
[ "$(docker compose ps -q edge | xargs docker inspect --format '{{.State.Health.Status}}')" = healthy ] && break
|
|
sleep 0.5
|
|
done
|
|
|
|
# Threshold 3 and trusted proxy headers, so two refusals from one address show
|
|
# as "2 / 3" without tripping the ban. The policy lives in the shared database
|
|
# and reaches the guard on the next snapshot refresh — hence the wait, which is
|
|
# the same TTL the multi-instance measurement is about.
|
|
admin -X PUT -H 'Content-Type: application/json' \
|
|
-d '{"mode":"Enforce","geo":"Off","streakThreshold":3,"trustProxyHeaders":true}' "$EDGE/admin-api/policy" >/dev/null
|
|
sleep 31
|
|
|
|
echo '- seeding what the page must show'
|
|
for _ in 1 2; do curl -s -o /dev/null -H "X-Forwarded-For: $SEED_SOURCE" "$EDGE/probe"; done
|
|
curl -s -o /dev/null -H 'X-Forwarded-For: 8.8.8.8' "$EDGE/no-such-page"
|
|
admin -X POST -H 'Content-Type: application/json' \
|
|
-d "{\"ip\":\"$SEED_BLOCK\",\"reason\":\"console gate: operator block\"}" "$EDGE/admin-api/blocks" >/dev/null
|
|
|
|
# Durable observations are written by a background loop (flush every 15 s, at
|
|
# most once per source per 30 s), so the observations table needs the same wait
|
|
# the policy write needed. Without it the page is correct and the gate is wrong.
|
|
sleep 35
|
|
|
|
echo '- driving the page'
|
|
node scripts/console-check.cjs
|