]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MEDIUM: capabilities: check process capabilities sets
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Fri, 15 Mar 2024 17:02:05 +0000 (18:02 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 5 Apr 2024 16:01:54 +0000 (18:01 +0200)
commitf0b6436f57db5014eecb5ef365bf278119711e02
tree7c50fa08a7ba837b28f2853bfdce98d0a5a16181
parente4306fb822fd1816dc7f46d48a99aa4d3b30e908
MEDIUM: capabilities: check process capabilities sets

Since the Linux capabilities support add-on (see the commit bd84387beb26
("MEDIUM: capabilities: enable support for Linux capabilities")), we can also
check haproxy process effective and permitted capabilities sets, when it
starts and runs as non-root.

Like this, if needed network capabilities are presented only in the process
permitted set, we can get this information with capget and put them in the
process effective set via capset. To do this properly, let's introduce
prepare_caps_from_permitted_set().

First, it checks if binary effective set has CAP_NET_ADMIN or CAP_NET_RAW. If
there is a match, LSTCHK_NETADM is removed from global.last_checks list to
avoid warning, because in the initialization sequence some last configuration
checks are based on LSTCHK_NETADM flag and haproxy process euid may stay
unpriviledged.

If there are no CAP_NET_ADMIN and CAP_NET_RAW in the effective set, permitted
set will be checked and only capabilities given in 'setcap' keyword will be
promoted in the process effective set. LSTCHK_NETADM will be also removed in
this case by the same reason. In order to be transparent, we promote from
permitted set only capabilities given by user in 'setcap' keyword. So, if
caplist doesn't include CAP_NET_ADMIN or CAP_NET_RAW, LSTCHK_NETADM would not
be unset and warning about missing priviledges will be emitted at
initialization.

Need to call it before protocol_bind_all() to allow binding to priviledged
ports under non-root and 'setcap cap_net_bind_service' must be set in the
global section in this case.
doc/configuration.txt
doc/management.txt
include/haproxy/linuxcap.h
src/haproxy.c
src/linuxcap.c