Class GuardRule

java.lang.Object
org.frontcache.guard.GuardRule

public class GuardRule extends Object
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 Details

    • GuardRule

      public GuardRule(String name, List<GuardPredicate> predicates, GuardAction action, boolean dryRun)
    • GuardRule

      public GuardRule(String name, List<GuardPredicate> predicates, GuardAction action, boolean dryRun, boolean onErrorAllow)
      Parameters:
      onErrorAllow - the rule says on-error=allow: an allow rule 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 says trap: 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 (see logReason(RequestContext, boolean))
  • Method Details

    • matches

      public boolean matches(RequestContext context)
      Returns:
      true when EVERY predicate holds (predicates are AND-ed, evaluation short-circuits) - and, for a trap, the request is a client's
    • getName

      public String getName()
    • getPredicates

      public List<GuardPredicate> getPredicates()
    • getAction

      public GuardAction getAction()
    • isDryRun

      public boolean isDryRun()
    • isOnErrorAllow

      public boolean isOnErrorAllow()
      | on-error=allow - see the constructor.
    • isTrap

      public boolean isTrap()
      | trap - see the constructor.
    • logReason

      public String logReason(RequestContext context, boolean dryRunMatch)
      The reason column of this rule's guard log line: the rule name (<rule>:dry-run for 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 a client-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

      public String getCondition()
    • toEntry

      public GuardRuleEntry toEntry()
      Returns:
      flat, JSON-friendly snapshot of this rule for the management API and the console
    • toString

      public String toString()
      Overrides:
      toString in class Object