Skip to content

maxuru ~ % cat haproxy/run-as-non-root

Run HAProxy as a non-root user

Severity: highApplies to: HAProxy 2.xApplies to: HAProxy 3.x
The fix/etc/haproxy/haproxy.cfg
global
user haproxy
group haproxy
chroot /var/lib/haproxy

Most distribution packages set these already. The job here is usually to confirm it rather than to change it.

HAProxy starts as root because it has two things to do that require it: bind ports below 1024, and read TLS private keys that should not be readable by anyone else. Having done both, it drops privileges — the process that then spends its life parsing untrusted bytes off the network runs as haproxy, not root.

That split is what makes the parsing bugs survivable. HAProxy’s CVE history is mostly memory-safety and protocol-handling issues in exactly that code path; whether such a bug is a bad day or a total host compromise is decided by which user the worker was running as when it hit.

If user and group are absent, HAProxy keeps root for the whole process lifetime. The config is valid and the service works, so nothing draws attention to it.

chroot confines the worker to a directory after privileges are dropped, so a process that gets hijacked cannot see the filesystem. HAProxy’s documentation is explicit that the jail must be empty and non-writable by anyone — an empty directory is the whole point, since there is nothing inside it to abuse.

Terminal window
sudo mkdir -p /var/lib/haproxy
sudo chown root:root /var/lib/haproxy
sudo chmod 755 /var/lib/haproxy

Owned by root and empty. Do not put the socket, certificates or logs inside it; HAProxy opens all of those before it chroots, so they belong in their normal locations.

Because the key is read before the drop, the private key does not need to be readable by the haproxy user — and should not be:

Terminal window
sudo chown root:root /etc/haproxy/certs/site.pem
sudo chmod 400 /etc/haproxy/certs/site.pem

This is the same two-process reasoning as Apache and nginx: the privileged parent reads the secret at startup so the unprivileged worker never holds it.