Files
openwaf/scripts/console-smoke.sh
T
Pavlo Ratushnyi e02e442ae2 The console gate has a Linux number now, in a real Chromium
The rehearsal covered the dotnet suites, smoke.sh and compose-smoke.sh, and
then printed "console gate: not covered here (needs a real Chromium)". That was
the one honest line in the summary, and it was also the last hole: the console
job in `.github/workflows/ci.yml` runs on ubuntu-latest, so its gate was
verified only on darwin.

`scripts/ci-linux-rehearsal.sh console` closes it. `scripts/console-smoke.sh`
grew `SEED_ONLY=1` (start the stack, seed the streaks/bans/allow entries the
page must show, then stop before driving the page) and an `EDGE` override, so
the seeding half runs in `docker:cli` against the host daemon and the browser
half runs in `mcr.microsoft.com/playwright:v1.63.0-noble` — the Playwright
version pinned there is the version the CI console job pins, or the rehearsal
is rehearsing something else. The stack is torn down either way.

Two facts about that image, both now comments in the script:

- It ships the browsers (`/ms-playwright`: chromium-1243) but **not** the npm
  package — there is no playwright-core anywhere in it. So the stage installs
  `playwright@1.63.0` into `/tmp` and points `PLAYWRIGHT_CORE` at
  `/tmp/node_modules/playwright-core`.
- The repo is mounted read-only for this stage. Writable, the install would
  have dropped `node_modules` into the working tree of the checkout.

The summary line also stopped lying by accident: `verdict()` now separates a
stage the caller never asked for ("not run") from a stage that could not run
("skipped (no docker socket)"), and the exit code includes the console stage.

Two full rehearsals on this tree, one invocation each, both EXIT=0:

    source gates (restore/build/unit/integration/smoke): PASS   54/54, 28/28, 19/19
    compose gate: PASS                                          27 passed, 0 failed
    console gate: PASS                                          26 assertions, 0 failed
    wall: 2:14.33 (cold containers, cold NuGet cache)

72 assertions pass from inside Linux, and the console half includes the
round-trip a page cannot fake: a ban drawn on the page answers 301 on the next
request from that address, and the address passes again once the row is
deleted. actionlint 1.7.12 (same pinned checksum as CI): 0 problems. shellcheck
and `bash -n` clean.

Still true: none of this has executed on a runner, because the repository has
no remote. The Linux numbers narrow what a first run can discover; they do not
replace one.
2026-10-01 15:50:51 +02:00

82 lines
4.0 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
# SEED_ONLY=1 … same, but leave the seeded stack for something else to drive
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=${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
# SEED_ONLY=1 stops after the seed and leaves the stack running: the page is not
# driven from here. That is what scripts/ci-linux-rehearsal.sh uses to drive it
# from a container that has a real Chromium, and it is also what you want when
# debugging the page by hand against a stack that already has something to show.
if [ "${SEED_ONLY:-0}" = 1 ]; then
echo '- SEED_ONLY=1: stack is up and seeded at '"$EDGE"'; the page is not driven from here'
trap - EXIT
exit 0
fi
echo '- driving the page'
node scripts/console-check.cjs