Previously, an initgroups() failure was only logged, and the worker
process went on with the supplementary groups inherited from the master
process, since setgid() does not change them. Anything relying on the
configured user's groups then failed at run time, far from the log
message, and the outcome depended on which worker hit the error.
Now such a failure is fatal, similarly to setgid() and setuid(). The
exception is EPERM, which is logged and ignored: it is returned when
supplementary groups cannot be changed at all, for example, in a user
namespace with setgroups denied, see user_namespaces(7), or under
seccomp.
This dates back to
42b12b34f (0.1.11).
}
if (initgroups(ccf->username, ccf->group) == -1) {
- ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
- "initgroups(%s, %d) failed",
+
+ if (ngx_errno != NGX_EPERM) {
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+ "initgroups(%s, %d) failed",
+ ccf->username, ccf->group);
+ /* fatal */
+ exit(2);
+ }
+
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+ "initgroups(%s, %d) failed, ignored",
ccf->username, ccf->group);
}