diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af00336..2bc3efa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -409,12 +409,28 @@ jobs: EDGE: http://${{ env.OPENWAF_EDGE_HOST }}:8090 run: ./scripts/ci-gates.sh console - # always(): the failure case is the one worth looking at. - - name: Publish the console screenshots + # Not an artifact upload, and that is a measurement rather than a + # preference. Run 2370 (head 36d9338) drove the page through every + # assertion — `console check: all assertions passed` — and the job still + # went red one step later: `actions/upload-artifact@v4` reports + # `@actions/artifact v2.0.0+, upload-artifact@v4+ and download-artifact@v4+ + # are not currently supported on GHES`, which is what Gitea's runner looks + # like to that action. The other pipeline on this instance says the same + # thing about the same instance: "actions/upload-artifact is not mirrored on + # git.vezha.io" (tskr, .gitea/workflows/ci.yml). So the evidence this job + # owes is in the log: the gate already prints every assertion with the value + # it read, and the step below names each screenshot with its size and hash + # so a reader can tell which picture the log describes. + - name: Report the console screenshots if: always() - uses: actions/upload-artifact@v4 - with: - name: console-evidence - path: console-evidence*.png - if-no-files-found: warn - retention-days: 14 + run: | + set -eu + seen=0 + for f in console-evidence.png console-evidence.phone.png; do + if [ -f "$f" ]; then + seen=1 + printf 'screenshot %s - %s bytes - sha256 %s\n' \ + "$f" "$(wc -c < "$f" | tr -d ' ')" "$(sha256sum "$f" | cut -d' ' -f1)" + fi + done + [ "$seen" -eq 1 ] || echo "no screenshot was written: the gate never reached the page" diff --git a/README.md b/README.md index 70a0235..4fafb2e 100644 --- a/README.md +++ b/README.md @@ -1485,6 +1485,70 @@ default and 500 at most, and an unknown query parameter is refused by name. It i a read: the read-only token can ask it, and eight asks leave every store holding the same rows. +### What would this ban touch? + +`GET /admin-api/impact?match=&path=&limit=` answers the +question that stops being askable the moment the write lands. Both failures it +prevents are silent: a `/24` written over an office block refuses people who were +never the target, and a range written inside an existing exemption refuses nobody +at all — the operator sees 204 and moves on. + +``` +GET /admin-api/impact?match=203.0.113.64/29 +{ "match": "203.0.113.64/29", "kind": "range", "filedUnder": "203.0.113.64/29", + "path": "/", "asOf": "…", "scope": "snapshot+database", + "probed": 3, "limit": 50, "truncated": false, + "counts": { "newlyRefused": 2, "alreadyRefused": 1, "stillPassing": 0 }, + "wouldRefuse": true, "changesNothing": false, + "alreadyCoveredBy": null, "outrankedBy": [], "exemptionsInside": [], + "sources": [ + { "source": "203.0.113.66", "kind": "standing streak", "lastSeenAt": "…", + "refusals": 12, "worstRun": 12, "before": "pass", "beforeBy": null, + "after": "block_operator", "afterBy": "203.0.113.64/29", + "change": "newly refused" } ], + "note": "…", "wrote": false } +``` + +**It is the engine, not a second implementation of it.** The answer is +`DecisionEngine.Decide` run over the live snapshot with the proposed entry added, +over the sources this edge is actually watching inside the match — every recorded +observation and every standing streak whose key falls in it, plus the match's own +address, because "nothing has been seen inside this range" and "the preview did +not look" are different answers. This is the same choice the dry run and the +horizon already make, for the same reason: a preview that disagrees with the wire +is worse than no preview, so there is no second copy of the pillar order here to +drift out of date. + +**The two ways a ban can do nothing are named, not inferred.** `alreadyCoveredBy` +is what already answers for the match's own address: a live `/28` makes the `/29` +about to be written decoration, and the row says so — `block_operator by +203.0.113.32/28`. `outrankedBy` is the exemption that covers that address: the +ban sits behind the allow pillar in the pillar order, so it never speaks there, +and the operator has to see that before the 204 rather than after the complaint. +`exemptionsInside` lists the exemptions covering *other* addresses inside the +match. All three arrive beside `changesNothing`, which is the sentence a 204 +would otherwise hide. + +**The match is normalised by the write path's own code.** `203.0.113.37/29` and +`203.0.113.32/29` are one row, so the preview answers about the row the write +would create and refuses a match the write would refuse, in the write's words — +including `198.51.100.0/0`, which is refused as a shutdown rather than a ban. +`filedUnder` is the key the write would file it under, which for a bare address is +this edge's group for it: with a `/29` key, banning one address reaches the whole +group, and a preview that answered about one address would be a preview of +nothing. + +`path` defaults to `/`, and the pillar order answers per path — a preview of `/` +says nothing about a path rule on `/login`. `limit` is 50 by default and 200 at +most, with `truncated` saying when the probe set was cut; an unknown query +parameter is refused by name. It is a read: the read-only token can ask it, no +token cannot, `wrote` is always `false`, and the compose gate checks the wire +still answers the upstream after the preview — because a preview that writes is +the exact bug this endpoint exists to prevent. The console carries the same answer +as its own panel — "What would this ban touch?", an address or CIDR and an +optional path — above the tables the operator reads, so the preview is part of +where the decision is made rather than a call one has to know to issue. + ## Console `GET /admin` serves a single page over those endpoints — mode and snapshot age, @@ -1676,7 +1740,7 @@ consequence was always observable and nothing on any surface pointed at it. The console gate starts the stack, seeds a source sitting at 2 of a threshold of 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 70 things. The read side: it authenticated, listed the streak as +and asserts 164 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, said how many recorded sources the observation table is only @@ -1716,7 +1780,10 @@ and the status line must clear WCAG AA (measured 11.85:1). It needs `playwright- (`PLAYWRIGHT_CORE=/path/to/it`) and exits 2 when that is missing — a gate that reports success having asserted nothing is worse than no gate. Its negative control (a wrong token) exits 1. `SCREENSHOT=console-evidence.png` writes the -desktop and phone screenshots the CI job publishes as artifacts. +desktop and phone screenshots; the console job names them in its log with +size and sha256, because `actions/upload-artifact@v4` is not supported by the +Gitea runner (measured on run 2370: every assertion passed and the job still +went red on the upload step). ### The same gates on the runner's operating system @@ -2037,11 +2104,11 @@ dotnet/ OpenWaf.Domain/ pure decision core: source key, streak, ordered decision, refusal page OpenWaf.Infrastructure/ EF Core (sqlite/postgres), snapshot store, writers, MMDB geo, in-place schema upgrade OpenWaf.Edge/ the deployable: guard, observer, admin API, healthcheck mode - OpenWaf.Tests.Unit/ 256 tests over the decision logic, the budget window, the refusal wording, the schema baseline and the durability counters - OpenWaf.Tests.Integration/ 245 tests driving the real pipeline against a fake upstream -scripts/smoke.sh 52 assertions against a running edge + a real upstream + 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 229 assertions against the built image (compose + nginx) -scripts/console-check.cjs 90 assertions against the page, in a real Chromium +scripts/console-check.cjs 164 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 diff --git a/dotnet/OpenWaf.Tests.Integration/PillarFailureVisibilityTests.cs b/dotnet/OpenWaf.Tests.Integration/PillarFailureVisibilityTests.cs index e0a4ab9..e14fa7f 100644 --- a/dotnet/OpenWaf.Tests.Integration/PillarFailureVisibilityTests.cs +++ b/dotnet/OpenWaf.Tests.Integration/PillarFailureVisibilityTests.cs @@ -129,15 +129,24 @@ public sealed class PillarFailureVisibilityTests [Fact] public async Task The_snapshot_age_is_measured_against_the_ttl_it_is_supposed_to_respect() { - // A TTL of one second with no traffic is the honest way to ask "is this - // snapshot older than the bound the process refuses to start without" — - // the refresh is driven off the request path, so nothing refreshes it. - await using var f = new EdgeFixture(refreshTtlSeconds: 1); + // A short TTL with no traffic is the honest way to ask "is this snapshot + // older than the bound the process refuses to start without" — the refresh + // is driven off the request path, so nothing refreshes it while nobody is + // asking. The TTL is 10 rather than 1 because the first assertion is about + // the age at the moment of the first read, and that age already includes + // however long the fixture took to come up: measured on a loaded machine + // (OPEN-76), a one-second bound was already blown by WebApplicationFactory + // start-up before the assertion ran, and the test went red on a snapshot + // that was honestly stale. Ten seconds is a bound start-up cannot blow and + // still short enough that the wait below is a wait and not a fixture. + await using var f = new EdgeFixture(refreshTtlSeconds: 10); var first = await StateAsync(f); Assert.False(first.Body.GetProperty("snapshotStale").GetBoolean()); Assert.Equal(0, first.Body.GetProperty("snapshotRefreshFailures").GetInt32()); - await Task.Delay(2500); + // Past the TTL, and by enough margin that scheduling cannot land this read + // inside the window it is supposed to have left. + await Task.Delay(13_000); var later = await StateAsync(f); Assert.True(later.Body.GetProperty("snapshotStale").GetBoolean(), $"age {later.Body.GetProperty("snapshotAgeSeconds")} over a ttl of {later.Body.GetProperty("snapshotTtlSeconds")}: {later.Text}");