Installation
Prerequisites
In order to start HAProxy Enforcer installation, please collect the output of the following two commands and send to your Solution Architect or HUMAN Support:
Upon receiving this information, you will receive an archive with HAProxy Enforcer files, built for your system.
Notes:
- HAProxy must be in “HTTP” mode.
- HAProxy must contain LUA support. You can check this by running
haproxy -vv | grep USE_LUA
. - HAProxy configuration must not include the
chroot
directive. Thechroot
directive prevents HAProxy Enforcer from accessing remote servers. - HAProxy must enable threads support. See Enable threads support for more information.
Installation
Dependencies installation
The following packages are required:
- apr-1
- apr-util-1
- libcurl
- openssl
- jansson
- lua
- pcre
Linux distribution specific installation instructions:
- For Debian/Ubuntu distribution:
apt-get update && apt-get install -y libcurl4 libapr1 libjansson4 libaprutil1 curl libpcre3 liblua5.4
- For Alpine Linux distribution:
apk add apr-util apr jansson curl pcre lua5.4
Adjust px_config.lua
Enforcer configuration file
Required parameters:
_M.px_appId
/ _M.auth_token
: Application ID / AppId and Token / Auth Token can be found in the Portal, in the “Applications” section.
_M.cookie_secret
: Cookie Encryption Key can be found in the portal, in the “Policies” section.
For other configuration parameteters please see HAProxy Module Configuration
Enforcer files installation
From the archive received from HUMAN, extract and copy files:
px_haproxy.lua
to/usr/local/lib/lua/
directory (createlua
directory if it doesn’t exist)px_core.so
file to/usr/local/lib/lua/
directorypx_config.lua
to/usr/local/etc/
directory
Modify haproxy.cfg HAProxy configuration file
- Add the following 3 lines to
global
section:
- To all frontends with HTTP mode (`mode http`) add
use_backend %[lua.px_handle_request]
line to redirect incoming traffic to PX HAProxy module - Add a new HTTP backend
request_pass
. This backend handles traffic which is marked as “human requests”. Addhttp-response lua.px_handle_response
line to append PX specific headers to outgoing responses - Add a new HTTP backend
request_block
with the context below. This backend handles traffic which is marked as “blocked”.
Minimal haproxy.cfg example
Enable threads support
By default, HAProxy prevents modules from creating new threads. However, PX HAProxy Enforcer spawns several threads while working.
The solution:
- Enable threads creating by adding
insecure-fork-wanted
configuration to HAProxy global section. See HAProxy’s documentation for more information. - Run HAProxy as a “root” user (not recommended)