Commit Graph
4 Commits
Author SHA1 Message Date
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