Skip to content

Bot protection on HAProxy

HAProxy sends request metadata to Centinel's hosted SPOA, and Lua hooks route blocked requests to a block service before they reach your backends.

How it fits into HAProxy

Execution model
An SPOE filter on the frontend plus Lua request and response hooks from centinel-spoe.lua.
Requirements
HAProxy 2.4+ built with Lua 5.3 and SPOE support, with mode http in the defaults block.
Timeouts and failure mode
timeout processing is 500ms in spoe-centinel.conf. A slow or unreachable SPOA lets the request through.
Message size
One SPOE frame, 16,380 bytes by default. The hooks cap the URL at 2 KiB, each header at 1 KiB and all headers at 6 KiB.

How a request moves through HAProxy

Decisions travel over SPOP on a persistent TLS connection to the hosted SPOA, so no HTTP call leaves the proxy per request.

  1. SPOE event

    On on-frontend-http-request, the filter sends request metadata and the secret key to validator.centinelanalytica.com:9000 over TLS. The static_file ACL keeps assets out of the event.

  2. Decision

    The SPOA returns allow, not_matched, block or redirect, and centinel-request-hook routes the request on it through txn.centinel_status.

  3. Routing

    use_backend centinel-block sends blocked or challenged requests to the centinel-block-service Lua applet. Allowed requests go to your default backend.

  4. Response hook

    On allow, centinel-response-hook applies the validator's headers and cookies on the way out. No answer within 500 ms means the request goes through.

Minimal configuration and a live check

Wire the filter, hooks and SPOA backend into haproxy.cfg

haproxy.cfg
global
    lua-prepend-path /etc/haproxy/lua/?.lua
    lua-load /etc/haproxy/lua/centinel-spoe.lua

defaults
    mode http

frontend http-in
    bind *:80
    filter spoe engine centinel config /etc/haproxy/spoe-centinel.conf
    http-request lua.centinel-request-hook
    http-response lua.centinel-response-hook
    use_backend centinel-block if { var(txn.centinel_status) -m str blocked }
    default_backend servers

backend centinel-block
    http-request use-service lua.centinel-block-service

backend spoe-centinel
    mode tcp
    server spoa validator.centinelanalytica.com:9000 ssl sni str(validator.centinelanalytica.com) verify required verifyhost validator.centinelanalytica.com ca-file /etc/ssl/certs/ca-certificates.crt

Keep verifyhost and sni on spoe-centinel: your secret key travels over this SPOP connection, and verify required alone skips hostname verification.

Send a scripted request

Verify
curl -s -o /dev/null -w '%{http_code}\n' -A 'python-requests/2.31' http://localhost/

Expect 403 once blocking is enabled, or 200 with a logged event in your Centinel dashboard while in log-only mode. If nothing logs and everything passes, run haproxy -c to check for ignored HTTP rules from a missing mode http, a failed SPOA TLS handshake, or timeout processing exceeded.

Deployment options

  • Config files on the host

    Extract centinel-haproxy.zip into /etc/haproxy/lua/, move spoe-centinel.conf to /etc/haproxy/, add the frontend and backend lines, set CENTINEL_SECRET_KEY in systemd and reload with -sf.

    HAProxy install guide (opens in a new tab)
  • Path exclusions in the SPOE message

    To keep /health or /metrics out of the pipeline, add an ACL to the spoe-message check-centinel section and change its event line to skip it.

    HAProxy configuration reference (opens in a new tab)

What to know before deploying

  • mode http is required

    Without it, HAProxy drops every http-request and http-response line, starts normally and enforces nothing. haproxy -c warns that the rules were ignored for frontend.

  • Keep verifyhost and sni on the SPOA backend

    verify required alone checks the certificate chain, not the hostname. The secret key is a SPOE argument on this connection.

  • Long URLs and cookies are cut

    Rules see the first 2 KiB of the URL and 1 KiB of the Cookie header, so a parameter or cookie past that limit does not match. Keep tune.bufsize at 16384 or higher.

  • Your backends, health checks and balancing algorithms
  • Your TLS termination, existing ACLs and stick tables
  • Static files that match the static_file ACL
  • Existing failover routing and server health checks

HAProxy integration questions

Walk through your HAProxy setup

Bring one route bots are hitting. We will map the right connector, timeouts, and log-only rollout for your HAProxy stack.