Files
Pavlo Ratushnyi 575ef88afe an operator can ask what the edge would answer, before it answers anyone
OPEN-59. Every other admin surface answers what the edge already did, so the only test for a path rule, an exemption or a country rule is a real visitor getting the real refusal. GET /admin-api/decide?ip=&path=&country= runs the same DecisionEngine over the same snapshot the wire reads — there is no second decision to drift — and narrates the order.

The trace is the product: a verdict says what would happen, the pillar list says which pillar to change, and it keeps four silences apart (did_not_match, not_reached, not_enforced_in_this_mode, not_evaluated). In Observe mode the engine line says whether a live ban for that source exists, because 'nothing was known about this address' and 'something was known and the mode chose not to act' are the two answers operators read as one. What a preview cannot honestly answer — the live rate counter and a streak that depends on responses the upstream has not produced — is named in the body rather than left out.

Three things the run caught. IPAddress.TryParse accepts abbreviated IPv4, so '203.0.113' parses as 203.0.113.0 and a missing octet was answered 'pass' for an address the operator did not mean; the guard now requires a full dotted quad. The preview read state.Current while the guard calls GetOrRefresh(), so it could answer from a snapshot the wire had already replaced — the whole claim of the feature is that the two agree. And a Pass carries no source key, so the Observe note claimed 'no live ban' for a source that had one; the key is now computed for the question rather than read off the answer.

Gates on this tree: build 0 warnings / 0 errors, unit 256/256, integration 245/245, smoke 65/0, compose 229/0 against the built image (261 MB), console 90/0.
2026-10-05 01:36:29 +02:00

52 lines
2.3 KiB
C#

namespace OpenWaf.Domain.Engine;
/// <summary>The one answer the edge gives a request. There is exactly one
/// place in the pipeline that may produce a non-Pass value.</summary>
public enum EdgeVerdict
{
Pass = 0,
/// <summary>Passed because the operator allowlisted the address. Wins over
/// every other pillar, including a geo deny.</summary>
PassAllowlisted = 1,
/// <summary>Passed because the path is an always-pass prefix (admin API,
/// health probes) — the recovery hatch for a self-blocked operator.</summary>
PassBypassed = 2,
BlockOperator = 3,
BlockEngine = 4,
GeoReject = 5,
/// <summary>Refused by an operator-written request rule. Fires in Observe
/// mode too: the mode switches off what the edge decides by itself, not
/// what a human wrote down.</summary>
BlockRule = 6,
/// <summary>Passed. An observe-action request rule matched, and the guard
/// records it — the verdict exists so "nothing matched" and "a rule matched
/// and was told to watch" are different answers.</summary>
PassRuleObserved = 7,
/// <summary>Refused for asking too often (OPEN-56). Produced by the guard
/// rather than by the ordered decision, because it is the only pillar that
/// reads live state; it is still one answer from the one place that may
/// refuse a request, and it deserves a name in the log for that.</summary>
BlockRate = 8
}
/// <summary>The verdict in the spelling every surface uses — the log, the metrics
/// label, and the decision preview (OPEN-59). One mapping, because the same word
/// has to mean the same thing in an alert rule and in a grepped line, and
/// <c>ToString()</c> on the enum answers "blockrule", which is neither.</summary>
public static class EdgeVerdictLabel
{
public static string For(EdgeVerdict verdict) => verdict switch
{
EdgeVerdict.Pass => "pass",
EdgeVerdict.PassAllowlisted => "pass_allowlisted",
EdgeVerdict.PassBypassed => "pass_bypassed",
EdgeVerdict.PassRuleObserved => "pass_rule_observed",
EdgeVerdict.BlockOperator => "block_operator",
EdgeVerdict.BlockEngine => "block_engine",
EdgeVerdict.BlockRule => "block_rule",
EdgeVerdict.GeoReject => "geo_reject",
EdgeVerdict.BlockRate => "block_rate",
_ => "unknown"
};
}