4 Commits
Author SHA1 Message Date
Pavlo Ratushnyi 34a13ce796 D5: the alert dedup is per process, and two edges is where that shows 2026-10-01 18:03:54 +02:00
Pavlo Ratushnyi f7ced94f75 The TTL knob got measured, and a sentence in the research turned out to be stale
`research/2026-10-01-multi-instance/RESULTS.md` said, correctly at the time, that
the snapshot TTL "is not operator-tunable... so 'shorten the TTL' is currently a
rebuild, not a deployment change". OPEN-13 made it
`OpenWaf:State:RefreshTtlSeconds` (validated 1-300 s, startup aborts naming the
key outside that range). A claim that was true and is now false is still a claim
sitting in a document, so it is corrected in place, with what changed and when,
rather than quietly rewritten.

`run4.sh` measures the option that claim was blocking. Same stack and same method
as D3 — edge-b serves a steady 200-only stream from one source (a refusal stream
bans its own probe, which is the mistake `run2.sh` made), edge-a writes an
operator block at t0, the first sample edge-b answers as a refusal is the
propagation number. Two phases, and the TTL is read back from `/healthz` rather
than assumed from the environment, because a typo in the key name would otherwise
measure 30 s twice and report it as two different settings.

    ttl=30 (default)  samples=1223 over 44.1 s (~27.7 req/s)  enforced 23 100 ms after the write
    ttl=5             samples=1247 over 44.3 s (~28.1 req/s)  enforced  3 367 ms after the write

**23.1 s → 3.4 s: a 6.9x cut**, and the 30 s phase independently reproduces D3's
23.7 s, which is the second time that number has come out the same.

What it does not say. The request path through edge-b during the same runs: p50
1.75 ms / p95 3.15 ms at TTL 30, p50 1.93 ms / p95 2.78 ms at TTL 5, n=200 each.
The two percentiles move in opposite directions, so the honest reading is "inside
noise", not "cheaper" — and a shorter TTL is more refresh round trips per process
per minute (12 against 2), cheap at the snapshot size that was measured (~3 ms of
queries at 2000 blocks) and unmeasured at any larger size.

For OPEN-12 this turns option (b) from an assumption into a measurement, and
leaves its limit exactly where it was: shortening the TTL fixes propagation, and
does nothing about D1 — four refusals split 2+2 across two edges at threshold 3
still produce no ban anywhere. The streak map is still the thing that would have
to move.

`docs/ARCHITECTURE.md` evolution triggers 2 and 3 updated with what is now true:
the geo-staleness trigger partly fired and was handled (including the case the
90-day runtime alarm does not catch), and the multi-instance trigger now carries
both reproduced findings and the measured TTL effect.
2026-10-01 17:18:12 +02:00
Pavlo Ratushnyi 768dd17a88 Measure the two-edge deployment instead of arguing about it
OPEN-12 asks whether the per-process snapshot is worth replacing. Until now
the answer rested on an SQLite measurement. This runs the deployable image
against PostgreSQL with two edges and one shared database and writes down
what actually happens: round-robin over two edges multiplies the effective
streak threshold (four refusals split 2+2 at threshold 3 produced no ban at
all), a block issued by one edge is enforced by the other after up to the
30 s snapshot TTL (23.7 s measured under 36 req/s, 1.7 s on an idle edge),
and the refresh itself is not the cost (3 ms of queries at 2000 blocks,
request p95 unchanged at 3.3 ms). Concurrent migrations on one database are
safe.

docs/ARCHITECTURE.md's multi-instance evolution trigger now points at the
measurement instead of restating the worry.
2026-10-01 12:33:17 +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