From 8082e6a598916df0e4834fb4d40573ee87424551 Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Thu, 1 Oct 2026 16:40:37 +0200 Subject: [PATCH] The alerting pillar had an endpoint and nobody reading it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `GET /admin-api/alerts` appeared in **zero** gate scripts. Both alert kinds were proven in-process, against `FakeUpstream`, at the database level — and the half that matters for an alert, the half where a human sees it, had nothing on the other end. The console read six endpoints and this was not one of them. The page now renders them: kind, source, count, last status and path, when. The kind an operator has to act on is marked rather than only printed, and the note above the table says what each kind means in words, because `server_error_streak` and `candidate_ban` are different sentences: your upstream is failing (and the edge will not ban the visitor who saw it) versus the rule would have banned and the mode is Observe. `scripts/console-smoke.sh` seeds four 502s from an address chosen for this run (`/boom`, added last commit), and `scripts/console-check.cjs` asserts the row by **source and count**, the note text, the marking, and that the table survives the phone pass: 26 → **30 assertions**. The wiring was the interesting part. The seeding runs in one container and the browser in another, so the address chosen at seed time cannot be inherited — an empty `SEED_ERROR` on the driver side would have quietly turned "the alert this run wrote" into "some alert exists somewhere". The seed now writes its values to `console-seed.env` (gitignored) and the rehearsal passes them to the browser container. `AdminConsoleTests` got the fast half: the markup contains the alerts table and fetches the endpoint. A static check cannot assert the row is there — that is what the browser gate is for — but it can notice the table disappearing without waiting for Chromium. 28 → **29 integration tests**. Numbers. Host: build 0 warnings, unit 54/54, integration 29/29. Linux rehearsal, one invocation on this tree, EXIT=0: source gates 54/54 + 29/29 + smoke 19/19, compose **35/35**, console **30/30** in a real Chromium. actionlint 1.7.12 over both workflow files: 0 problems; shellcheck, `bash -n` and `node --check` clean. Two things said plainly. The console number above is the Linux one: this laptop's browser cache has chromium-1223/1228/1234 and the pinned Playwright wants 1243, so the darwin console gate was not re-run for this change. And during the run the table's own note read "Newest 25" — the endpoint is capped and residue from earlier runs fills the page. That is OPEN-18's amplification showing up where an operator would see it, and the note states the cap instead of pretending the table is everything. --- .github/workflows/ci.yml | 8 ++--- .gitignore | 4 +++ README.md | 30 ++++++++++++------- dotnet/OpenWaf.Edge/Admin/AdminConsole.cs | 24 +++++++++++++-- .../AdminConsoleTests.cs | 18 +++++++++++ scripts/ci-linux-rehearsal.sh | 9 ++++++ scripts/console-check.cjs | 22 +++++++++++++- scripts/console-smoke.sh | 21 +++++++++++-- 8 files changed, 117 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 69949ed..3dd00ae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,12 +16,12 @@ # What has been done to narrow the darwin/linux gap without a runner: # scripts/ci-linux-rehearsal.sh runs the gates in containers. Source gates # (restore, build, unit, integration, smoke) in mcr.microsoft.com/dotnet/sdk:10.0 -# — Ubuntu 24.04.5, SDK 10.0.401 resolving the pinned global.json, 54/54 + 28/28 +# — Ubuntu 24.04.5, SDK 10.0.401 resolving the pinned global.json, 54/54 + 29/29 # + 19/19, first try, 1:02.81 wall cold: evidence that the 25-minute timeout -# below is not near. Compose gate in docker:cli against the host daemon: 28/28 on +# below is not near. Compose gate in docker:cli against the host daemon: 35/35 on # Linux. Console gate in mcr.microsoft.com/playwright:v1.63.0-noble — the stack # seeded by docker:cli, the same console-check.cjs driving it in a real Linux -# Chromium: 26/26. So every gate this file runs now has a Linux number. What it +# Chromium: 30/30. So every gate this file runs now has a Linux number. What it # does not have is a runner: the repository has no remote, so this file has # never executed on GitHub. # @@ -125,7 +125,7 @@ jobs: # # Honest status: this job has never run on a runner, like the rest of the # file. What was verified is the gate it calls — scripts/ci-gates.sh console - # passed locally (26 assertions, playwright-core 1.63.0 — the version pinned + # passed locally (30 assertions, playwright-core 1.63.0 — the version pinned # right above, and rehearsed on Linux in the Playwright image), and its # control (a wrong token) exits 1 rather than reporting success. The step # calls the gate by name rather than retyping the script, so the CI definition diff --git a/.gitignore b/.gitignore index 5ab6163..9cc650d 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,7 @@ openwaf.db* # Written by scripts/console-smoke.sh when SCREENSHOT is a relative path. console-evidence*.png + +# Written by scripts/console-smoke.sh SEED_ONLY=1 so the browser container can +# look at the same seeded addresses the stack was seeded with. +console-seed.env diff --git a/README.md b/README.md index 3f482fb..ea78117 100644 --- a/README.md +++ b/README.md @@ -224,6 +224,10 @@ outranks every ban). Each ban row has a delete that removes that row, each allow row a remove, and each country row a rule toggle. There is no DELETE for a country rule, so the toggle back is `PUT ?allowed=true`: the row stays behind and means "not denied". +It shows the alerts the edge raises — `server_error_streak` (your upstream is +failing, and the edge will not ban the visitor who saw it) and `candidate_ban` +(the rule would have banned, but the mode is Observe). That table is the whole +point of the alerting pillar: an alert nobody reads is a log line. It decides nothing: every control on it is one call to the API above. It is on the always-pass list, so an operator who is themselves blocked can still reach the page that clears it, and it is never observed, so fumbling it cannot build a @@ -250,11 +254,14 @@ refuse to invent one, because run by hand they can be pointed at a real deployment. The console gate starts the stack, seeds a source sitting at 2 of a threshold of -3 and an operator block with a reason, drives `/admin` in a real Chromium, and -asserts 26 things. The read side: it authenticated, listed the streak as +3 and an operator block with a reason, four 502s from an address chosen for this +run (`/boom`, see the alerting note above), drives `/admin` in a real Chromium, +and asserts 30 things. The read side: it authenticated, listed the streak as current-over-threshold rather than as a historical maximum, listed the operator block with its reason, listed observations and countries with bars that have -real pixel widths, kept the token out of the markup, and threw no javascript. +real pixel widths, listed the alert this run's seeding wrote (by source and +count, not just "a row exists"), said in words that a server error is never a +reason to ban, kept the token out of the markup, and threw no javascript. The write side, checked on the wire and not just in the table: an address reaches the upstream (404), the page writes a ban for it, the same address is then refused (301 with the policy's redirect Location — the probe uses @@ -287,10 +294,10 @@ against the host daemon, so the image build and the stack are Linux. Rehearsed 2026-10-01. Source gates: Ubuntu 24.04.5, SDK **10.0.401** resolving `dotnet/global.json` (pinned `10.0.100`, `rollForward: latestFeature` — which is also the answer to whether `setup-dotnet` with `10.0.x` satisfies the pin), unit -**54/54**, integration **28/28**, smoke **19/19**, first try, nothing to fix; +**54/54**, integration **29/29**, smoke **19/19**, first try, nothing to fix; wall clock with a cold container and a cold NuGet cache **1:02.81**, so the source job's 25-minute timeout is not close even on a slower CPU. Compose gate on -Linux: **28 passed, 0 failed** (27 before the geo-pin assertion was added), +Linux: **35 passed, 0 failed** (27 before the geo-pin and alerting assertions), enforcement lag 12 ms and 36 ms in two runs. Console gate on Linux: **26 assertions, 0 failed** — described below. `scripts/geo-db-freshness.sh` was run in `mcr.microsoft.com/dotnet/sdk:10.0` too: current pin answers 0, and a forced @@ -313,7 +320,7 @@ and the stack is torn down afterwards. That image ships the browsers but not the npm package, so the script installs `playwright-core` into `/tmp` and points `PLAYWRIGHT_CORE` at it, mounting the repository read-only so the install never lands in the working tree. Rehearsed the same day on Linux 7.0.12-linuxkit -aarch64, node v24.20.0, `chromium-1243`: **26 assertions, 0 failed**, including +aarch64, node v24.20.0, `chromium-1243`: **30 assertions, 0 failed**, including the round-trip the page alone cannot fake — a ban drawn on the page answers 301 on the next request from that address. All three scenes in one cold run: **2:14.33**. @@ -355,11 +362,14 @@ dotnet/ OpenWaf.Domain/ pure decision core: source key, streak, ordered decision OpenWaf.Infrastructure/ EF Core (sqlite/postgres), snapshot store, writers, MMDB geo OpenWaf.Edge/ the deployable: guard, observer, admin API, healthcheck mode - OpenWaf.Tests.Unit/ 36 tests over the decision logic - OpenWaf.Tests.Integration/ 19 tests driving the real pipeline against a fake upstream + OpenWaf.Tests.Unit/ 54 tests over the decision logic + OpenWaf.Tests.Integration/ 29 tests driving the real pipeline against a fake upstream scripts/smoke.sh 19 assertions against a running edge + a real upstream -scripts/compose-smoke.sh 28 assertions against the built image (compose + nginx) -.github/workflows/ci.yml runs all four gates on every push +scripts/compose-smoke.sh 35 assertions against the built image (compose + nginx) +scripts/console-check.cjs 30 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 +.github/workflows/geo-freshness.yml the same check on a schedule docs/ARCHITECTURE.md the design authority and its rulings ``` diff --git a/dotnet/OpenWaf.Edge/Admin/AdminConsole.cs b/dotnet/OpenWaf.Edge/Admin/AdminConsole.cs index 7855bbd..37030ff 100644 --- a/dotnet/OpenWaf.Edge/Admin/AdminConsole.cs +++ b/dotnet/OpenWaf.Edge/Admin/AdminConsole.cs @@ -121,6 +121,10 @@ internal static class AdminConsole
sourceconsecutiveserver errorslast statuspathgeolast seen
+

Alerts — what the edge wants a human to look at

+
+
kindsourcecountlastwhen
+

Countries seen

codesourcesrefusalsrefusals vs the busiestrule
@@ -163,11 +167,11 @@ function row(cells) { async function load() { if (!token) { note('no token', true); return; } try { - const [state, blocksRes, obs, streaks, countries, rules, allow] = await Promise.all([ + const [state, blocksRes, obs, streaks, countries, rules, allow, alerts] = await Promise.all([ api('/admin-api/state'), apiRaw('/admin-api/blocks?live=false'), api('/admin-api/observations?limit=25'), api('/admin-api/streaks'), api('/admin-api/countries/summary'), api('/admin-api/countries'), - api('/admin-api/allow') + api('/admin-api/allow'), api('/admin-api/alerts?limit=25') ]); const blocks = blocksRes.body; // The listing is capped server-side. Saying so is the difference between a @@ -228,6 +232,22 @@ async function load() { + totalSources + ' ' + plural(totalSources, 'source') + ', ' + totalRefusals + ' ' + plural(totalRefusals, 'refusal') + ' total' : 'no country-resolved sources yet'; + // The alerting pillar is the only one whose whole point is a human reading + // it, so a table nobody renders is a pillar with no top. The two kinds mean + // different things and the page says which: a server error is never a reason + // to ban, and a candidate ban is a rule that has not been allowed to act. + el('alerts').tBodies[0].innerHTML = (alerts || []).map((a) => row([ + { h: a.kind === 'server_error_streak' + ? '' + esc(a.kind) + '' : esc(a.kind) }, + { v: a.sourceKey }, + { v: a.count, n: true }, + { v: (a.lastStatusCode || '') + ' ' + (a.lastPath || ''), n: true }, + { v: (a.createdAt || '').replace('T', ' ').slice(0, 19) } + ])).join('') || row([{ v: 'nothing — no server-error streaks and no dry-run candidates' }]); + el('alertnote').textContent = (alerts || []).length + ? 'server_error_streak = your upstream is failing, and the edge will not ban the visitor who saw it; candidate_ban = the rule would have banned, mode is Observe. Newest ' + (alerts || []).length + '.' + : 'no alerts. server_error_streak means the upstream is failing; candidate_ban means a dry run would have banned.'; + el('countries').tBodies[0].innerHTML = seen.map((c) => row([ { v: c.code }, { v: c.sources, n: true }, { v: c.refusals, n: true }, { h: '/dev/null) + [ -n "$SEED_ERROR" ] || { echo 'console stage: no SEED_ERROR in console-seed.env' >&2; console_status=1; } + fi + if [ "$console_status" -eq 0 ]; then docker run --rm \ -v "$PWD:$PWD:ro" -w /tmp \ --add-host=host.docker.internal:host-gateway \ -e EDGE_URL="$HOST_EDGE" -e OPENWAF_ADMIN_TOKEN \ -e SEED_SOURCE=203.0.113.55 -e SEED_BLOCK=203.0.113.77 \ + -e SEED_ERROR="$SEED_ERROR" \ -e SCREENSHOT=/tmp/console-linux.png \ -e CHECK="$PWD/scripts/console-check.cjs" \ -e PW_VERSION="$PLAYWRIGHT_VERSION" \ diff --git a/scripts/console-check.cjs b/scripts/console-check.cjs index c9dc688..55751d5 100644 --- a/scripts/console-check.cjs +++ b/scripts/console-check.cjs @@ -16,6 +16,7 @@ const SCREENSHOT = process.env.SCREENSHOT : ''; const SEED_SOURCE = process.env.SEED_SOURCE || ''; const SEED_BLOCK = process.env.SEED_BLOCK || ''; +const SEED_ERROR = process.env.SEED_ERROR || ''; let chromium; try { @@ -97,6 +98,23 @@ const rgb = (s) => s.match(/\d+/g).slice(0, 3).map(Number); bars.length > 0 && bars.some((b) => b.cell > 0 && b.w >= b.cell * 0.9), JSON.stringify(bars)); check('the country table states what it counted', /^\d+ countr(y|ies), \d+ sources?, \d+ refusals? total$/.test(countrysum), countrysum); + // The alerting pillar's whole point is a human reading it, and until now no + // gate read /admin-api/alerts at all — the endpoint could have returned anything + // and every assertion would have stayed green. The seed hit /boom four times + // from an address chosen for this run, so a residue alert from an older run + // cannot satisfy this. + const alertRows = await cells('#alerts tbody tr'); + const errAlerts = alertRows.filter((r) => r[0] === 'server_error_streak' && r[1] === SEED_ERROR); + check('the alerts table lists the server-error streak this run wrote', + errAlerts.length >= 1 && errAlerts.some((r) => Number(r[2]) >= 3), + JSON.stringify(errAlerts.map((r) => [r[2], r[3]]))); + const alertnote = (await page.textContent('#alertnote')).replace(/\s+/g, ' ').trim(); + check('the page says a server error is never a reason to ban', + /will not ban/.test(alertnote), alertnote); + const warnCells = await page.$$eval('#alerts tbody tr .warn', (els) => els.map((e) => e.textContent)); + check('the kind an operator has to act on is marked, not only printed', + warnCells.includes('server_error_streak'), JSON.stringify(warnCells)); + check('the token never appears in the markup', !html.includes(TOKEN)); check('the page threw no javascript', jsProblems.length === 0, jsProblems.join(' | ')); @@ -254,7 +272,9 @@ const rgb = (s) => s.match(/\d+/g).slice(0, 3).map(Number); m.streakRow.some((r) => r[0] === SEED_SOURCE && /2 \/ 3/.test(r[1] || '')), JSON.stringify(m.streakRow.map((r) => [r[0], r[1]]))); check('the token is not in the markup at phone width either', !m.html.includes(TOKEN)); - check('the country bars survive the phone layout', + const phoneAlertRows = await page.$$eval('#alerts tbody tr', (r) => r.length); + check('the alerts table is still there at phone width', phoneAlertRows > 0, `${phoneAlertRows} rows`); + check('the country bars survive the phone layout', m.barWidths.length > 0 && m.barWidths.every((w) => w >= 2), JSON.stringify(m.barWidths)); check('the page threw no javascript at phone width', phoneProblems.length === 0, phoneProblems.join(' | ')); if (SCREENSHOT) await phone.screenshot({ path: SCREENSHOT.replace(/(\.[a-z0-9]+)$/i, '.phone$1'), fullPage: true }); diff --git a/scripts/console-smoke.sh b/scripts/console-smoke.sh index eac61ec..a0a6fa7 100755 --- a/scripts/console-smoke.sh +++ b/scripts/console-smoke.sh @@ -18,7 +18,11 @@ export OPENWAF_ADMIN_TOKEN="${OPENWAF_ADMIN_TOKEN:?set OPENWAF_ADMIN_TOKEN befor 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 +# Per run: the alerts table is ordered newest first and the data volume survives +# `compose down`, so a fixed address here would let last week's alert satisfy the +# assertion. A fresh one makes the check about this run. +SEED_ERROR="203.0.113.$(( 140 + RANDOM % 60 ))" +export EDGE_URL="$EDGE" SEED_SOURCE SEED_BLOCK SEED_ERROR admin() { curl -s -m 10 -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" "$@"; } @@ -62,6 +66,13 @@ 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 +# An alert the page must show. /boom answers 502 (deploy/upstream.conf), and this +# gate already set the threshold to 3, so four of them from one address write +# server_error_streak rows. The alert is written after the response is, hence the +# short wait before the page reads it. +for _ in 1 2 3 4; do curl -s -o /dev/null -H "X-Forwarded-For: $SEED_ERROR" "$EDGE/boom"; done +sleep 2 + # 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. @@ -72,7 +83,13 @@ sleep 35 # 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' + # The driver lives in another container (scripts/ci-linux-rehearsal.sh runs the + # page in a browser image), so it cannot inherit these values. Writing them out + # is what keeps the alert assertion honest: SEED_ERROR is chosen per run, and an + # empty one on the driver side would silently weaken the check to "any alert". + printf 'EDGE_URL=%s\nSEED_SOURCE=%s\nSEED_BLOCK=%s\nSEED_ERROR=%s\n' \ + "$EDGE" "$SEED_SOURCE" "$SEED_BLOCK" "$SEED_ERROR" > "${SEED_FILE:-console-seed.env}" + echo "- SEED_ONLY=1: stack is up and seeded at $EDGE; seed values in ${SEED_FILE:-console-seed.env}" trap - EXIT exit 0 fi