The resulting jail has no name in the filesystem and is empty and read-only,
removing the need to prepare a dedicated jail directory.
- When starting with superuser privileges, a warning will be displayed if no
- chroot is used, in order to encourage users to always use the mechanism. If
- for any reason there is a compelling reason not to use chroot (e.g. access to
- a server via a UNIX socket with an unconvenient path), it remains possible to
- silence the warning by adding an explicit "chroot /", which has the benefit
- of being visible in a configuration.
+ When starting with sufficient privileges, 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.
close-spread-time <time>
Define a time window during which idle connections and active connections
int chroot_permitted = geteuid() == 0;
#if defined(USE_PRCTL) && defined(PR_CAPBSET_READ) && defined(CAP_SYS_CHROOT)
- chroot_permitted &= (prctl(PR_CAPBSET_READ, CAP_SYS_CHROOT, 0, 0, 0) == 1);
-#endif
- if (chroot_permitted) {
+ int ret = prctl(PR_CAPBSET_READ, CAP_SYS_CHROOT, 0, 0, 0);
+ if (ret == 1)
+ chroot_permitted = 1;
+ else if (ret == 0)
+ chroot_permitted = 0;
+ /* errors mean prctl() not supported, so don't update the verdict */
+#endif
+ if (chroot_permitted && do_chroot(argv[0], "auto") != 0) {
ha_warning("[%s.main()] HAProxy was started as root without any 'chroot' "
- "directive. A chroot limits filesystem access of an intruder "
- "to a single, preferably empty, directory. It is strongly recommended "
- "to enable this feature whenever possible (it's always possible when "
- "starting as root), via 'chroot auto' in the global section. If you "
- "think you have good reasons for running outside a chroot, explicitly "
- "configure 'chroot /' to silence this warning.\n", argv[0]);
+ "directive, and an attempt at automatically chrooting failed, "
+ "so the haproxy process is not as protected as it could be. "
+ "Please report this event to developers with as many details as "
+ "possible about your execution environment so they can evaluate "
+ "if anything can be done to better support it. A chroot limits "
+ "filesystem access of an intruder to a single, preferably empty, "
+ "directory. It is strongly recommended to enable this feature "
+ "whenever possible (it's always possible when starting as root), "
+ "via 'chroot auto' in the global section. If you think you have "
+ "good reasons for running outside a chroot, explicitly configure "
+ "'chroot /' to silence this warning.\n", argv[0]);
}
}