diff --git a/doc/configuration.txt b/doc/configuration.txt index 13e136d57..93437bbd6 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -59,18 +59,22 @@ Summary 6. HTTP header manipulation -7. Using ACLs and pattern extraction -7.1. Matching integers -7.2. Matching strings -7.3. Matching regular expressions (regexes) -7.4. Matching IPv4 and IPv6 addresses -7.5. Available matching criteria -7.5.1. Matching at Layer 4 and below -7.5.2. Matching contents at Layer 4 -7.5.3. Matching at Layer 7 -7.6. Pre-defined ACLs -7.7. Using ACLs to form conditions -7.8. Pattern extraction +7. Using ACLs and fetching samples +7.1. ACL basics +7.1.1. Matching booleans +7.1.2. Matching integers +7.1.3. Matching strings +7.1.4. Matching regular expressions (regexes) +7.1.5. Matching arbitrary data blocks +7.1.6. Matching IPv4 and IPv6 addresses +7.2. Using ACLs to form conditions +7.3. Fetching samples +7.3.1. Fetching samples from internal states +7.3.2. Fetching samples at Layer 4 +7.3.3. Fetching samples at Layer 5 +7.3.4. Fetching samples from buffer contents (Layer 6) +7.3.5. Fetching HTTP samples (Layer 7) +7.4. Pre-defined ACLs 8. Logging 8.1. Log levels @@ -5903,7 +5907,7 @@ stick match [table ] [{if | unless} ] no | no | yes | yes Arguments : - is a pattern extraction rule as described in section 7.8. It + is a pattern extraction rule as described in section 7.3. It describes what elements of the incoming request or connection will be analysed in the hope to find a matching entry in a stickiness table. This rule is mandatory. @@ -6022,7 +6026,7 @@ stick store-request [table
] [{if | unless} ] no | no | yes | yes Arguments : - is a pattern extraction rule as described in section 7.8. It + is a pattern extraction rule as described in section 7.3. It describes what elements of the incoming request or connection will be analysed, extracted and stored in the table once a server is selected. @@ -6329,7 +6333,7 @@ stick store-response [table
] [{if | unless} ] no | no | yes | yes Arguments : - is a pattern extraction rule as described in section 7.8. It + is a pattern extraction rule as described in section 7.3. It describes what elements of the response or connection will be analysed, extracted and stored in the table once a server is selected. @@ -6478,7 +6482,7 @@ tcp-request connection [{if | unless} ] These actions take one or two arguments : is mandatory, and is a pattern extraction rule as described - in section 7.8. It describes what elements of the incoming + in section 7.3. It describes what elements of the incoming request or connection will be analysed, extracted, combined, and used to select which table entry to update the counters. Note that "tcp-request connection" cannot use content-based @@ -8211,22 +8215,35 @@ Notes related to these keywords : before switching. -7. Using ACLs and pattern extraction ------------------------------------- +7. Using ACLs and fetching samples +---------------------------------- + +Haproxy is capable of extracting data from request or response streams, from +client or server information, from tables, environmental information etc... +The action of extracting such data is called fetching a sample. Once retrieved, +these samples may be used for various purposes such as a key to a stick-table, +but most common usages consist in matching them against predefined constant +data called patterns. + + +7.1. ACL basics +--------------- The use of Access Control Lists (ACL) provides a flexible solution to perform content switching and generally to take decisions based on content extracted from the request, the response or any environmental status. The principle is simple : - - define test criteria with sets of values - - perform actions only if a set of tests is valid + - extract a data sample from a stream, table or the environment + - apply one or multiple pattern matching methods on this sample + - perform actions only when a pattern matches the sample -The actions generally consist in blocking the request, or selecting a backend. +The actions generally consist in blocking a request, selecting a backend, or +adding a header. In order to define a test, the "acl" keyword is used. The syntax is : - acl [flags] [operator] ... + acl [flags] [operator] [] ... This creates a new ACL or completes an existing one with new tests. Those tests apply to the portion of request/response specified in @@ -8241,38 +8258,84 @@ which means that "my_acl" and "My_Acl" are two different ACLs. There is no enforced limit to the number of ACLs. The unused ones do not affect performance, they just consume a small amount of memory. +The criterion generally is the name of a sample fetch method, or one of its ACL +specific declinations. The default test method is implied by the output type of +this sample fetch method. The ACL declinations can describe alternate matching +methods of a same sample fetch method. + +Sample fetch methods return data which can be of the following types : + - boolean + - integer (signed or unsigned) + - IPv4 or IPv6 address + - string + - data block + +The ACL engine can match these types against patterns of the following types : + - boolean + - integer or integer range + - IP address / network + - string (exact, substring, suffix, prefix, subdir, domain) + - regular expression + - hex block + The following ACL flags are currently supported : -i : ignore case during matching of all subsequent patterns. -f : load patterns from a file. - -m : changes the pattern matching method + -m : use a specific pattern matching method -- : force end of flags. Useful when a string looks like one of the flags. -The "-m" flag is special. It allows the default pattern matching method to be -changed for the fetched sample. The default method depends on the keyword and -is described later in this document. When "-m" is specified and followed by a -pattern matching method name, this method is used instead. This makes it -possible to match contents in ways that were not initially planned. There are -some restrictions however. Not all methods can be used with all sample fetch -methods. Also, if "-m" is used in conjunction with "-f", it must be placed -first. The pattern matching method must be one of the following : +The "-f" flag is followed by the name of a file from which all lines will be +read as individual values. It is even possible to pass multiple "-f" arguments +if the patterns are to be loaded from multiple files. Empty lines as well as +lines beginning with a sharp ('#') will be ignored. All leading spaces and tabs +will be stripped. If it is absolutely necessary to insert a valid pattern +beginning with a sharp, just prefix it with a space so that it is not taken for +a comment. Depending on the data type and match method, haproxy may load the +lines into a binary tree, allowing very fast lookups. This is true for IPv4 and +exact string matching. In this case, duplicates will automatically be removed. + +Also, note that the "-i" flag applies to subsequent entries and not to entries +loaded from files preceding it. For instance : + + acl valid-ua hdr(user-agent) -f exact-ua.lst -i -f generic-ua.lst test + +In this example, each line of "exact-ua.lst" will be exactly matched against +the "user-agent" header of the request. Then each line of "generic-ua" will be +case-insensitively matched. Then the word "test" will be insensitively matched +as well. + +The "-m" flag is used to select a specific pattern matching method on the input +sample. All ACL-specific criteria imply a pattern matching method and generally +do not need this flag. However, this flag is useful with generic sample fetch +methods to describe how they're going to be matched against the patterns. This +is required for sample fetches which return data type for which there is no +obvious matching method (eg: string or binary). When "-m" is specified and +followed by a pattern matching method name, this method is used instead of the +default one for the criterion. This makes it possible to match contents in ways +that were not initially planned, or with sample fetch methods which return a +string. The matching method also affects the way the patterns are parsed. + +There are some restrictions however. Not all methods can be used with all +sample fetch methods. Also, if "-m" is used in conjunction with "-f", it must +be placed first. The pattern matching method must be one of the following : - "found" : only check if the requested sample could be found in the stream, but do not compare it against any pattern. It is recommended not - to pass any pattern to avoid any confusion. This matching method - is particularly useful to detect presence of certain contents - such as headers, cookies, etc... even if they are empty and - without comparing them to anything nor counting them. + to pass any pattern to avoid confusion. This matching method is + particularly useful to detect presence of certain contents such + as headers, cookies, etc... even if they are empty and without + comparing them to anything nor counting them. - "bool" : check the value as a boolean. It can only be applied to fetches which return a boolean or integer value, and takes no pattern. - Value zero does not match, all other values do match. + Value zero or false does not match, all other values do match. - "int" : match the value as an integer. It can be used with integer and - boolean samples. + boolean samples. Boolean false is integer 0, true is integer 1. - "ip" : match the value as an IPv4 or IPv6 address. It is compatible - with IP addresse only. + with IP address samples only, so it is implied and never needed. - "bin" : match the contents against an hexadecimal string representing a binary sequence. This may be used with binary or string samples. @@ -8280,28 +8343,29 @@ first. The pattern matching method must be one of the following : - "len" : match the sample's length as an integer. This may be used with binary or string samples. - - "str" : match the contents against a string. This may be used with - binary or string samples. + - "str" : exact match : match the contents against a string. This may be + used with binary or string samples. - - "beg" : check that the contents begin like the provided string patterns. - This may be used with binary or string samples. + - "sub" : substring match : check that the contents contain at least one of + the provided string patterns. This may be used with binary or + string samples. - - "sub" : check that the contents contain at least one of the provided + - "reg" : regex match : match the contents against a list of regular + expressions. This may be used with binary or string samples. + + - "beg" : prefix match : check that the contents begin like the provided string patterns. This may be used with binary or string samples. - - "dir" : check that a slash-delimited portion of the contents exactly - match one of the provided string patterns. This may be used with - binary or string samples. + - "end" : suffix match : check that the contents end like the provided + string patterns. This may be used with binary or string samples. - - "dom" : check that a dot-delimited portion of the contents exactly - match one of the provided string patterns. This may be used with - binary or string samples. - - - "end" : check that the contents end like the provided string patterns. + - "dir" : subdir match : check that a slash-delimited portion of the + contents exactly matches one of the provided string patterns. This may be used with binary or string samples. - - "reg" : match the contents against a list of regular expressions. This - may be used with binary or string samples. + - "dom" : domain match : check that a dot-delimited portion of the contents + exactly match one of the provided string patterns. This may be + used with binary or string samples. For example, to quickly detect the presence of cookie "JSESSIONID" in an HTTP request, it is possible to do : @@ -8313,45 +8377,84 @@ buffer, one would use the following acl : acl script_tag payload(0,500) -m reg -i