]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MINOR: capabilities: add cap_sys_admin support
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Fri, 26 Apr 2024 19:47:54 +0000 (21:47 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 30 Apr 2024 19:40:17 +0000 (21:40 +0200)
commit5cbb278faed4f40bd84e8e79e414eb6ac474dc8b
treefc4dc6f59d9b6d2160ba4dca65061037e6092a08
parent13ef5524888faf47936ce54a0164dac2689ff7b5
MINOR: capabilities: add cap_sys_admin support

If 'namespace' keyword is used in the backend server settings or/and in the
bind string, it means that haproxy process will call setns() to change its
default namespace to the configured one and then, it will create a
socket in this new namespace. setns() syscall requires CAP_SYS_ADMIN
capability in the process Effective set (see man 2 setns). Otherwise, the
process must be run as root.

To avoid to run haproxy as root, let's add cap_sys_admin capability in the
same way as we already added the support for some other network capabilities.

As CAP_SYS_ADMIN belongs to CAP_SYS_* capabilities type, let's add a separate
flag LSTCHK_SYSADM for it. This flag is set, if the 'namespace' keyword was
found during configuration parsing. The flag may be unset only in
prepare_caps_for_setuid() or in prepare_caps_from_permitted_set(), which
inspect process EUID/RUID and Effective and Permitted capabilities sets.

If system doesn't support Linux capabilities or 'cap_sys_admin' was not set
in 'setcap', but 'namespace' keyword is presented in the configuration, we
keep the previous strict behaviour. Process, that has changed uid to the
non-priviledged user, will terminate with alert. This alert invites the user
to recheck its configuration.

In the case, when haproxy will start and run under a non-root user and
'cap_sys_admin' is not set, but 'namespace' keyword is presented, this patch
does not change previous behaviour as well. We'll still let the user to try
its configuration, but we inform via warning, that unexpected things, like
socket creation errors, may occur.
doc/management.txt
include/haproxy/global-t.h
src/cfgparse-tcp.c
src/haproxy.c
src/linuxcap.c
src/server.c