Commit Graph
14 Commits
Author SHA1 Message Date
Pavlo Ratushnyi b6126c2fd2 Two rules that had only ever been proven inside a test process
`Server errors alert, they never ban` and `Observe mode records the decision and
blocks nothing` are the two claims that protect honest traffic from this WAF: a
bad deploy must not lock out the site's own visitors, and a dry run must be
judgeable before it is allowed to act. Both were proven in-process, against
`FakeUpstream`, in `EdgeBlockingTests`. Neither had ever been proven against the
image users actually run. And `GET /admin-api/alerts` appeared in **zero** gate
scripts — the operator-visible half of the alerting pillar had no gate at all,
which is how the console gate found its first bug: everything below the surface
looks fine while nothing reads it.

`deploy/upstream.conf` is nginx's own default plus one path that answers 502,
mounted read-only into the compose upstream. `scripts/compose-smoke.sh` grew two
sections, 28 → **35 assertions**:

    - server errors alert, and never ban
      a 502 reaches the client through the edge / four 502s did not ban the source
      that saw them / no engine ban written / a server_error_streak alert exists
    - Observe mode records the decision and blocks nothing
      five refusals still reach the upstream / no ban written / the dry run is
      visible as a candidate_ban alert

Numbers: host **35 passed, 0 failed**; the same script in the Linux rehearsal
(`docker:cli` against the host daemon) **35 passed, 0 failed**.

Two lessons about counting, both written into the script:

- The data volume survives `compose down`, so an absolute alert count asserts
  history rather than this run. Alerts are counted as a delta now.
- The alert is written *after* the response is, so a count read the instant the
  last request returns undercounts. The first version of the measurement line
  printed 1 where the settled number is 2. A number that is wrong by a race is
  worse than no number, so the count is taken after a pause.

The measurement itself is the finding: **4 requests past N=3 wrote 2 alert rows**
— one row per response past the threshold, not one per source. A real 5xx storm
therefore writes at request rate. Retention ages alerts out (`BanRetention`), so
they do not accumulate forever, but the write rate is a number an operator should
know before their upstream falls over.

Honest about the fixture: the 502 is nginx returning it directly, not an
application failing behind nginx. The edge's classifier sees a status code on a
socket, which is exactly what the rule is about; the fixture does not simulate a
crashed process, and nothing should read it as if it did.
2026-10-01 16:24:02 +02:00
Pavlo Ratushnyi 7afa7541a2 The geo pin has a shelf life now, and a gate that checks it
The Dockerfile pins `ARG DBIP_VERSION=YYYY-MM`, and moving that pin was a habit
someone kept by hand: 2026-10 on 2026-10-01, 2026-09 the month before that. The
runtime answer was not better. `/healthz`'s `geoStale` is a 90-day alarm, and a
month behind is not 90 days. Measured on this tree: a container whose named
volume held `dbip-country-lite-2026-09` while the Dockerfile asked for `2026-10`
reported `geoBuiltAt: 2026-09-01T01:32:45+00:00` and `geoStale: false` — and
every geo assertion in `compose-smoke.sh` stayed green, the country deny list
still refusing 8.8.8.8 with 451. The policy was being enforced on a database
nobody chose, reported as healthy.

Three pieces:

- `scripts/geo-db-freshness.sh` compares the pin with the newest release the
  vendor actually serves (14 HEAD probes, newest first). Three exit codes, not
  two: 0 current, 1 the vendor has something newer, 2 could not tell — no
  network, or a pin the vendor has never served, which would make the image
  build fail on a 404. `MACHINE=1` prints one line for the bump script.
- `scripts/geo-db-bump.sh` rewrites the ARG and prints the two commands that
  make the new database actually land. It refuses to write anything when the
  check could not run: a pin moved on the strength of a check that did not run
  is worse than a pin left alone.
- `.github/workflows/geo-freshness.yml` runs the check on the 1st and the 8th
  (dbip publishes on the 1st; the second date catches a late publish or one
  failed run). It deliberately does not open a PR — a bot that cannot run the
  geo assertions bumping a data dependency is a worse default than a red job.

`scripts/compose-smoke.sh` grew the assertion that ties the pin to the running
container: `the loaded geo database is the pinned one`. Its teeth were checked,
not assumed — the stale volume above produced exactly one failure:

    FAIL the loaded geo database is the pinned one   Dockerfile pins 2026-10, the container loaded 2026-09
         a named volume is seeded once: docker volume rm openwaf_openwaf-geoip
    compose smoke: 27 passed, 1 failed

and after `docker volume rm`, **28 passed, 0 failed**.

Numbers on this tree. Host, `scripts/ci-gates.sh all`, EXIT=0: build 0 warnings,
unit 54/54, integration 28/28, smoke 19/19, image 261 MB, compose-smoke 28/28.
Linux rehearsal (third run today), EXIT=0: source PASS (54/54, 28/28, 19/19),
compose 28/28 with enforcement lag 36 ms, console 26/26. The freshness script
itself in `mcr.microsoft.com/dotnet/sdk:10.0`: current pin exits 0, a forced
`PIN=2026-05` exits 1 with the bump command. actionlint 1.7.12 over both
workflow files: 0 problems; shellcheck and `bash -n` clean.

Honest edges. The scheduled job has never run, because the repository has no
remote; and GitHub disables schedules on a repository with no push for 60 days,
so a cron is a nudge with a failure mode. A red freshness job can mean "no
network" rather than "stale" — the message names which, and exit 2 is not exit 0.
2026-10-01 16:09:11 +02:00
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
Pavlo Ratushnyi c290aa06f6 Every gate this workflow runs now has a Linux number except one
`scripts/ci-linux-rehearsal.sh` (added in `42d4af9`) covered the dotnet suites
and `smoke.sh`. The third thing the objective asks CI to run — `scripts/
compose-smoke.sh` — did not have a Linux number, and "we run it on macOS against
a Linux image" is only half a proof: the script itself is the part that could be
a darwin habit.

It now runs in `docker:cli` against the host daemon, so the image build, the
stack and the asserting shell are all Linux. Full rehearsal, one invocation:

    source gates (restore/build/unit/integration/smoke): PASS   54/54, 28/28, 19/19
    compose gate: PASS                                          27 passed, 0 failed
    console gate: not covered here (needs a real Chromium)
    wall: 47.61 s

Getting it green surfaced two facts about the harness, not the product, and both
are now comments in the script where the next person will hit them:

- `compose-smoke.sh` asserts over JSON with **python3** (`jcount`/`jget`) and
  reads the clock with it. A bare container failed **23 of 27** assertions for
  nothing else. The runner image has python3; `docker:cli` does not, so the
  stage installs bash, curl and python3 itself.
- The stack is created by the host daemon, so its published port lives in the
  host's network namespace. Without `EDGE=http://host.docker.internal:8080`,
  every HTTP assertion returns curl code `000` **while the image's own
  HEALTHCHECK reports healthy** — a green stack with red assertions, the most
  confusing failure this gate can produce. The gate already had an `EDGE`
  override; this is what it is for.

The compose stage also printed its own instrumentation again: enforcement lag
**12 ms** between writing a ban and the edge refusing the source — the snapshot
invalidation path, measured on Linux this time.

Still true and still said plainly: none of these jobs has executed on a runner,
because the repository has no remote. The Linux numbers narrow what a first run
could still discover; they do not replace one.
2026-10-01 15:31:16 +02:00
Pavlo Ratushnyi bf1129a8d8 The failure mode on a write form is the one nobody demos
The console now writes, so the question stopped being "does the table show the
ban" and became "what happens when the operator types the wrong thing". A form
that accepts `not-an-ip`, says nothing, and adds no row leaves an operator
believing an address is blocked when it is not — which is worse than giving them
no console at all.

Two assertions added to the browser gate. The API already rejected the value
(`BlockStore.AddOperatorAsync` returns `not an IP address: not-an-ip`, the
endpoint answers 400, the page already surfaces `body.error` in its status line);
what is new is that a gate now proves that chain instead of assuming it. The run
prints the actual string: `not an IP address: not-an-ip`, and no phantom row in
the bans table. Console gate: **26/26**.

Also measured, because a timeout written at a desk is a guess: the Linux
rehearsal (`scripts/ci-linux-rehearsal.sh`, added in `42d4af9`) was re-run with
`time`. Cold container, cold NuGet cache, Ubuntu 24.04.5, SDK 10.0.401:
**1:02.81** wall for restore + build + unit + integration + smoke. The source
job's `timeout-minutes: 25` is not close, even allowing for a runner's slower
CPU. Before this, the number in the workflow was folklore from a build that once
stalled ~12 minutes on a single apt-get step.

No source-tree change in this commit: gate assertions and the numbers written
down where the next reader will look for them. Unchanged and still said plainly:
no job of this workflow has executed on a runner — the repository has no remote.
2026-10-01 15:16:19 +02:00
Pavlo Ratushnyi 42d4af9a76 The gates were rehearsed on the runner's operating system, without a runner
Every green number this project has quoted was produced on darwin. The workflow
runs on ubuntu-latest. That is not a cosmetic difference: a gate that passes on
macOS and fails on Linux is a local habit wearing a gate's clothes, and the
first person to find out would be the first CI run — which, with no remote, is
still a run that has not happened.

`scripts/ci-linux-rehearsal.sh` copies the tree (no `.git`, no host build
output — Linux binaries landing in a macOS working tree make the next
`--no-build` try to exec an ELF file) and runs restore, build, unit, integration
and smoke inside `mcr.microsoft.com/dotnet/sdk:10.0`. Result, first try, nothing
to fix:

    Ubuntu 24.04.5 LTS, x86_64
    sdk resolving global.json: 10.0.401
    unit         Passed! 54/54
    integration  Passed! 28/28
    smoke        passed 19, failed 0

The SDK line answers a question the workflow would otherwise have asked in front
of an audience: `dotnet/global.json` pins `10.0.100` with
`rollForward: latestFeature`, and `setup-dotnet` with `10.0.x` installs
`10.0.401` — that combination resolves, measured rather than assumed.

What it does not cover, said plainly: `compose-smoke` needs a docker daemon
inside the container, and the console gate needs a real Chromium. Both of those
already drive a Linux image, so the un-rehearsed part there is the host-side
script, not the thing under test. The script installs `python3` in the container
because the dotnet SDK image has no python and `smoke.sh` uses
`python3 -m http.server` as the upstream it knows nothing about — the runner
image has python3, so this is a rehearsal detail, not a project dependency.

Nothing in the source tree changed: this commit adds the rehearsal script and
writes down what it proved. The honest status sentence is unchanged — no job of
this workflow has ever executed on a runner, because the repository has no
remote.
2026-10-01 15:09:31 +02:00
Pavlo Ratushnyi 31d8633975 A console that can only read is a dashboard, not a console
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.
2026-10-01 14:56:16 +02:00
Pavlo Ratushnyi 66df999cdf The country table got a shape, and the page caught me colliding with itself
The console's country view was a column of numbers. "Where is this traffic
coming from" is a comparison, so each row now carries a bar sized against the
busiest country, and the table says what it counted. No tiles, no CDN, no asset
file: the runtime image is distroless and the page has to work at the moment the
site in front of it is being attacked. A geographic map is still not here and
the README now says why plainly — the admin API exposes counts per ISO code, not
coordinates, and an outline drawn from memory would be decoration that misleads.

The first run after the change failed, for a real reason: the class I added was
`.bar`, and the page already had a `.bar` — the toolbar. The toolbar collapsed
to 0.55em tall, `div#summary` started intercepting pointer events, and every
assertion after the token click died on a click timeout. Renamed to
`.sharebar`.

The gate itself got the same treatment as the page. It used to leave a reviewer
with nothing but a stack trace; now it writes a screenshot both when the page
cannot be driven at all and when it is driven and wrong. That path was checked
by making it red on purpose: with seeds that do not match the stack it exits 1
naming 3 failed assertions and writes a 105078-byte picture.

Measured, not assumed, in the same pass:

- `ci-gates.sh` gained a `console` gate and the workflow calls it by that name
  instead of retyping the script: one definition, two callers. It is
  deliberately NOT in `all` — without a Chromium the gate exits 2 ("cannot
  run"), which is a different answer from 1 ("the page is wrong"), and folding
  it in would make the one-command entry point unrunnable off a CI runner.
- `ci-gates.sh all` no longer stops at the last gate for want of an admin
  token: it was dying at compose-smoke with `OPENWAF_ADMIN_TOKEN: set …` before
  it could print a verdict. The throwaway for the stack the gate starts and
  tears down itself is defaulted there; the standalone scripts still refuse to
  invent one, because run by hand they can be pointed at a real deployment.
- The console job publishes the desktop and phone screenshots as artifacts,
  with `if: always()` so the failure case is the one you can look at. The
  relative SCREENSHOT path and the `console-evidence*.png` glob were verified
  locally: 107935 and 86179 bytes written.
- DBIP_VERSION 2026-09 -> 2026-10. Not a cache hit: 8348509 bytes fetched,
  image 261 MB, compose smoke 27/27 afterwards.
- The trap that bump exposes, measured rather than reasoned about: the same
  rebuilt image reported `geoBuiltAt: 2026-09-01T01:32:45Z` against the
  existing `openwaf_openwaf-geoip` volume and `2026-10-01T01:36:12Z` after
  removing it. Docker seeds a named volume from the image only when the volume
  is first created, so a rebuild alone never replaces the geo database.

Gates on this commit: build 0 warnings / 0 errors, unit 54/54, integration
27/27, smoke 19/19, image 261 MB, compose-smoke 27/27, console 16/16 (desktop
bar 513 px inside a 529 px cell; phone pass at 375 px in dark mode: scrollWidth
375, status contrast 11.85:1, bars 67 px), actionlint 0, shellcheck 0. Still
true, and unchanged by any of the above: not one of these jobs has run on a
runner, because the repository has no remote.
2026-10-01 14:26:33 +02:00
Pavlo Ratushnyi 1014712c99 The console was unreadable on a phone in dark mode — measured, then fixed
The console gate had never looked at anything but a 1280 px desktop in light
mode, and I had recorded that as a gap twice. Probing it properly found two
real defects, both with numbers before and after.

Contrast. The page declares color-scheme: light dark, so Chromium paints a dark
canvas — but .ok and .warn were fixed colours chosen for white paper. The
status line, which is the only feedback the page gives ("token rejected" vs
"refreshed"), measured 2.82:1 against rgb(18,18,18). Below WCAG AA. The two
colours now have dark-scheme values; the same measurement reads 11.85:1.

Width. At a 375 px viewport the seven-column tables measured 501 px and pushed
the whole document to 520 px of sideways scroll — the token field and the
summary pills slid off screen, on the one device an operator reaches for when
they have blocked themselves. Each table now scrolls inside its own box; the
document measures 375 against a 375 viewport.

The gate covers both, so the gap cannot silently reopen: console-check.cjs runs
a second pass at 375x720 in dark mode and asserts the document does not
overflow, the status line clears 4.5:1 against the Canvas the browser actually
paints (computed, not eyeballed), the standing streak is still listed, the
token is still absent from the markup, and no javascript threw. Twelve
assertions pass on this commit.

Also fixed while here: SCREENSHOT without an extension made Chromium throw
"unsupported mime type", which reads like a page failure and is not one.

Gates on this commit: scripts/ci-gates.sh all — build 0 errors, unit 54/54,
integration 27/27, smoke 19/19, image built, compose-smoke 27/27; console gate
12/12 against the running image.
2026-10-01 13:55:45 +02:00
Pavlo Ratushnyi b9a6c7e532 One definition of a gate, and a gate for the page itself
OPEN-10's honest caveat has always been the same sentence: the workflow has
never executed on a runner, so it proves what CI will run rather than being
green. That gap cannot be closed from this machine — the repository has no
remote — but the gap behind it can. Until now ci.yml retyped every command, so
"an agent ran these commands on a laptop" and "CI runs these commands" were two
claims that could drift apart without anyone noticing.

scripts/ci-gates.sh is now the single definition: restore, build, unit,
integration, smoke, image, compose-smoke, or all. The workflow calls one gate
per step, so the job log still names the gate that failed, and an operator
running scripts/ci-gates.sh all before pushing is running the same file.

The console had no gate at all. Its evidence was an agent driving Chromium from
a script in /tmp. scripts/console-smoke.sh 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 seven things: the page authenticated, the
standing streak is shown as current/threshold rather than as a historical
maximum, the block shows its reason, observations and the country summary
rendered, the token is nowhere in the markup, and the page threw no javascript.
It needs playwright-core and exits non-zero when that is missing — a gate that
reports success having asserted nothing is worse than no gate. The negative
control was run: with a wrong token it exits 1.

Verified on this commit: scripts/ci-gates.sh all end to end — build 0 errors,
unit 54/54, integration 27/27, smoke 19/19, image built, compose-smoke 27/27;
console-smoke 7/7 assertions against the running stack (playwright-core 1.61.1);
actionlint 0; shellcheck over scripts/*.sh 0. The new console job pins
playwright@1.63.0, a version checked against the registry rather than guessed,
and it has never run on a runner — the README says so in the same breath as the
rest of the workflow.

README gains a Gates section and the per-process cost bullet now quotes the
measurement instead of the worry.
2026-10-01 13:43:17 +02:00
Pavlo Ratushnyi 9491f01b86 CI: lint the workflow and the shell that runs the gates
A gate that is only checked by eye is a gate that fails silently. Two additions
to ci.yml:

 * a lint job running actionlint 1.7.12 pinned by a checksum-verified tarball —
   not piped from a setup script, because a gate someone can move by
   republishing a tag is not a gate. actionlint also shellchecks the run: blocks
   it reads, including its own.
 * shellcheck over scripts/*.sh. Both smoke scripts are gates, so a broken one
   has to fail loudly rather than report a green run with zero assertions.

shellcheck found four real things in compose-smoke.sh: an unguarded cd, and
unquoted source IPs in the X-Forwarded-For helpers. Fixed; the script now passes
shellcheck and still reports 27/27 against the built image.

Verified, not assumed: actionlint exits 0 on this file locally (shellcheck
integration active), and the lint step's body — checksum, tar, actionlint — was
run on ubuntu:24.04, the family ubuntu-latest runs on, with the pinned digest
confirmed against the published artifact (sha256sum -c: OK). What is still not
verified is the workflow running on a GitHub runner: the repository has no
remote.
2026-10-01 11:47:48 +02:00
Pavlo Ratushnyi 0a8d0e7695 Operator console at /admin, over the endpoints that already exist
The admin API has been complete since a3d0777 and an operator still has to
drive it with curl. GET /admin now serves one page: mode and snapshot age, live
bans with their reasons, the sources being watched, and the countries seen.
Every control on it is one call to an existing endpoint — the page decides
nothing, which is the only reason it is safe to put on an edge.

Inherited properties, tested rather than asserted in a comment:
 * /admin is on the always-pass list, so a blocked operator can still reach the
   page that unblocks them (integration test + compose-smoke assertion);
 * the always-pass surface is never observed, so fumbling it builds no streak;
 * the token is typed into the page and sent as a header — never in a URL, where
   it would sit in proxy logs, history and Referer — and the markup is checked
   not to contain it, in the fixture and against the built image.
No external assets: a console that needs a CDN fails exactly when the site
behind the edge is under attack.

One new read endpoint, /admin-api/countries/summary, counting sources and
refusals per country from the observation aggregates — there is no request log
to count, by design.

Two bugs the new tests caught before this was true:
 * "/admin" and "/admin/" are the same route to the matcher — registering both
   is an AmbiguousMatchException, i.e. a 500 on the page; now one endpoint with
   a catch-all, so a mistyped subpath shows the page instead of being proxied to
   an upstream that has never heard of it.
 * the country query compiled and failed at translation time with a record
   constructor; an anonymous projection translates.

Gates on this commit: 36 unit + 19 integration, 0 failed; scripts/smoke.sh
19/19; docker build ok (261 MB); scripts/compose-smoke.sh 27/27, the three new
assertions included.
2026-10-01 11:32:52 +02:00
Pavlo Ratushnyi 0234cc1c72 Verify the deployed image end to end; ship country-lite by default
The image built, but nothing had ever run it. scripts/compose-smoke.sh now
asserts the ship shape against the built image: the image HEALTHCHECK reaches
healthy, a streak ban is enforced over a real socket with Retry-After and a
reason, a bystander from another source is untouched, an operator block
redirects, an allow entry outranks it, DELETE ?source=engine cannot clear an
operator row, and a denied country answers 451 while another source passes.
24 assertions, 0 failures.

Two build fixes found by actually building:
 * ARG DBIP_VERSION was declared inside the build stage, so the geoip stage's
   re-declaration expanded to an empty string and the URL 404'd. Both ARGs are
   global now.
 * curlimages/curl runs as uid 100, so /geoip was not writable; the download
   lands in /tmp and COPY re-owns it.

The bundled database is dbip-country-lite (4 MB) rather than city-lite (127 MB
unpacked): the geo pillar decides on the ISO country code, and city only feeds
two observation columns. --build-arg DBIP_EDITION=city restores it, and
MaxMindGeoIpLookup reads DatabaseType rather than the filename, so no code
change is involved either way.
2026-10-01 10:08:10 +02:00
Pavlo Ratushnyi a3d0777492 openwaf: edge WAF with one decision point and a streak ban
Initial implementation of the OPEN-2 epic: a .NET 10 YARP edge that
decides from what the upstream answered.

Design (docs/ARCHITECTURE.md, tracker authority 4c9de3f6):
- one short-circuit point, ordered: always-pass prefixes -> allowlist ->
  operator block (301) -> engine ban (403 + Retry-After) -> geo (451)
- a post-response observer feeds a consecutive-refusal streak; N refusals
  in M minutes ban for BanDuration; 5xx alerts and never bans
- provenance on the block row, so clearing engine bans cannot touch an
  operator's entries; the toggle is Off/Observe/Enforce and changes no rows
- inherited protections from the reference deployment: one durable write
  per source per 30s, LRU-bounded streak map, no DB on the request path

Verification: 36 unit + 14 integration tests, plus scripts/smoke.sh (19
assertions against a running edge and a real upstream, including the
distroless --healthcheck mode).

Findings worth keeping (documented in docs/ARCHITECTURE.md):
- ctx.RequestAborted silently cancelled the ban write, because the
  observer runs after the response is written
- SQLite cannot translate DateTimeOffset comparisons; timestamps are
  stored as integers there and stay timestamptz on PostgreSQL
- CIDR masking order silently widened prefixes (198.51.100.24/19 -> /16)
- an empty string in appsettings.json defeats the env fallback (?? on "")
- concurrent ban writes raced into the unique index and lost evidence

Also moves the unrelated 2026-09-30 inference benchmarks out of the
project root into research/.
2026-10-01 02:13:01 +02:00