From: Willy Tarreau Date: Tue, 24 Nov 2026 13:58:57 +0000 (+0100) Subject: BUG/MEDIUM: startup: revisit the default chroot behavior X-Git-Url: https://git.kaiwu.me/http/ngx_http_proxy_module.html?a=commitdiff_plain;h=064c7793bd0f56b0a45629cc1462b0a04b3147f2;p=haproxy.git BUG/MEDIUM: startup: revisit the default chroot behavior A few users reported the following pattern at boot: geteuid() = 1000 prctl(PR_CAPBSET_READ, CAP_SYS_CHROOT) = 1 mkdir("/tmp/haproxy.wbFFQW", 0700) = 0 chdir("/tmp/haproxy.wbFFQW") = 0 rmdir("/tmp/haproxy.wbFFQW") = 0 chroot(".") = -1 EPERM (Operation not permitted) geteuid() = 1000 getegid() = 1000 unshare(CLONE_NEWUSER) = 0 chroot(".") = -1 EPERM (Operation not permitted) I.e. everything looks like we'llb be able to chroot but we fail to. And that's pretty annoying because it reports a warning after that, speaking about starting as root while it is not the case. A first approach would consist in relaxing the rules around "auto" but that's not good because users writing "chroot auto" *want* a chroot to be performed (and it's actually the safest one since it has no "." nor ".."). This patch clarifies the situation by introducing a new "opportunistic" mode, that noone needs to type since it's the default. In this mode, no error is reported during the attempt to chroot. However on failure, if the user was root, a warning is reported to indicate that it's strange, and suggests to use chroot / instead if needed. In this case the conditions producing the trace above will no longer display any irritating message on a config without chroot directive, but users of "chroot auto" will still be told what's wrong. This only affects 3.5 so no backport is needed. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 3f04d3483..fd05d6749 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -2364,7 +2364,7 @@ ca-base directives. Absolute locations specified in "ca-file", "ca-verify-file" and "crl-file" prevail and ignore "ca-base". -chroot { | auto } +chroot { | auto | opportunistic } Changes current directory to and performs a chroot() there before dropping privileges. This increases the security level in case an unknown vulnerability would be exploited, since it would make it very hard for the @@ -2378,15 +2378,17 @@ chroot { | auto } As a special case, may be set to "auto", in which case haproxy creates an anonymous temporary directory, unlinks it, and chroots into it. The resulting jail has no name in the filesystem and is empty and read-only, - removing the need to prepare a dedicated jail directory. + removing the need to prepare a dedicated jail directory. "opportunistic" is + the same except that no error is displayed on failure. When starting with sufficient privileges and when "set-dumpable" is not set, - haproxy will automatically apply "chroot auto" if no "chroot" directive is - used, i.e. it will isolate itself in a chroot jail, and will emit a warning - if it fails to do so. If there is a compelling reason not to use chroot (e.g. - access to a server via a UNIX socket outside of the jail), it remains - possible to silence the warning by adding an explicit "chroot /", which has - the benefit of being visible in a configuration. + haproxy will automatically apply "chroot opportunistic" if no "chroot" + directive is used, i.e. it will try to isolate itself in a chroot jail, and + will only emit a warning if it fails to do so while being started as root. If + there is a compelling reason not to use chroot (e.g. access to a server via a + UNIX socket outside of the jail), it remains possible to silence the warning + by adding an explicit "chroot /", which has the benefit of being visible in a + configuration. close-spread-time