Every defence this edge had reads something that already happened: the status the application answered, the country the address sits in, a list a human wrote. A source asking for a cheap path two hundred times a minute produces no refusal, so no streak matures, no path rule names it, and the origin serves all two hundred. The only signal is the count, and a count has to be kept while the requests are arriving — which is why this pillar is the one piece of live state on the request path, and why it runs after the ordered decision instead of inside it. `rateMode` off|observe|enforce, `rateLimitPerWindow`, `rateWindowSeconds` (policy_settings, so no schema change). Off is the default: a limit nobody wrote is a defence nobody asked for, and a false positive here locks out a whole office behind one address. `observe` counts and raises one `rate_breach` alert per source per window. `enforce` answers the request that crosses with 429 + Retry-After — the surplus never reaches the origin — and writes an engine ban, so the stop outlives the window, is shared with the other edges and survives a restart; from then on the answer is the ban's own 403. One breach, one alert, one ban write per source per window: a flood is exactly the traffic that turns a per-request durable write into the thing that takes the database down. Exempt by construction rather than by a second copy of the precedence rules: the counter runs only on a plain Pass, so an always-pass prefix, an allowlisted address, a matched rule, a block or a geo refusal never reaches it. The budget counts exactly the requests that would have cost the origin. Costs, stated rather than hidden: the counter is per process, so N edges allow N times the budget (the same trade `SharedStreaks` made for the streak, at a round trip per request instead of per observed response); the window is fixed, not sliding, so the worst sustained rate is twice the limit across one boundary — a sliding counter needs one entry per request, which is a map that grows at attack rate. Two things the run caught rather than the design assumed: * The guard wrote the 429 and then called next() anyway, so YARP answered "the request cannot be forwarded, the response has already started". The pillar now says whether the request may go through. * `StreakTracker.Configure` was called by nobody outside its own tests, so `maxTrackedSources` bounded nothing in a running edge — the map grew to the built-in 10000 whatever the operator had asked for. Both maps are configured at warm-up and on a policy write now. And the smoke gate was not testing what its first line says. The edge was started from the repository root, where there is no appsettings.json, so it loaded no ReverseProxy section at all, logged "Request reached the end of the middleware pipeline without being handled by application code" for every request, and answered 404 for a path the upstream was serving with 200. Every assertion in the file expects a 404 or a refusal, so the gate kept passing on an edge that never proxied anything. Naming the content root fixes it; the streak scene also waits for the ban row to exist before asking the wire whether it is enforced, because the ban is written out of band after the response that proved it. Gates on this tree: build 0 warnings 0 errors, unit 207/207, integration 219/219 in 20 s, smoke passed 48 failed 0, console 90 assertions 0 failed, compose 209 passed 0 failed, image 261 MB. OPEN-56
33 lines
1.4 KiB
C#
33 lines
1.4 KiB
C#
namespace OpenWaf.Domain.Policy;
|
|
|
|
/// <summary>
|
|
/// What the edge does with a source that asked more often than the budget
|
|
/// allows (OPEN-56).
|
|
///
|
|
/// A separate switch from <see cref="EnforcementMode"/> on purpose. Volume is a
|
|
/// different claim from a run of refusals: the streak reads what the origin
|
|
/// answered, the rate policy reads how often the origin was asked. An operator
|
|
/// who has been running the streak in Enforce for a month and wants to find out
|
|
/// what a volume limit would have done must be able to switch one on without
|
|
/// touching the other, and the reverse.
|
|
///
|
|
/// Off is the default. A limit nobody wrote is a defence nobody asked for, and
|
|
/// a false positive here locks out a whole office behind one address.
|
|
/// </summary>
|
|
public enum RateMode
|
|
{
|
|
/// <summary>Nothing is counted. The answer to every request is exactly what
|
|
/// it was before the feature existed.</summary>
|
|
Off = 0,
|
|
|
|
/// <summary>Counted, and said so — one alert per source per window — but
|
|
/// nothing is refused. This is how an operator learns what the budget would
|
|
/// have cut before it cuts anything.</summary>
|
|
Observe = 1,
|
|
|
|
/// <summary>The request that crosses the budget is refused for the rest of
|
|
/// the window, and the source also gets an engine ban so the stop is shared
|
|
/// with the other edges and survives a restart.</summary>
|
|
Enforce = 2
|
|
}
|