Class GuardRule
java.lang.Object
org.frontcache.guard.GuardRule
A guard rule: name | condition | action.
The name is the rule's identity everywhere else - it is written to the failed-requests log as
the reason and becomes the metric in the Kibana "Frontcache Rejected Requests" dashboard.
Renaming a rule renames the metric.
-
Constructor Summary
ConstructorsConstructorDescriptionGuardRule(String name, List<GuardPredicate> predicates, GuardAction action, boolean dryRun) GuardRule(String name, List<GuardPredicate> predicates, GuardAction action, boolean dryRun, boolean onErrorAllow) GuardRule(String name, List<GuardPredicate> predicates, GuardAction action, boolean dryRun, boolean onErrorAllow, boolean trap) -
Method Summary
Modifier and TypeMethodDescriptionvoidcountHit()longgetHits()getName()booleanisDryRun()boolean| on-error=allow- see the constructor.booleanisTrap()| trap- see the constructor.logReason(RequestContext context, boolean dryRunMatch) The reason column of this rule's guard log line: the rule name (<rule>:dry-runfor a dry-run match), and the client address this node resolved as<rule>#<address>- for a rate-limit rule that refused the request, and for a trap, acted on or dry-run.booleanmatches(RequestContext context) toEntry()toString()
-
Constructor Details
-
GuardRule
-
GuardRule
public GuardRule(String name, List<GuardPredicate> predicates, GuardAction action, boolean dryRun, boolean onErrorAllow) - Parameters:
onErrorAllow- the rule sayson-error=allow: anallowrule naming a plugin's predicate, whose author accepted that the exemption does not apply when the predicate has no answer
-
GuardRule
public GuardRule(String name, List<GuardPredicate> predicates, GuardAction action, boolean dryRun, boolean onErrorAllow, boolean trap) - Parameters:
trap- the rule saystrap: a honeypot, whose hit identifies the client - it matches a client's request only (never an<fc:include>re-entering the engine, which carries the visitor's address but is the origin's page asking, not the visitor), and its log line records the address this node resolved (seelogReason(RequestContext, boolean))
-
-
Method Details
-
matches
- Returns:
- true when EVERY predicate holds (predicates are AND-ed, evaluation short-circuits) - and, for a trap, the request is a client's
-
getName
-
getPredicates
-
getAction
-
isDryRun
public boolean isDryRun() -
isOnErrorAllow
public boolean isOnErrorAllow()| on-error=allow- see the constructor. -
isTrap
public boolean isTrap()| trap- see the constructor. -
logReason
The reason column of this rule's guard log line: the rule name (<rule>:dry-runfor a dry-run match), and the client address this node resolved as<rule>#<address>- for a rate-limit rule that refused the request, and for a trap, acted on or dry-run. The address is the one the limiter counts and aclient-ip:rule matches: a forwarding header is read only from a configured trusted proxy. The log's own client-IP column is best effort - the first forwarding header, whoever wrote it - so the two CAN disagree, and for the two kinds of rule whose whole point is WHICH client, the log records the one the node would act on. "Which address was counted?" is the first question anyone debugging a 429 asks; "who fell into the trap?" is the only question a trap answers, and an address a scanner can write itself would let it frame anyone. A rate rule's dry-run line keeps the plain reason it always had. -
getHits
public long getHits() -
countHit
public void countHit() -
getCondition
-
toEntry
- Returns:
- flat, JSON-friendly snapshot of this rule for the management API and the console
-
toString
-