13. Security considerations
- HAProxy is designed to run with very limited privileges. The standard way to
- use it is to isolate it into a chroot jail and to drop its privileges to a
- non-root user without any permissions inside this jail so that if any future
- vulnerability were to be discovered, its compromise would not affect the rest
- of the system.
- In order to perform a chroot, it first needs to be started as a root user. It is
- pointless to build hand-made chroots to start the process there, these ones are
- painful to build, are never properly maintained and always contain way more
- bugs than the main file-system. And in case of compromise, the intruder can use
- the purposely built file-system. Unfortunately many administrators confuse
- "start as root" and "run as root", resulting in the uid change to be done prior
- to starting haproxy, and reducing the effective security restrictions.
- HAProxy will need to be started as root in order to :
- - adjust the file descriptor limits
- - bind to privileged port numbers
- - bind to a specific network interface
- - transparently listen to a foreign address
- - isolate itself inside the chroot jail
- - drop to another non-privileged UID
- HAProxy may require to be run as root in order to :
- - bind to an interface for outgoing connections
- - bind to privileged source ports for outgoing connections
- - transparently bind to a foreign address for outgoing connections
- Most users will never need the "run as root" case. But the "start as root"
- covers most usages.
- A safe configuration will have :
- - a chroot statement pointing to an empty location without any access
- permissions. This can be prepared this way on the UNIX command line :
- # mkdir /var/empty && chmod 0 /var/empty || echo "Failed"
- and referenced like this in the HAProxy configuration's global section :
- chroot /var/empty
- - both a uid/user and gid/group statements in the global section :
- user haproxy
- group haproxy
- - a stats socket whose mode, uid and gid are set to match the user and/or
- group allowed to access the CLI so that nobody may access it :
- stats socket /var/run/haproxy.stat uid hatop gid hatop mode 600
HAProxy 2.0.14 – Management Guide
,