Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 1 | ----------------------------------------------- |
| 2 | Stream Processing Offload Engine (SPOE) |
Christopher Faulet | 57583e4 | 2017-09-04 15:41:09 +0200 | [diff] [blame] | 3 | Version 1.2 |
Christopher Faulet | 3b78809 | 2020-05-13 08:25:12 +0200 | [diff] [blame] | 4 | ( Last update: 2020-06-13 ) |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 5 | ----------------------------------------------- |
| 6 | Author : Christopher Faulet |
| 7 | Contact : cfaulet at haproxy dot com |
| 8 | |
| 9 | |
| 10 | SUMMARY |
| 11 | -------- |
| 12 | |
| 13 | 0. Terms |
| 14 | 1. Introduction |
| 15 | 2. SPOE configuration |
| 16 | 2.1. SPOE scope |
| 17 | 2.2. "spoe-agent" section |
| 18 | 2.3. "spoe-message" section |
Christopher Faulet | 11610f3 | 2017-09-21 10:23:10 +0200 | [diff] [blame] | 19 | 2.4. "spoe-group" section |
| 20 | 2.5. Example |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 21 | 3. SPOP specification |
| 22 | 3.1. Data types |
| 23 | 3.2. Frames |
| 24 | 3.2.1. Frame capabilities |
| 25 | 3.2.2. Frame types overview |
| 26 | 3.2.3. Workflow |
| 27 | 3.2.4. Frame: HAPROXY-HELLO |
| 28 | 3.2.5. Frame: AGENT-HELLO |
| 29 | 3.2.6. Frame: NOTIFY |
| 30 | 3.2.7. Frame: ACK |
| 31 | 3.2.8. Frame: HAPROXY-DISCONNECT |
| 32 | 3.2.9. Frame: AGENT-DISCONNECT |
| 33 | 3.3. Events & messages |
| 34 | 3.4. Actions |
Christopher Faulet | d1307ce | 2017-02-27 21:59:39 +0100 | [diff] [blame] | 35 | 3.5. Errors & timeouts |
Christopher Faulet | b2dd1e0 | 2018-03-22 09:07:41 +0100 | [diff] [blame] | 36 | 4. Logging |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 37 | |
| 38 | |
| 39 | 0. Terms |
| 40 | --------- |
| 41 | |
| 42 | * SPOE : Stream Processing Offload Engine. |
| 43 | |
| 44 | A SPOE is a filter talking to servers managed ba a SPOA to offload the |
| 45 | stream processing. An engine is attached to a proxy. A proxy can have |
Christopher Faulet | d1307ce | 2017-02-27 21:59:39 +0100 | [diff] [blame] | 46 | several engines. Each engine is linked to an agent and only one. |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 47 | |
| 48 | * SPOA : Stream Processing Offload Agent. |
| 49 | |
| 50 | A SPOA is a service that will receive info from a SPOE to offload the |
| 51 | stream processing. An agent manages several servers. It uses a backend to |
| 52 | reference all of them. By extension, these servers can also be called |
| 53 | agents. |
| 54 | |
| 55 | * SPOP : Stream Processing Offload Protocol, used by SPOEs to talk to SPOA |
| 56 | servers. |
| 57 | |
| 58 | This protocol is used by engines to talk to agents. It is an in-house |
| 59 | binary protocol described in this documentation. |
| 60 | |
| 61 | |
| 62 | 1. Introduction |
| 63 | ---------------- |
| 64 | |
| 65 | SPOE is a feature introduced in HAProxy 1.7. It makes possible the |
| 66 | communication with external components to retrieve some info. The idea started |
| 67 | with the problems caused by most ldap libs not working fine in event-driven |
| 68 | systems (often at least the connect() is blocking). So, it is hard to properly |
| 69 | implement Single Sign On solution (SSO) in HAProxy. The SPOE will ease this |
| 70 | kind of processing, or we hope so. |
| 71 | |
| 72 | Now, the aim of SPOE is to allow any kind of offloading on the streams. First |
Christopher Faulet | 3b78809 | 2020-05-13 08:25:12 +0200 | [diff] [blame] | 73 | releases won't do lot of things. As we will see, there are few handled events |
| 74 | and even less actions supported. Actually, for now, the SPOE can offload the |
| 75 | processing before "tcp-request content", "tcp-response content", "http-request" |
| 76 | and "http-response" rules. And it only supports variables definition. But, in |
| 77 | spite of these limited features, we can easily imagine to implement SSO |
| 78 | solution, ip reputation or ip geolocation services. |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 79 | |
| 80 | |
| 81 | 2. SPOE configuration |
| 82 | ---------------------- |
| 83 | |
| 84 | Because SPOE is implemented as a filter, To use it, you must declare a "filter |
| 85 | spoe" line in a proxy section (frontend/backend/listen) : |
| 86 | |
| 87 | frontend my-front |
| 88 | ... |
| 89 | filter spoe [engine <name>] config <file> |
| 90 | ... |
| 91 | |
| 92 | The "config" parameter is mandatory. It specififies the SPOE configuration |
| 93 | file. The engine name is optional. It can be set to declare the scope to use in |
| 94 | the SPOE configuration. So it is possible to use the same SPOE configuration |
| 95 | for several engines. If no name is provided, the SPOE configuration must not |
| 96 | contain any scope directive. |
| 97 | |
| 98 | We use a separate configuration file on purpose. By commenting SPOE filter |
Michael Prokop | 4438c60 | 2019-05-24 10:25:45 +0200 | [diff] [blame] | 99 | line, you completely disable the feature, including the parsing of sections |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 100 | reserved to SPOE. This is also a way to keep the HAProxy configuration clean. |
| 101 | |
| 102 | A SPOE configuration file must contains, at least, the SPOA configuration |
Christopher Faulet | 11610f3 | 2017-09-21 10:23:10 +0200 | [diff] [blame] | 103 | ("spoe-agent" section) and SPOE messages/groups ("spoe-message" or "spoe-group" |
| 104 | sections) attached to this agent. |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 105 | |
| 106 | IMPORTANT : The configuration of a SPOE filter must be located in a dedicated |
| 107 | file. But the backend used by a SPOA must be declared in HAProxy configuration |
| 108 | file. |
| 109 | |
| 110 | 2.1. SPOE scope |
| 111 | ------------------------- |
| 112 | |
| 113 | If you specify an engine name on the SPOE filter line, then you need to define |
| 114 | scope in the SPOE configuration with the same name. You can have several SPOE |
| 115 | scope in the same file. In each scope, you must define one and only one |
| 116 | "spoe-agent" section to configure the SPOA linked to your SPOE and several |
Ilya Shipitsin | 2a950d0 | 2020-03-06 13:07:38 +0500 | [diff] [blame] | 117 | "spoe-message" and "spoe-group" sections to describe, respectively, messages and |
Christopher Faulet | 11610f3 | 2017-09-21 10:23:10 +0200 | [diff] [blame] | 118 | group of messages sent to servers mananged by your SPOA. |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 119 | |
| 120 | A SPOE scope starts with this kind of line : |
| 121 | |
| 122 | [<name>] |
| 123 | |
| 124 | where <name> is the same engine name specified on the SPOE filter line. The |
| 125 | scope ends when the file ends or when another scope is found. |
| 126 | |
| 127 | Example : |
| 128 | [my-first-engine] |
| 129 | spoe-agent my-agent |
| 130 | ... |
| 131 | spoe-message msg1 |
| 132 | ... |
| 133 | spoe-message msg2 |
| 134 | ... |
Christopher Faulet | b2dd1e0 | 2018-03-22 09:07:41 +0100 | [diff] [blame] | 135 | spoe-group grp1 |
Christopher Faulet | 11610f3 | 2017-09-21 10:23:10 +0200 | [diff] [blame] | 136 | ... |
Christopher Faulet | b2dd1e0 | 2018-03-22 09:07:41 +0100 | [diff] [blame] | 137 | spoe-group grp2 |
| 138 | ... |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 139 | |
| 140 | [my-second-engine] |
| 141 | ... |
| 142 | |
| 143 | If no engine name is provided on the SPOE filter line, no SPOE scope must be |
| 144 | found in the SPOE configuration file. All the file is considered to be in the |
| 145 | same anonymous and implicit scope. |
| 146 | |
Christopher Faulet | 7ee8667 | 2017-09-19 11:08:28 +0200 | [diff] [blame] | 147 | The engine name must be uniq for a proxy. If no engine name is provided on the |
Joseph Herlant | 71b4b15 | 2018-11-13 16:55:16 -0800 | [diff] [blame] | 148 | SPOE filter line, the SPOE agent name is used by default. |
Christopher Faulet | 7ee8667 | 2017-09-19 11:08:28 +0200 | [diff] [blame] | 149 | |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 150 | 2.2. "spoe-agent" section |
| 151 | -------------------------- |
| 152 | |
| 153 | For each engine, you must define one and only one "spoe-agent" section. In this |
| 154 | section, you will declare SPOE messages and the backend you will use. You will |
| 155 | also set timeouts and options to customize your agent's behaviour. |
| 156 | |
| 157 | |
| 158 | spoe-agent <name> |
| 159 | Create a new SPOA with the name <name>. It must have one and only one |
| 160 | "spoe-agent" definition by SPOE scope. |
| 161 | |
| 162 | Arguments : |
| 163 | <name> is the name of the agent section. |
| 164 | |
| 165 | following keywords are supported : |
Christopher Faulet | 11610f3 | 2017-09-21 10:23:10 +0200 | [diff] [blame] | 166 | - groups |
Christopher Faulet | 7250b8f | 2018-03-26 17:19:01 +0200 | [diff] [blame] | 167 | - log |
Christopher Faulet | 4802672 | 2016-11-16 15:01:12 +0100 | [diff] [blame] | 168 | - maxconnrate |
| 169 | - maxerrrate |
Christopher Faulet | d1307ce | 2017-02-27 21:59:39 +0100 | [diff] [blame] | 170 | - max-frame-size |
Christopher Faulet | e8ade38 | 2018-01-25 15:32:22 +0100 | [diff] [blame] | 171 | - max-waiting-frames |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 172 | - messages |
Christopher Faulet | d1307ce | 2017-02-27 21:59:39 +0100 | [diff] [blame] | 173 | - [no] option async |
Christopher Faulet | 0e0f085 | 2018-03-26 17:20:36 +0200 | [diff] [blame] | 174 | - [no] option dontlog-normal |
Christopher Faulet | d1307ce | 2017-02-27 21:59:39 +0100 | [diff] [blame] | 175 | - [no] option pipelining |
| 176 | - [no] option send-frag-payload |
Christopher Faulet | ea62c2a | 2016-11-14 10:54:21 +0100 | [diff] [blame] | 177 | - option continue-on-error |
Christopher Faulet | 336d3ef | 2017-12-22 10:00:55 +0100 | [diff] [blame] | 178 | - option force-set-var |
Christopher Faulet | 985532d | 2016-11-16 15:36:19 +0100 | [diff] [blame] | 179 | - option set-on-error |
Christopher Faulet | 36bda1c | 2018-03-22 09:08:20 +0100 | [diff] [blame] | 180 | - option set-process-time |
| 181 | - option set-total-time |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 182 | - option var-prefix |
Christopher Faulet | 336d3ef | 2017-12-22 10:00:55 +0100 | [diff] [blame] | 183 | - register-var-names |
Christopher Faulet | 03a3449 | 2016-11-19 16:47:56 +0100 | [diff] [blame] | 184 | - timeout hello|idle|processing |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 185 | - use-backend |
| 186 | |
| 187 | |
Christopher Faulet | 11610f3 | 2017-09-21 10:23:10 +0200 | [diff] [blame] | 188 | groups <grp-name> ... |
| 189 | Declare the list of SPOE groups that an agent will handle. |
| 190 | |
| 191 | Arguments : |
| 192 | <grp-name> is the name of a SPOE group. |
| 193 | |
Joseph Herlant | 71b4b15 | 2018-11-13 16:55:16 -0800 | [diff] [blame] | 194 | Groups declared here must be found in the same engine scope, else an error is |
Christopher Faulet | 11610f3 | 2017-09-21 10:23:10 +0200 | [diff] [blame] | 195 | triggered during the configuration parsing. You can have many "groups" lines. |
| 196 | |
| 197 | See also: "spoe-group" section. |
| 198 | |
| 199 | |
Christopher Faulet | 7250b8f | 2018-03-26 17:19:01 +0200 | [diff] [blame] | 200 | log global |
| 201 | log <address> [len <length>] [format <format>] <facility> [<level> [<minlevel>]] |
| 202 | no log |
| 203 | Enable per-instance logging of events and traffic. |
| 204 | |
| 205 | Prefix : |
| 206 | no should be used when the logger list must be flushed. |
| 207 | |
| 208 | See the HAProxy Configuration Manual for details about this option. |
| 209 | |
Christopher Faulet | 4802672 | 2016-11-16 15:01:12 +0100 | [diff] [blame] | 210 | maxconnrate <number> |
| 211 | Set the maximum number of connections per second to <number>. The SPOE will |
| 212 | stop to open new connections if the maximum is reached and will wait to |
| 213 | acquire an existing one. So it is important to set "timeout hello" to a |
| 214 | relatively small value. |
| 215 | |
| 216 | |
| 217 | maxerrrate <number> |
| 218 | Set the maximum number of errors per second to <number>. The SPOE will stop |
| 219 | its processing if the maximum is reached. |
| 220 | |
| 221 | |
Christopher Faulet | d1307ce | 2017-02-27 21:59:39 +0100 | [diff] [blame] | 222 | max-frame-size <number> |
| 223 | Set the maximum allowed size for frames exchanged between HAProxy and SPOA. |
| 224 | It must be in the range [256, tune.bufsize-4] (4 bytes are reserved for the |
| 225 | frame length). By default, it is set to (tune.bufsize-4). |
| 226 | |
Christopher Faulet | e8ade38 | 2018-01-25 15:32:22 +0100 | [diff] [blame] | 227 | max-waiting-frames <number> |
| 228 | Set the maximum number of frames waiting for an acknowledgement on the same |
| 229 | connection. This value is only used when the pipelinied or asynchronus |
| 230 | exchanges between HAProxy and SPOA are enabled. By default, it is set to 20. |
Christopher Faulet | d1307ce | 2017-02-27 21:59:39 +0100 | [diff] [blame] | 231 | |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 232 | messages <msg-name> ... |
| 233 | Declare the list of SPOE messages that an agent will handle. |
| 234 | |
| 235 | Arguments : |
| 236 | <msg-name> is the name of a SPOE message. |
| 237 | |
| 238 | Messages declared here must be found in the same engine scope, else an error |
| 239 | is triggered during the configuration parsing. You can have many "messages" |
| 240 | lines. |
| 241 | |
| 242 | See also: "spoe-message" section. |
| 243 | |
| 244 | |
Christopher Faulet | d1307ce | 2017-02-27 21:59:39 +0100 | [diff] [blame] | 245 | option async |
| 246 | no option async |
| 247 | Enable or disable the support of asynchronus exchanges between HAProxy and |
| 248 | SPOA. By default, this option is enabled. |
| 249 | |
| 250 | |
Christopher Faulet | ea62c2a | 2016-11-14 10:54:21 +0100 | [diff] [blame] | 251 | option continue-on-error |
| 252 | Do not stop the events processing when an error occurred on a stream. |
| 253 | |
| 254 | By default, for a specific stream, when an abnormal/unexpected error occurs, |
| 255 | the SPOE is disabled for all the transaction. So if you have several events |
| 256 | configured, such error on an event will disabled all followings. For TCP |
| 257 | streams, this will disable the SPOE for the whole session. For HTTP streams, |
| 258 | this will disable it for the transaction (request and response). |
| 259 | |
| 260 | When set, this option bypass this behaviour and only the current event will |
| 261 | be ignored. |
| 262 | |
Christopher Faulet | 0e0f085 | 2018-03-26 17:20:36 +0200 | [diff] [blame] | 263 | |
| 264 | option dontlog-normal |
| 265 | no option dontlog-normal |
| 266 | Enable or disable logging of normal, successful processing. |
| 267 | |
| 268 | Arguments : none |
| 269 | |
| 270 | See also: "log" and section 4 about logging. |
| 271 | |
| 272 | |
Etienne Carriere | aec8989 | 2017-12-14 09:36:40 +0000 | [diff] [blame] | 273 | option force-set-var |
| 274 | By default, SPOE filter only register already known variables (mainly from |
| 275 | parsing of the configuration). If you want that haproxy trusts the agent and |
| 276 | registers all variables (ex: can be useful for LUA workload), activate this |
| 277 | option. |
| 278 | |
| 279 | Caution : this option opens to a variety of attacks such as a rogue SPOA that |
| 280 | asks to register too many variables. |
| 281 | |
Christopher Faulet | ea62c2a | 2016-11-14 10:54:21 +0100 | [diff] [blame] | 282 | |
Christopher Faulet | d1307ce | 2017-02-27 21:59:39 +0100 | [diff] [blame] | 283 | option pipelining |
| 284 | no option pipelining |
| 285 | Enable or disable the support of pipelined exchanges between HAProxy and |
| 286 | SPOA. By default, this option is enabled. |
| 287 | |
| 288 | |
| 289 | option send-frag-payload |
| 290 | no option send-frag-payload |
| 291 | Enable or disable the sending of fragmented payload to SPOA. By default, this |
| 292 | option is enabled. |
| 293 | |
| 294 | |
Christopher Faulet | 985532d | 2016-11-16 15:36:19 +0100 | [diff] [blame] | 295 | option set-on-error <var name> |
| 296 | Define the variable to set when an error occurred during an event processing. |
| 297 | |
| 298 | Arguments : |
| 299 | |
| 300 | <var name> is the variable name, without the scope. The name may only |
| 301 | contain characters 'a-z', 'A-Z', '0-9', '.' and '_'. |
| 302 | |
| 303 | This variable will only be set when an error occurred in the scope of the |
| 304 | transaction. As for all other variables define by the SPOE, it will be |
| 305 | prefixed. So, if your variable name is "error" and your prefix is |
| 306 | "my_spoe_pfx", the variable will be "txn.my_spoe_pfx.error". |
| 307 | |
Christopher Faulet | b067b06 | 2017-01-04 16:39:11 +0100 | [diff] [blame] | 308 | When set, the variable is an integer representing the error reason. For values |
| 309 | under 256, it represents an error coming from the engine. Below 256, it |
| 310 | reports a SPOP error. In this case, to retrieve the right SPOP status code, |
| 311 | you must remove 256 to this value. Here are possible values: |
| 312 | |
| 313 | * 1 a timeout occurred during the event processing. |
| 314 | |
Michael Prokop | 4438c60 | 2019-05-24 10:25:45 +0200 | [diff] [blame] | 315 | * 2 an error was triggered during the resources allocation. |
Christopher Faulet | b067b06 | 2017-01-04 16:39:11 +0100 | [diff] [blame] | 316 | |
Christopher Faulet | d1307ce | 2017-02-27 21:59:39 +0100 | [diff] [blame] | 317 | * 3 the frame payload exceeds the frame size and it cannot be |
| 318 | fragmented. |
| 319 | |
| 320 | * 4 the fragmentation of a payload is aborted. |
| 321 | |
Christopher Faulet | 344c4ab | 2017-09-22 10:20:13 +0200 | [diff] [blame] | 322 | * 5 The frame processing has been interrupted by HAProxy. |
| 323 | |
Christopher Faulet | b067b06 | 2017-01-04 16:39:11 +0100 | [diff] [blame] | 324 | * 255 an unknown error occurred during the event processing. |
| 325 | |
| 326 | * 256+N a SPOP error occurred during the event processing (see section |
| 327 | "Errors & timeouts"). |
| 328 | |
| 329 | Note that if "option continue-on-error" is set, the variable is not |
| 330 | automatically removed between events processing. |
Christopher Faulet | 985532d | 2016-11-16 15:36:19 +0100 | [diff] [blame] | 331 | |
| 332 | See also: "option continue-on-error", "option var-prefix". |
| 333 | |
Christopher Faulet | 36bda1c | 2018-03-22 09:08:20 +0100 | [diff] [blame] | 334 | |
| 335 | option set-process-time <var name> |
| 336 | Define the variable to set to report the processing time of the last event or |
| 337 | group. |
| 338 | |
| 339 | Arguments : |
| 340 | |
| 341 | <var name> is the variable name, without the scope. The name may only |
| 342 | contain characters 'a-z', 'A-Z', '0-9', '.' and '_'. |
| 343 | |
| 344 | This variable will be set in the scope of the transaction. As for all other |
| 345 | variables define by the SPOE, it will be prefixed. So, if your variable name |
| 346 | is "process_time" and your prefix is "my_spoe_pfx", the variable will be |
| 347 | "txn.my_spoe_pfx.process_time". |
| 348 | |
| 349 | When set, the variable is an integer representing the delay to process the |
| 350 | event or the group, in milliseconds. From the stream point of view, it is the |
| 351 | latency added by the SPOE processing for the last handled event or group. |
| 352 | |
| 353 | If several events or groups are processed for the same stream, this value |
| 354 | will be overrideen. |
| 355 | |
| 356 | See also: "option set-total-time". |
| 357 | |
| 358 | |
| 359 | option set-total-time <var name> |
| 360 | Define the variable to set to report the total processing time SPOE for a |
| 361 | stream. |
| 362 | |
| 363 | Arguments : |
| 364 | |
| 365 | <var name> is the variable name, without the scope. The name may only |
| 366 | contain characters 'a-z', 'A-Z', '0-9', '.' and '_'. |
| 367 | |
| 368 | This variable will be set in the scope of the transaction. As for all other |
| 369 | variables define by the SPOE, it will be prefixed. So, if your variable name |
| 370 | is "total_time" and your prefix is "my_spoe_pfx", the variable will be |
| 371 | "txn.my_spoe_pfx.total_time". |
| 372 | |
| 373 | When set, the variable is an integer representing the sum of processing times |
| 374 | for a stream, in milliseconds. From the stream point of view, it is the |
| 375 | latency added by the SPOE processing. |
| 376 | |
| 377 | If several events or groups are processed for the same stream, this value |
| 378 | will be updated. |
| 379 | |
| 380 | See also: "option set-process-time". |
| 381 | |
| 382 | |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 383 | option var-prefix <prefix> |
| 384 | Define the prefix used when variables are set by an agent. |
| 385 | |
| 386 | Arguments : |
| 387 | |
| 388 | <prefix> is the prefix used to limit the scope of variables set by an |
| 389 | agent. |
| 390 | |
| 391 | To avoid conflict with other variables defined by HAProxy, all variables |
| 392 | names will be prefixed. By default, the "spoe-agent" name is used. This |
| 393 | option can be used to customize it. |
| 394 | |
| 395 | The prefix will be added between the variable scope and its name, separated |
| 396 | by a '.'. It may only contain characters 'a-z', 'A-Z', '0-9', '.' and '_', as |
| 397 | for variables name. In HAProxy configuration, you need to use this prefix as |
| 398 | a part of the variables name. For example, if an agent define the variable |
| 399 | "myvar" in the "txn" scope, with the prefix "my_spoe_pfx", then you should |
| 400 | use "txn.my_spoe_pfx.myvar" name in your HAProxy configuration. |
| 401 | |
Etienne Carriere | aec8989 | 2017-12-14 09:36:40 +0000 | [diff] [blame] | 402 | By default, an agent will never set new variables at runtime: It can only set |
| 403 | new value for existing ones. If you want a different behaviour, see |
Christopher Faulet | 336d3ef | 2017-12-22 10:00:55 +0100 | [diff] [blame] | 404 | force-set-var option and register-var-names directive. |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 405 | |
Christopher Faulet | 336d3ef | 2017-12-22 10:00:55 +0100 | [diff] [blame] | 406 | register-var-names <var name> ... |
| 407 | Register some variable names. By default, an agent will not be allowed to set |
| 408 | new variables at runtime. This rule can be totally relaxed by setting the |
| 409 | option "force-set-var". If you know all the variables you will need, this |
| 410 | directive is a good way to register them without letting an agent doing what |
| 411 | it want. This is only required if these variables are not referenced anywhere |
| 412 | in the HAProxy configuration or the SPOE one. |
| 413 | |
| 414 | Arguments: |
| 415 | <var name> is a variable name without the scope. The name may only |
| 416 | contain characters 'a-z', 'A-Z', '0-9', '.' and '_'. |
| 417 | |
| 418 | The prefix will be automatically added during the registration. You can have |
| 419 | many "register-var-names" lines. |
| 420 | |
| 421 | See also: "option force-set-var", "option var-prefix". |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 422 | |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 423 | timeout hello <timeout> |
| 424 | Set the maximum time to wait for an agent to receive the AGENT-HELLO frame. |
Christopher Faulet | f7a3092 | 2016-11-10 15:04:51 +0100 | [diff] [blame] | 425 | It is applied on the stream that handle the connection with the agent. |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 426 | |
| 427 | Arguments : |
| 428 | <timeout> is the timeout value specified in milliseconds by default, but |
| 429 | can be in any other unit if the number is suffixed by the unit, |
| 430 | as explained at the top of this document. |
| 431 | |
| 432 | This timeout is an applicative timeout. It differ from "timeout connect" |
| 433 | defined on backends. |
| 434 | |
| 435 | |
| 436 | timeout idle <timeout> |
Christopher Faulet | f7a3092 | 2016-11-10 15:04:51 +0100 | [diff] [blame] | 437 | Set the maximum time to wait for an agent to close an idle connection. It is |
| 438 | applied on the stream that handle the connection with the agent. |
| 439 | |
| 440 | Arguments : |
| 441 | <timeout> is the timeout value specified in milliseconds by default, but |
| 442 | can be in any other unit if the number is suffixed by the unit, |
| 443 | as explained at the top of this document. |
| 444 | |
| 445 | |
| 446 | timeout processing <timeout> |
| 447 | Set the maximum time to wait for a stream to process an event, i.e to acquire |
| 448 | a stream to talk with an agent, to encode all messages, to send the NOTIFY |
| 449 | frame, to receive the corrsponding acknowledgement and to process all |
| 450 | actions. It is applied on the stream that handle the client and the server |
| 451 | sessions. |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 452 | |
| 453 | Arguments : |
| 454 | <timeout> is the timeout value specified in milliseconds by default, but |
| 455 | can be in any other unit if the number is suffixed by the unit, |
| 456 | as explained at the top of this document. |
| 457 | |
| 458 | |
| 459 | use-backend <backend> |
| 460 | Specify the backend to use. It must be defined. |
| 461 | |
| 462 | Arguments : |
| 463 | <backend> is the name of a valid "backend" section. |
| 464 | |
| 465 | |
| 466 | 2.3. "spoe-message" section |
| 467 | ---------------------------- |
| 468 | |
| 469 | To offload the stream processing, SPOE will send messages with specific |
| 470 | information at a specific moment in the stream life and will wait for |
| 471 | corresponding replies to know what to do. |
| 472 | |
| 473 | |
| 474 | spoe-message <name> |
| 475 | Create a new SPOE message with the name <name>. |
| 476 | |
| 477 | Arguments : |
| 478 | <name> is the name of the SPOE message. |
| 479 | |
| 480 | Here you define a message that can be referenced in a "spoe-agent" |
| 481 | section. Following keywords are supported : |
Christopher Faulet | 57583e4 | 2017-09-04 15:41:09 +0200 | [diff] [blame] | 482 | - acl |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 483 | - args |
| 484 | - event |
| 485 | |
| 486 | See also: "spoe-agent" section. |
| 487 | |
| 488 | |
Christopher Faulet | 57583e4 | 2017-09-04 15:41:09 +0200 | [diff] [blame] | 489 | acl <aclname> <criterion> [flags] [operator] <value> ... |
Christopher Faulet | 57583e4 | 2017-09-04 15:41:09 +0200 | [diff] [blame] | 490 | Declare or complete an access list. |
| 491 | |
| 492 | See section 7 about ACL usage in the HAProxy Configuration Manual. |
| 493 | |
| 494 | |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 495 | args [name=]<sample> ... |
| 496 | Define arguments passed into the SPOE message. |
| 497 | |
| 498 | Arguments : |
| 499 | <sample> is a sample expression. |
| 500 | |
| 501 | When the message is processed, if a sample expression is not available, it is |
| 502 | set to NULL. Arguments are processed in their declaration order and added in |
Joseph Herlant | 71b4b15 | 2018-11-13 16:55:16 -0800 | [diff] [blame] | 503 | the message in that order. It is possible to declare named arguments. |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 504 | |
| 505 | For example: |
| 506 | args frontend=fe_id src dst |
| 507 | |
| 508 | |
Christopher Faulet | 57583e4 | 2017-09-04 15:41:09 +0200 | [diff] [blame] | 509 | event <name> [ { if | unless } <condition> ] |
| 510 | Set the event that triggers sending of the message. It may optionally be |
| 511 | followed by an ACL-based condition, in which case it will only be evaluated |
| 512 | if the condition is true. |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 513 | |
Christopher Faulet | 57583e4 | 2017-09-04 15:41:09 +0200 | [diff] [blame] | 514 | ACL-based conditions are executed in the context of the stream that handle |
| 515 | the client and the server connections. |
| 516 | |
| 517 | Arguments : |
| 518 | <name> is the event name. |
| 519 | <condition> is a standard ACL-based condition. |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 520 | |
| 521 | Supported events are: |
| 522 | - on-client-session |
Christopher Faulet | 1002aac | 2016-12-09 17:41:54 +0100 | [diff] [blame] | 523 | - on-server-session |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 524 | - on-frontend-tcp-request |
| 525 | - on-backend-tcp-request |
| 526 | - on-tcp-response |
| 527 | - on-frontend-http-request |
| 528 | - on-backend-http-request |
| 529 | - on-http-response |
| 530 | |
Christopher Faulet | 57583e4 | 2017-09-04 15:41:09 +0200 | [diff] [blame] | 531 | See section "Events & Messages" for more details about supported events. |
| 532 | See section 7 about ACL usage in the HAProxy Configuration Manual. |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 533 | |
Christopher Faulet | 11610f3 | 2017-09-21 10:23:10 +0200 | [diff] [blame] | 534 | 2.4. "spoe-group" section |
| 535 | -------------------------- |
| 536 | |
| 537 | This section can be used to declare a group of SPOE messages. Unlike messages |
| 538 | referenced in a "spoe-agent" section, messages inside a group are not sent on a |
| 539 | specific event. The sending must be triggered by TCP or HTTP rules, from the |
| 540 | HAProxy configuration. |
| 541 | |
| 542 | |
| 543 | spoe-group <name> |
| 544 | Create a new SPOE group with the name <name>. |
| 545 | |
| 546 | Arguments : |
| 547 | <name> is the name of the SPOE group. |
| 548 | |
| 549 | Here you define a group of SPOE messages that can be referenced in a |
| 550 | "spoe-agent" section. Following keywords are supported : |
| 551 | - messages |
| 552 | |
| 553 | See also: "spoe-agent" and "spoe-message" sections. |
| 554 | |
| 555 | |
| 556 | messages <msg-name> ... |
| 557 | Declare the list of SPOE messages belonging to the group. |
| 558 | |
| 559 | Arguments : |
| 560 | <msg-name> is the name of a SPOE message. |
| 561 | |
| 562 | Messages declared here must be found in the same engine scope, else an error |
| 563 | is triggered during the configuration parsing. Furthermore, a message belongs |
| 564 | at most to a group. You can have many "messages" lines. |
| 565 | |
| 566 | See also: "spoe-message" section. |
| 567 | |
| 568 | |
| 569 | 2.5. Example |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 570 | ------------- |
| 571 | |
| 572 | Here is a simple but complete example that sends client-ip address to a ip |
| 573 | reputation service. This service can set the variable "ip_score" which is an |
| 574 | integer between 0 and 100, indicating its reputation (100 means totally safe |
| 575 | and 0 a blacklisted IP with no doubt). |
| 576 | |
| 577 | ### |
| 578 | ### HAProxy configuration |
| 579 | frontend www |
| 580 | mode http |
| 581 | bind *:80 |
| 582 | |
| 583 | filter spoe engine ip-reputation config spoe-ip-reputation.conf |
| 584 | |
| 585 | # Reject connection if the IP reputation is under 20 |
| 586 | tcp-request content reject if { var(sess.iprep.ip_score) -m int lt 20 } |
| 587 | |
| 588 | default_backend http-servers |
| 589 | |
| 590 | backend http-servers |
| 591 | mode http |
| 592 | server http A.B.C.D:80 |
| 593 | |
| 594 | backend iprep-servers |
| 595 | mode tcp |
| 596 | balance roundrobin |
| 597 | |
| 598 | timeout connect 5s # greater than hello timeout |
| 599 | timeout server 3m # greater than idle timeout |
| 600 | |
| 601 | server iprep1 A1.B1.C1.D1:12345 |
| 602 | server iprep2 A2.B2.C2.D2:12345 |
| 603 | |
| 604 | #### |
| 605 | ### spoe-ip-reputation.conf |
| 606 | [ip-reputation] |
| 607 | |
| 608 | spoe-agent iprep-agent |
| 609 | messages get-ip-reputation |
| 610 | |
| 611 | option var-prefix iprep |
| 612 | |
Christopher Faulet | 03a3449 | 2016-11-19 16:47:56 +0100 | [diff] [blame] | 613 | timeout hello 2s |
| 614 | timeout idle 2m |
| 615 | timeout processing 10ms |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 616 | |
| 617 | use-backend iprep-servers |
| 618 | |
| 619 | spoe-message get-ip-reputation |
| 620 | args ip=src |
Christopher Faulet | 57583e4 | 2017-09-04 15:41:09 +0200 | [diff] [blame] | 621 | event on-client-session if ! { src -f /etc/haproxy/whitelist.lst } |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 622 | |
| 623 | |
| 624 | 3. SPOP specification |
| 625 | ---------------------- |
| 626 | |
| 627 | 3.1. Data types |
| 628 | ---------------- |
| 629 | |
| 630 | Here is the bytewise representation of typed data: |
| 631 | |
| 632 | TYPED-DATA : <TYPE:4 bits><FLAGS:4 bits><DATA> |
| 633 | |
| 634 | Supported types and their representation are: |
| 635 | |
| 636 | TYPE | ID | DESCRIPTION |
| 637 | -----------------------------+-----+---------------------------------- |
| 638 | NULL | 0 | NULL : <0> |
| 639 | Boolean | 1 | BOOL : <1+FLAG> |
| 640 | 32bits signed integer | 2 | INT32 : <2><VALUE:varint> |
| 641 | 32bits unsigned integer | 3 | UINT32 : <3><VALUE:varint> |
| 642 | 64bits signed integer | 4 | INT64 : <4><VALUE:varint> |
| 643 | 32bits unsigned integer | 5 | UNIT64 : <5><VALUE:varint> |
| 644 | IPV4 | 6 | IPV4 : <6><STRUCT IN_ADDR:4 bytes> |
| 645 | IPV6 | 7 | IPV6 : <7><STRUCT IN_ADDR6:16 bytes> |
| 646 | String | 8 | STRING : <8><LENGTH:varint><BYTES> |
| 647 | Binary | 9 | BINARY : <9><LENGTH:varint><BYTES> |
| 648 | 10 -> 15 unused/reserved | - | - |
| 649 | -----------------------------+-----+---------------------------------- |
| 650 | |
| 651 | Variable-length integer (varint) are encoded using Peers encoding: |
| 652 | |
| 653 | |
| 654 | 0 <= X < 240 : 1 byte (7.875 bits) [ XXXX XXXX ] |
| 655 | 240 <= X < 2288 : 2 bytes (11 bits) [ 1111 XXXX ] [ 0XXX XXXX ] |
| 656 | 2288 <= X < 264432 : 3 bytes (18 bits) [ 1111 XXXX ] [ 1XXX XXXX ] [ 0XXX XXXX ] |
| 657 | 264432 <= X < 33818864 : 4 bytes (25 bits) [ 1111 XXXX ] [ 1XXX XXXX ]*2 [ 0XXX XXXX ] |
| 658 | 33818864 <= X < 4328786160 : 5 bytes (32 bits) [ 1111 XXXX ] [ 1XXX XXXX ]*3 [ 0XXX XXXX ] |
| 659 | ... |
| 660 | |
| 661 | For booleans, the value (true or false) is the first bit in the FLAGS |
| 662 | bitfield. if this bit is set to 0, then the boolean is evaluated as false, |
| 663 | otherwise, the boolean is evaluated as true. |
| 664 | |
| 665 | 3.2. Frames |
| 666 | ------------ |
| 667 | |
| 668 | Exchange between HAProxy and agents are made using FRAME packets. All frames |
| 669 | must be prefixed with their size encoded on 4 bytes in network byte order: |
| 670 | |
| 671 | <FRAME-LENGTH:4 bytes> <FRAME> |
| 672 | |
| 673 | A frame always starts with its type, on one byte, followed by metadata |
| 674 | containing flags, on 4 bytes and a two variable-length integer representing the |
| 675 | stream identifier and the frame identifier inside the stream: |
| 676 | |
| 677 | FRAME : <FRAME-TYPE:1 byte> <METADATA> <FRAME-PAYLOAD> |
| 678 | METADATA : <FLAGS:4 bytes> <STREAM-ID:varint> <FRAME-ID:varint> |
| 679 | |
| 680 | Then comes the frame payload. Depending on the frame type, the payload can be |
| 681 | of three types: a simple key/value list, a list of messages or a list of |
| 682 | actions. |
| 683 | |
| 684 | FRAME-PAYLOAD : <LIST-OF-MESSAGES> | <LIST-OF-ACTIONS> | <KV-LIST> |
| 685 | |
| 686 | LIST-OF-MESSAGES : [ <MESSAGE-NAME> <NB-ARGS:1 byte> <KV-LIST> ... ] |
| 687 | MESSAGE-NAME : <STRING> |
| 688 | |
| 689 | LIST-OF-ACTIONS : [ <ACTION-TYPE:1 byte> <NB-ARGS:1 byte> <ACTION-ARGS> ... ] |
| 690 | ACTION-ARGS : [ <TYPED-DATA>... ] |
| 691 | |
| 692 | KV-LIST : [ <KV-NAME> <KV-VALUE> ... ] |
| 693 | KV-NAME : <STRING> |
| 694 | KV-VALUE : <TYPED-DATA> |
| 695 | |
Thierry FOURNIER | c4dcaff | 2018-05-18 12:25:39 +0200 | [diff] [blame] | 696 | FLAGS : |
| 697 | |
| 698 | Flags are a 32 bits field. They are encoded on 4 bytes in network byte |
| 699 | order, where the bit 0 is the LSB. |
| 700 | |
| 701 | 0 1 2-31 |
Christopher Faulet | d1307ce | 2017-02-27 21:59:39 +0100 | [diff] [blame] | 702 | +---+---+----------+ |
| 703 | | | A | | |
| 704 | | F | B | | |
| 705 | | I | O | RESERVED | |
| 706 | | N | R | | |
| 707 | | | T | | |
| 708 | +---+---+----------+ |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 709 | |
| 710 | FIN: Indicates that this is the final payload fragment. The first fragment |
| 711 | may also be the final fragment. |
| 712 | |
Christopher Faulet | d1307ce | 2017-02-27 21:59:39 +0100 | [diff] [blame] | 713 | ABORT: Indicates that the processing of the current frame must be |
| 714 | cancelled. This bit should be set on frames with a fragmented |
| 715 | payload. It can be ignore for frames with an unfragemnted |
| 716 | payload. When it is set, the FIN bit must also be set. |
| 717 | |
| 718 | |
Joseph Herlant | 71b4b15 | 2018-11-13 16:55:16 -0800 | [diff] [blame] | 719 | Frames cannot exceed a maximum size negotiated between HAProxy and agents |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 720 | during the HELLO handshake. Most of time, payload will be small enough to send |
| 721 | it in one frame. But when supported by the peer, it will be possible to |
| 722 | fragment huge payload on many frames. This ability is announced during the |
| 723 | HELLO handshake and it can be asynmetric (supported by agents but not by |
| 724 | HAProxy or the opposite). The following rules apply to fragmentation: |
| 725 | |
| 726 | * An unfragemnted payload consists of a single frame with the FIN bit set. |
| 727 | |
| 728 | * A fragemented payload consists of several frames with the FIN bit clear and |
| 729 | terminated by a single frame with the FIN bit set. All these frames must |
Christopher Faulet | d1307ce | 2017-02-27 21:59:39 +0100 | [diff] [blame] | 730 | share the same STREAM-ID and FRAME-ID. The first frame must set the right |
| 731 | FRAME-TYPE (e.g, NOTIFY). The following frames must have an unset type (0). |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 732 | |
| 733 | Beside the support of fragmented payload by a peer, some payload must not be |
| 734 | fragmented. See below for details. |
| 735 | |
Christopher Faulet | d1307ce | 2017-02-27 21:59:39 +0100 | [diff] [blame] | 736 | IMPORTANT : The maximum size supported by peers for a frame must be greater |
| 737 | than or equal to 256 bytes. |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 738 | |
| 739 | 3.2.1. Frame capabilities |
| 740 | -------------------------- |
| 741 | |
| 742 | Here are the list of official capabilities that HAProxy and agents can support: |
| 743 | |
Christopher Faulet | a1cda02 | 2016-12-21 08:58:06 +0100 | [diff] [blame] | 744 | * fragmentation: This is the ability for a peer to support fragmented |
| 745 | payload in received frames. This is an asymmectical |
| 746 | capability, it only concerns the peer that announces |
| 747 | it. This is the responsibility to the other peer to use it |
| 748 | or not. |
| 749 | |
| 750 | * pipelining: This is the ability for a peer to decouple NOTIFY and ACK |
| 751 | frames. This is a symmectical capability. To be used, it must |
| 752 | be supported by HAproxy and agents. Unlike HTTP pipelining, the |
| 753 | ACK frames can be send in any order, but always on the same TCP |
| 754 | connection used for the corresponding NOTIFY frame. |
| 755 | |
| 756 | * async: This ability is similar to the pipelining, but here any TCP |
| 757 | connection established between HAProxy and the agent can be used to |
| 758 | send ACK frames. if an agent accepts connections from multiple |
| 759 | HAProxy, it can use the "engine-id" value to group TCP |
| 760 | connections. See details about HAPROXY-HELLO frame. |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 761 | |
| 762 | Unsupported or unknown capabilities are silently ignored, when possible. |
| 763 | |
| 764 | 3.2.2. Frame types overview |
| 765 | ---------------------------- |
| 766 | |
| 767 | Here are types of frame supported by SPOE. Frames sent by HAProxy come first, |
| 768 | then frames sent by agents : |
| 769 | |
| 770 | TYPE | ID | DESCRIPTION |
| 771 | -----------------------------+-----+------------------------------------- |
Christopher Faulet | d1307ce | 2017-02-27 21:59:39 +0100 | [diff] [blame] | 772 | UNSET | 0 | Used for all frames but the first when a |
| 773 | | | payload is fragmented. |
| 774 | -----------------------------+-----+------------------------------------- |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 775 | HAPROXY-HELLO | 1 | Sent by HAProxy when it opens a |
| 776 | | | connection on an agent. |
| 777 | | | |
| 778 | HAPROXY-DISCONNECT | 2 | Sent by HAProxy when it want to close |
| 779 | | | the connection or in reply to an |
| 780 | | | AGENT-DISCONNECT frame |
| 781 | | | |
| 782 | NOTIFY | 3 | Sent by HAProxy to pass information |
| 783 | | | to an agent |
| 784 | -----------------------------+-----+------------------------------------- |
| 785 | AGENT-HELLO | 101 | Reply to a HAPROXY-HELLO frame, when |
| 786 | | | the connection is established |
| 787 | | | |
| 788 | AGENT-DISCONNECT | 102 | Sent by an agent just before closing |
| 789 | | | the connection |
| 790 | | | |
| 791 | ACK | 103 | Sent to acknowledge a NOTIFY frame |
| 792 | -----------------------------+-----+------------------------------------- |
| 793 | |
| 794 | Unknown frames may be silently skipped. |
| 795 | |
| 796 | 3.2.3. Workflow |
| 797 | ---------------- |
| 798 | |
| 799 | * Successful HELLO handshake: |
| 800 | |
| 801 | HAPROXY AGENT SRV |
| 802 | | HAPROXY-HELLO | |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 803 | | (healthcheck: false) | |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 804 | | --------------------------> | |
| 805 | | | |
| 806 | | AGENT-HELLO | |
| 807 | | <-------------------------- | |
| 808 | | | |
| 809 | |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 810 | * Successful HELLO healthcheck: |
| 811 | |
| 812 | HAPROXY AGENT SRV |
| 813 | | HAPROXY-HELLO | |
| 814 | | (healthcheck: true) | |
| 815 | | --------------------------> | |
| 816 | | | |
| 817 | | AGENT-HELLO + close() | |
| 818 | | <-------------------------- | |
| 819 | | | |
| 820 | |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 821 | |
| 822 | * Error encountered by agent during the HELLO handshake: |
| 823 | |
| 824 | HAPROXY AGENT SRV |
| 825 | | HAPROXY-HELLO | |
| 826 | | --------------------------> | |
| 827 | | | |
| 828 | | DISCONNECT + close() | |
| 829 | | <-------------------------- | |
| 830 | | | |
| 831 | |
| 832 | * Error encountered by HAProxy during the HELLO handshake: |
| 833 | |
| 834 | HAPROXY AGENT SRV |
| 835 | | HAPROXY-HELLO | |
| 836 | | --------------------------> | |
| 837 | | | |
| 838 | | AGENT-HELLO | |
| 839 | | <-------------------------- | |
| 840 | | | |
| 841 | | DISCONNECT | |
| 842 | | --------------------------> | |
| 843 | | | |
| 844 | | DISCONNECT + close() | |
| 845 | | <-------------------------- | |
| 846 | | | |
| 847 | |
Christopher Faulet | d1307ce | 2017-02-27 21:59:39 +0100 | [diff] [blame] | 848 | * Notify / Ack exchange (unfragmented payload): |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 849 | |
| 850 | HAPROXY AGENT SRV |
| 851 | | NOTIFY | |
| 852 | | --------------------------> | |
| 853 | | | |
| 854 | | ACK | |
| 855 | | <-------------------------- | |
| 856 | | | |
| 857 | |
Christopher Faulet | d1307ce | 2017-02-27 21:59:39 +0100 | [diff] [blame] | 858 | * Notify / Ack exchange (fragmented payload): |
| 859 | |
| 860 | HAPROXY AGENT SRV |
| 861 | | NOTIFY (frag 1) | |
| 862 | | --------------------------> | |
| 863 | | | |
| 864 | | UNSET (frag 2) | |
| 865 | | --------------------------> | |
| 866 | | ... | |
| 867 | | UNSET (frag N) | |
| 868 | | --------------------------> | |
| 869 | | | |
| 870 | | ACK | |
| 871 | | <-------------------------- | |
| 872 | | | |
| 873 | |
| 874 | * Aborted fragmentation of a NOTIFY frame: |
| 875 | |
| 876 | HAPROXY AGENT SRV |
| 877 | | ... | |
| 878 | | UNSET (frag X) | |
| 879 | | --------------------------> | |
| 880 | | | |
| 881 | | ACK/ABORT | |
| 882 | | <-------------------------- | |
| 883 | | | |
| 884 | | UNSET (frag X+1) | |
| 885 | | -----------X | |
| 886 | | | |
| 887 | | | |
| 888 | |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 889 | * Connection closed by haproxy: |
| 890 | |
| 891 | HAPROXY AGENT SRV |
| 892 | | DISCONNECT | |
| 893 | | --------------------------> | |
| 894 | | | |
| 895 | | DISCONNECT + close() | |
| 896 | | <-------------------------- | |
| 897 | | | |
| 898 | |
| 899 | * Connection closed by agent: |
| 900 | |
| 901 | HAPROXY AGENT SRV |
| 902 | | DISCONNECT + close() | |
| 903 | | <-------------------------- | |
| 904 | | | |
| 905 | |
| 906 | 3.2.4. Frame: HAPROXY-HELLO |
| 907 | ---------------------------- |
| 908 | |
| 909 | This frame is the first one exchanged between HAProxy and an agent, when the |
| 910 | connection is established. The payload of this frame is a KV-LIST. It cannot be |
| 911 | fragmented. STREAM-ID and FRAME-ID are must be set 0. |
| 912 | |
| 913 | Following items are mandatory in the KV-LIST: |
| 914 | |
| 915 | * "supported-versions" <STRING> |
| 916 | |
| 917 | Last SPOP major versions supported by HAProxy. It is a comma-separated list |
| 918 | of versions, following the format "Major.Minor". Spaces must be ignored, if |
| 919 | any. When a major version is announced by HAProxy, it means it also support |
| 920 | all previous minor versions. |
| 921 | |
| 922 | Example: "2.0, 1.5" means HAProxy supports SPOP 2.0 and 1.0 to 1.5 |
| 923 | |
| 924 | * "max-frame-size" <UINT32> |
| 925 | |
| 926 | This is the maximum size allowed for a frame. The HAPROXY-HELLO frame must |
| 927 | be lower or equal to this value. |
| 928 | |
| 929 | * "capabilities" <STRING> |
| 930 | |
| 931 | This a comma-separated list of capabilities supported by HAProxy. Spaces |
| 932 | must be ignored, if any. |
| 933 | |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 934 | Following optional items can be added in the KV-LIST: |
| 935 | |
| 936 | * "healthcheck" <BOOLEAN> |
| 937 | |
| 938 | If this item is set to TRUE, then the HAPROXY-HELLO frame is sent during a |
| 939 | SPOE health check. When set to FALSE, this item can be ignored. |
| 940 | |
Christopher Faulet | a1cda02 | 2016-12-21 08:58:06 +0100 | [diff] [blame] | 941 | * "engine-id" <STRING> |
| 942 | |
| 943 | This is a uniq string that identify a SPOE engine. |
| 944 | |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 945 | To finish the HELLO handshake, the agent must return an AGENT-HELLO frame with |
| 946 | its supported SPOP version, the lower value between its maximum size allowed |
| 947 | for a frame and the HAProxy one and capabilities it supports. If an error |
| 948 | occurs or if an incompatibility is detected with the agent configuration, an |
| 949 | AGENT-DISCONNECT frame must be returned. |
| 950 | |
| 951 | 3.2.5. Frame: AGENT-HELLO |
| 952 | -------------------------- |
| 953 | |
| 954 | This frame is sent in reply to a HAPROXY-HELLO frame to finish a HELLO |
| 955 | handshake. As for HAPROXY-HELLO frame, STREAM-ID and FRAME-ID are also set |
| 956 | 0. The payload of this frame is a KV-LIST and it cannot be fragmented. |
| 957 | |
| 958 | Following items are mandatory in the KV-LIST: |
| 959 | |
| 960 | * "version" <STRING> |
| 961 | |
| 962 | This is the SPOP version the agent supports. It must follow the format |
| 963 | "Major.Minor" and it must be lower or equal than one of major versions |
| 964 | announced by HAProxy. |
| 965 | |
| 966 | * "max-frame-size" <UINT32> |
| 967 | |
| 968 | This is the maximum size allowed for a frame. It must be lower or equal to |
| 969 | the value in the HAPROXY-HELLO frame. This value will be used for all |
| 970 | subsequent frames. |
| 971 | |
| 972 | * "capabilities" <STRING> |
| 973 | |
| 974 | This a comma-separated list of capabilities supported by agent. Spaces must |
| 975 | be ignored, if any. |
| 976 | |
| 977 | At this time, if everything is ok for HAProxy (supported version and valid |
| 978 | max-frame-size value), the HELLO handshake is successfully completed. Else, |
| 979 | HAProxy sends a HAPROXY-DISCONNECT frame with the corresponding error. |
| 980 | |
Christopher Faulet | ba7bc16 | 2016-11-07 21:07:38 +0100 | [diff] [blame] | 981 | If "healthcheck" item was set to TRUE in the HAPROXY-HELLO frame, the agent can |
| 982 | safely close the connection without DISCONNECT frame. In all cases, HAProxy |
| 983 | will close the connexion at the end of the health check. |
| 984 | |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 985 | 3.2.6. Frame: NOTIFY |
| 986 | --------------------- |
| 987 | |
| 988 | Information are sent to the agents inside NOTIFY frames. These frames are |
| 989 | attached to a stream, so STREAM-ID and FRAME-ID must be set. The payload of |
| 990 | NOTIFY frames is a LIST-OF-MESSAGES and, if supported by agents, it can be |
| 991 | fragmented. |
| 992 | |
| 993 | NOTIFY frames must be acknowledge by agents sending an ACK frame, repeating |
| 994 | right STREAM-ID and FRAME-ID. |
| 995 | |
| 996 | 3.2.7. Frame: ACK |
| 997 | ------------------ |
| 998 | |
| 999 | ACK frames must be sent by agents to reply to NOTIFY frames. STREAM-ID and |
| 1000 | FRAME-ID found in a NOTIFY frame must be reuse in the corresponding ACK |
| 1001 | frame. The payload of ACK frames is a LIST-OF-ACTIONS and, if supported by |
| 1002 | HAProxy, it can be fragmented. |
| 1003 | |
| 1004 | 3.2.8. Frame: HAPROXY-DISCONNECT |
| 1005 | --------------------------------- |
| 1006 | |
| 1007 | If an error occurs, at anytime, from the HAProxy side, a HAPROXY-DISCONNECT |
| 1008 | frame is sent with information describing the error. HAProxy will wait an |
| 1009 | AGENT-DISCONNECT frame in reply. All other frames will be ignored. The agent |
| 1010 | must then close the socket. |
| 1011 | |
| 1012 | The payload of this frame is a KV-LIST. It cannot be fragmented. STREAM-ID and |
| 1013 | FRAME-ID are must be set 0. |
| 1014 | |
| 1015 | Following items are mandatory in the KV-LIST: |
| 1016 | |
| 1017 | * "status-code" <UINT32> |
| 1018 | |
| 1019 | This is the code corresponding to the error. |
| 1020 | |
| 1021 | * "message" <STRING> |
| 1022 | |
| 1023 | This is a textual message describing the error. |
| 1024 | |
| 1025 | For more information about known errors, see section "Errors & timeouts" |
| 1026 | |
| 1027 | 3.2.9. Frame: AGENT-DISCONNECT |
| 1028 | ------------------------------- |
| 1029 | |
| 1030 | If an error occurs, at anytime, from the agent size, a AGENT-DISCONNECT frame |
Michael Prokop | 4438c60 | 2019-05-24 10:25:45 +0200 | [diff] [blame] | 1031 | is sent, with information describing the error. such frame is also sent in reply |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 1032 | to a HAPROXY-DISCONNECT. The agent must close the socket just after sending |
| 1033 | this frame. |
| 1034 | |
| 1035 | The payload of this frame is a KV-LIST. It cannot be fragmented. STREAM-ID and |
| 1036 | FRAME-ID are must be set 0. |
| 1037 | |
| 1038 | Following items are mandatory in the KV-LIST: |
| 1039 | |
| 1040 | * "status-code" <UINT32> |
| 1041 | |
| 1042 | This is the code corresponding to the error. |
| 1043 | |
| 1044 | * "message" <STRING> |
| 1045 | |
| 1046 | This is a textual message describing the error. |
| 1047 | |
| 1048 | For more information about known errors, see section "Errors & timeouts" |
| 1049 | |
| 1050 | 3.3. Events & Messages |
| 1051 | ----------------------- |
| 1052 | |
| 1053 | Information about streams are sent in NOTIFY frames. You can specify which kind |
| 1054 | of information to send by defining "spoe-message" sections in your SPOE |
| 1055 | configuration file. for each "spoe-message" there will be a message in a NOTIFY |
| 1056 | frame when the right event is triggered. |
| 1057 | |
| 1058 | A NOTIFY frame is sent for an specific event when there is at least one |
| 1059 | "spoe-message" attached to this event. All messages for an event will be added |
| 1060 | in the same NOTIFY frame. |
| 1061 | |
| 1062 | Here is the list of supported events: |
| 1063 | |
| 1064 | * on-client-session is triggered when a new client session is created. |
| 1065 | This event is only available for SPOE filters |
| 1066 | declared in a frontend or a listen section. |
| 1067 | |
| 1068 | * on-frontend-tcp-request is triggered just before the evaluation of |
| 1069 | "tcp-request content" rules on the frontend side. |
| 1070 | This event is only available for SPOE filters |
| 1071 | declared in a frontend or a listen section. |
| 1072 | |
| 1073 | * on-backend-tcp-request is triggered just before the evaluation of |
| 1074 | "tcp-request content" rules on the backend side. |
| 1075 | This event is skipped for SPOE filters declared |
| 1076 | in a listen section. |
| 1077 | |
| 1078 | * on-frontend-http-request is triggered just before the evaluation of |
| 1079 | "http-request" rules on the frontend side. This |
| 1080 | event is only available for SPOE filters declared |
| 1081 | in a frontend or a listen section. |
| 1082 | |
| 1083 | * on-backend-http-request is triggered just before the evaluation of |
| 1084 | "http-request" rules on the backend side. This |
| 1085 | event is skipped for SPOE filters declared in a |
| 1086 | listen section. |
| 1087 | |
| 1088 | * on-server-session is triggered when the session with the server is |
| 1089 | established. |
| 1090 | |
| 1091 | * on-tcp-response is triggered just before the evaluation of |
| 1092 | "tcp-response content" rules. |
| 1093 | |
| 1094 | * on-http-response is triggered just before the evaluation of |
| 1095 | "http-response" rules. |
| 1096 | |
| 1097 | |
| 1098 | The stream processing will loop on these events, when triggered, waiting the |
| 1099 | agent reply. |
| 1100 | |
| 1101 | 3.4. Actions |
| 1102 | ------------- |
| 1103 | |
| 1104 | An agent must acknowledge each NOTIFY frame by sending the corresponding ACK |
| 1105 | frame. Actions can be added in these frames to dynamically take action on the |
| 1106 | processing of a stream. |
| 1107 | |
| 1108 | Here is the list of supported actions: |
| 1109 | |
| 1110 | * set-var set the value for an existing variable. 3 arguments must be |
| 1111 | attached to this action: the variable scope (proc, sess, txn, |
Kevin Zhu | 730323e | 2018-06-01 05:38:00 +0200 | [diff] [blame] | 1112 | req or res), the variable name (a string) and its value. |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 1113 | |
| 1114 | ACTION-SET-VAR : <SET-VAR:1 byte><NB-ARGS:1 byte><VAR-SCOPE:1 byte><VAR-NAME><VAR-VALUE> |
| 1115 | |
| 1116 | SET-VAR : <1> |
| 1117 | NB-ARGS : <3> |
| 1118 | VAR-SCOPE : <PROCESS> | <SESSION> | <TRANSACTION> | <REQUEST> | <RESPONSE> |
| 1119 | VAR-NAME : <STRING> |
| 1120 | VAR-VALUE : <TYPED-DATA> |
| 1121 | |
| 1122 | PROCESS : <0> |
| 1123 | SESSION : <1> |
| 1124 | TRANSACTION : <2> |
| 1125 | REQUEST : <3> |
Christopher Faulet | a1cda02 | 2016-12-21 08:58:06 +0100 | [diff] [blame] | 1126 | RESPONSE : <4> |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 1127 | |
| 1128 | * unset-var unset the value for an existing variable. 2 arguments must be |
| 1129 | attached to this action: the variable scope (proc, sess, txn, |
Kevin Zhu | 730323e | 2018-06-01 05:38:00 +0200 | [diff] [blame] | 1130 | req or res) and the variable name (a string). |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 1131 | |
Christopher Faulet | 1002aac | 2016-12-09 17:41:54 +0100 | [diff] [blame] | 1132 | ACTION-UNSET-VAR : <UNSET-VAR:1 byte><NB-ARGS:1 byte><VAR-SCOPE:1 byte><VAR-NAME> |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 1133 | |
Christopher Faulet | 1002aac | 2016-12-09 17:41:54 +0100 | [diff] [blame] | 1134 | UNSET-VAR : <2> |
| 1135 | NB-ARGS : <2> |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 1136 | VAR-SCOPE : <PROCESS> | <SESSION> | <TRANSACTION> | <REQUEST> | <RESPONSE> |
| 1137 | VAR-NAME : <STRING> |
| 1138 | |
| 1139 | PROCESS : <0> |
| 1140 | SESSION : <1> |
| 1141 | TRANSACTION : <2> |
| 1142 | REQUEST : <3> |
Christopher Faulet | a1cda02 | 2016-12-21 08:58:06 +0100 | [diff] [blame] | 1143 | RESPONSE : <4> |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 1144 | |
| 1145 | |
| 1146 | NOTE: Name of the variables will be automatically prefixed by HAProxy to avoid |
| 1147 | name clashes with other variables used in HAProxy. Moreover, unknown |
| 1148 | variable will be silently ignored. |
| 1149 | |
Christopher Faulet | d1307ce | 2017-02-27 21:59:39 +0100 | [diff] [blame] | 1150 | 3.5. Errors & timeouts |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 1151 | ---------------------- |
| 1152 | |
| 1153 | Here is the list of all known errors: |
| 1154 | |
| 1155 | STATUS CODE | DESCRIPTION |
| 1156 | ----------------+-------------------------------------------------------- |
| 1157 | 0 | normal (no error occurred) |
| 1158 | 1 | I/O error |
| 1159 | 2 | A timeout occurred |
| 1160 | 3 | frame is too big |
| 1161 | 4 | invalid frame received |
| 1162 | 5 | version value not found |
| 1163 | 6 | max-frame-size value not found |
| 1164 | 7 | capabilities value not found |
| 1165 | 8 | unsupported version |
| 1166 | 9 | max-frame-size too big or too small |
Christopher Faulet | d1307ce | 2017-02-27 21:59:39 +0100 | [diff] [blame] | 1167 | 10 | payload fragmentation is not supported |
| 1168 | 11 | invalid interlaced frames |
| 1169 | 12 | frame-id not found (it does not match any referenced frame) |
| 1170 | 13 | resource allocation error |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 1171 | 99 | an unknown error occurrde |
| 1172 | ----------------+-------------------------------------------------------- |
| 1173 | |
| 1174 | An agent can define its own errors using a not yet assigned status code. |
| 1175 | |
Christopher Faulet | ea62c2a | 2016-11-14 10:54:21 +0100 | [diff] [blame] | 1176 | IMPORTANT NOTE: By default, for a specific stream, when an abnormal/unexpected |
| 1177 | error occurs, the SPOE is disabled for all the transaction. So |
| 1178 | if you have several events configured, such error on an event |
| 1179 | will disabled all followings. For TCP streams, this will |
| 1180 | disable the SPOE for the whole session. For HTTP streams, this |
| 1181 | will disable it for the transaction (request and response). |
| 1182 | See 'option continue-on-error' to bypass this limitation. |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 1183 | |
Joseph Herlant | 71b4b15 | 2018-11-13 16:55:16 -0800 | [diff] [blame] | 1184 | To avoid a stream to wait undefinetly, you must carefully choose the |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 1185 | acknowledgement timeout. In most of cases, it will be quiet low. But it depends |
| 1186 | on the responsivness of your service. |
| 1187 | |
| 1188 | You must also choose idle timeout carefully. Because connection with your |
| 1189 | service depends on the backend configuration used by the SPOA, it is important |
| 1190 | to use a lower value for idle timeout than the server timeout. Else the |
| 1191 | connection will be closed by HAProxy. The same is true for hello timeout. You |
| 1192 | should choose a lower value than the connect timeout. |
| 1193 | |
Christopher Faulet | b2dd1e0 | 2018-03-22 09:07:41 +0100 | [diff] [blame] | 1194 | 4. Logging |
| 1195 | ----------- |
| 1196 | |
| 1197 | Activity of an SPOE is logged using HAProxy's logger. The messages are logged |
| 1198 | in the context of the streams that handle the client and the server |
| 1199 | connections. A message is emitted for each event or group handled by an |
| 1200 | SPOE. Depending on the status code, the log level will be different. In the |
| 1201 | normal case, when no error occurred, the message is logged with the level |
| 1202 | LOG_NOTICE. Otherwise, the message is logged with the level LOG_WARNING. |
| 1203 | |
Christopher Faulet | 3b8e349 | 2018-03-26 17:20:58 +0200 | [diff] [blame] | 1204 | The messages are logged using the agent's logger, if defined, and use the |
| 1205 | following format: |
Christopher Faulet | b2dd1e0 | 2018-03-22 09:07:41 +0100 | [diff] [blame] | 1206 | |
Christopher Faulet | 6e0d5e7 | 2018-04-26 14:25:43 +0200 | [diff] [blame] | 1207 | SPOE: [AGENT] <TYPE:NAME> sid=STREAM-ID st=STATUS-CODE reqT/qT/wT/resT/pT \ |
Christopher Faulet | caf2fec | 2018-04-04 10:25:50 +0200 | [diff] [blame] | 1208 | <idles>/<applets> <nb_sending>/<nb_waiting> <nb_error>/<nb_processed> |
Christopher Faulet | b2dd1e0 | 2018-03-22 09:07:41 +0100 | [diff] [blame] | 1209 | |
| 1210 | AGENT is the agent name |
| 1211 | TYPE is EVENT of GROUP |
| 1212 | NAME is the event or the group name |
| 1213 | STREAM-ID is an integer, the unique id of the stream |
| 1214 | STATUS_CODE is the processing's status code |
| 1215 | reqT/qT/wT/resT/pT are the following time events: |
| 1216 | |
| 1217 | * reqT : the encoding time. It includes ACLs processing, if any. For |
| 1218 | fragmented frames, it is the sum of all fragments. |
| 1219 | * qT : the delay before the request gets out the sending queue. For |
| 1220 | fragmented frames, it is the sum of all fragments. |
Joseph Herlant | 71b4b15 | 2018-11-13 16:55:16 -0800 | [diff] [blame] | 1221 | * wT : the delay before the response is received. No fragmentation |
Christopher Faulet | b2dd1e0 | 2018-03-22 09:07:41 +0100 | [diff] [blame] | 1222 | supported here. |
| 1223 | * resT : the delay to process the response. No fragmentation supported |
Christopher Faulet | 36bda1c | 2018-03-22 09:08:20 +0100 | [diff] [blame] | 1224 | here. |
Christopher Faulet | b2dd1e0 | 2018-03-22 09:07:41 +0100 | [diff] [blame] | 1225 | * pT : the delay to process the event or the group. From the stream |
Christopher Faulet | 36bda1c | 2018-03-22 09:08:20 +0100 | [diff] [blame] | 1226 | point of view, it is the latency added by the SPOE processing. |
| 1227 | It is more or less the sum of values above. |
Christopher Faulet | b2dd1e0 | 2018-03-22 09:07:41 +0100 | [diff] [blame] | 1228 | |
Christopher Faulet | caf2fec | 2018-04-04 10:25:50 +0200 | [diff] [blame] | 1229 | <idle> is the numbers of idle SPOE applets |
| 1230 | <applets> is the numbers of SPOE applets |
| 1231 | <nb_sending> is the numbers of streams waiting to send data |
| 1232 | <nb_waiting> is the numbers of streams waiting for a ack |
| 1233 | <nb_error> is the numbers of processing errors |
| 1234 | <nb_processed> is the numbers of events/groups processed |
| 1235 | |
| 1236 | |
Christopher Faulet | b2dd1e0 | 2018-03-22 09:07:41 +0100 | [diff] [blame] | 1237 | For all these time events, -1 means the processing was interrupted before the |
| 1238 | end. So -1 for the queue time means the request was never dequeued. For |
| 1239 | fragmented frames it is harder to know when the interruption happened. |
Christopher Faulet | f7e4e7e | 2016-10-27 22:29:49 +0200 | [diff] [blame] | 1240 | |
| 1241 | /* |
| 1242 | * Local variables: |
| 1243 | * fill-column: 79 |
| 1244 | * End: |
| 1245 | */ |