7 Commits
Author SHA1 Message Date
Pavlo Ratushnyi be6c608ada the edge ships on an image with no base, and the 368 assertions agree it behaves
ci / the operator page in a real browser (push) Successful in 2m38s
ci / lint the workflow and the shell (push) Successful in 13s
geo-freshness / the pinned geo database vs the vendor (push) Successful in 4s
ci / build, test, smoke (push) Successful in 2m48s
ci / build the image and smoke it (push) Successful in 4m23s
ci / the same smoke on an image with no base (push) Successful in 5m3s
Dockerfile.scratch builds the same program self-contained and puts it on
scratch: 12 shared objects and the CA bundle — 18.7 MB — carried at their
absolute paths, because a scratch layer has nothing to borrow them from, and the
dynamic loader has to land at the path recorded inside the binary or the kernel
refuses to start the process. Measured on one arm64 host: chiseled 262 MB,
scratch 222 MB. scripts/compose-smoke.sh runs against it unchanged through
docker-compose.scratch.yml: 368 passed, 0 failed, and 368/0 again when the same
gate is called as scripts/ci-gates.sh scratch-smoke.

The first scratch image built here is why that second run matters. It started,
its own HEALTHCHECK reported healthy, and it still failed 7 of the 368. A
self-contained apphost takes its content root from the process's working
directory, a scratch image has no WORKDIR, so the process began in /, never found
the appsettings.json next to it, the reverse proxy had no routes, and every
request that should have reached the upstream answered the edge's own 404 —
including /boom's 502, which turned the "server errors alert, they never ban"
scene into a streak ban. The edge said it in its own log: "Request reached the
end of the middleware pipeline without being handled by application code."

The schema-script gate was red on the runner at 7c5e1ef (run 2462, exit 2):
`dotnet tool restore` from the repo root finds no manifest, prints "No tools were
restored." and exits 0, so the gate's own restore check passed vacuously and
`dotnet ef` then died. It now restores dotnet/dotnet-tools.json by path and asks
the tool for its version before trusting it.

NativeAOT, measured further: with the two alert-queue queries taken out,
`dotnet ef dbcontext optimize --precompile-queries` on EF 10.0.12 reports 0
precompilation errors and writes 8 interceptor files — 14 of whose declarations
have dots in the identifier, because the local is named from the entity type's
full name. The 4 refusals that remain are four shapes the generator cannot
translate at all: Contains over a captured collection, any method parameter
referenced inside a query (down to the CancellationToken), an ExecuteUpdate
set-list, and a literal whose type is not the column's. docs/ARCHITECTURE.md
carries the exception for each. No C# changed in this commit: the experiments
that produced those numbers were reverted, and the query rewrites kept at
7c5e1ef are the ones that made 40 refusals into 4.

Gates: scratch-image and scratch-smoke in scripts/ci-gates.sh and in `all`, and a
fifth CI job that runs the 368 against the scratch image on the runner.
2026-10-06 06:38:07 +02:00
Pavlo Ratushnyi 7c5e1ef230 the edge gains a schema step a compiled binary can run, and NativeAOT gets a measured verdict
ci / lint the workflow and the shell (push) Successful in 10s
geo-freshness / the pinned geo database vs the vendor (push) Successful in 5s
ci / the operator page in a real browser (push) Successful in 3m42s
ci / build, test, smoke (push) Failing after 2m6s
ci / build the image and smoke it (push) Successful in 5m7s
The Dockerfile said "why not NativeAOT" on the authority of another repo's
Dockerfile. That claim is now this repo's own, and it is a measurement.

What was built to find out:

* Persistence/Schema/schema.sqlite.sql — the model's DDL, generated by
  `dotnet ef dbcontext script`, embedded in the binary and read by
  Persistence/EmbeddedSchema.cs. A NativeAOT build cannot ask EF to build a
  model at run time, and EnsureCreated and GenerateCreateScript both go through
  the design-time model, so the schema step has nowhere to get its SQL from.
  OPENWAF_SCHEMA=script is the fourth strategy: same provider-shaped
  statements, produced at build time instead of at start-up. The schema-script
  CI step regenerates the file and fails the run when the committed copy is not
  what the current model produces (5652 bytes today).
* SchemaUpgrader.ModelTables asks the runtime model, per entity type. The
  design-time one is refused outright under NativeAOT, and GetRelationalModel()
  on the runtime model of a compiled model throws
  "The annotation 'Relational:DefaultMappings' cannot be added because an
  annotation with the same name already exists on the object EntityType:
  CountryRule" — building a compiled model's relational model a second time
  collides with itself.
* The persistence layer's queries were rewritten into the shape EF's query
  precompiler accepts: captured parameters copied to locals, conditional
  IQueryable composition written as literal chains, aggregates that take a
  predicate given their own Where. 40 of them were refused before that.
* dotnet-ef and EF Core moved 10.0.0 -> 10.0.12, because 10.0.0's design package
  ships no build host and `--precompile-queries` cannot load a project without it.

What the measurement says, from scripts/aot-probe.sh on osx-arm64: the AOT build
compiles (48,797,072-byte native binary, 10 IL warnings, 0 errors), starts, and
creates all 12 tables from the DDL it carries. Then it never serves. EF refuses
every query at run time ("Query wasn't precompiled and dynamic code isn't
supported with NativeAOT"), and the precompiler that would fix that is not
usable on this model: after all 40 refusals were cleared it emitted 14
declarations with dots in the identifier
(`var openWaf.Domain.Security.BlockEntryPrimaryKeyProperties = …`) — 28 CS1002
and CS1003 errors, one per entity materialisation — with or without --nativeaot.
The refusals themselves trace to dotnet/efcore#35887, #38030 and #35494; the fix
landed in the 12.0-preview1 milestone, not in any 10.0.x.

Two things were not kept, and why:

* The atomic alert-queue claim and the claim release were rewritten as raw SQL
  to dodge the precompiler's ExecuteUpdate failures. Reverted: with the
  statement written as SQL, DateTimeOffset reaches sqlite as a provider
  parameter instead of through the property's own mapping, the reclaim
  comparison stops matching, and
  AlertPushQueueTests.A_delivery_owed_by_a_process_that_stopped_is_owed_by_the_next_one
  fails with the row still owed. A correctness risk here buys nothing when the
  AOT build is blocked further along anyway.
* --nativeaot on the compiled model: its unsafe accessors do not compile
  (CS1503 in BlockEntryEntityType.cs). The plain compiled model is what is
  committed.

The compose gate's two escalation-count scenes also stopped being a coin toss.
They slept a fixed 2 s and then counted; on a loaded host the same tree read 3
rows once and 1 the next, and the assertion is about a settled number either
way. They now wait for three equal reads, bounded. The scene count is unchanged
at 368.

Gates at this commit: build 0 warnings / 0 errors, unit 378/378, integration
405/405, schema-script ok, smoke 256/0, compose-smoke 368/0, README counts
match (256, 368), lint clean (actionlint 1.7.12, shellcheck 0.11.0).

Not verified: the AOT image on linux-x64 — the probe ran on osx-arm64, and the
ILC failure mode that ends the attempt is a codegen bug in EF, not a
platform-specific one, but that is an inference rather than a measurement.
2026-10-06 05:20:28 +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 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 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 3cede3c302 Dockerfile: fetch the geoip database in its own stage
Downloading inside the SDK stage put apt-get update on every cache miss;
observed as a >12-minute stall on the first build. A static curl image
removes apt entirely from this step and the download itself takes ~2s.

Also pins DBIP_VERSION to 2026-09: the 2026-04 file is gone from the
DB-IP CDN (404), which failed the build.
2026-10-01 09:49:32 +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