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