-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run php:fpm as non-root #70
Comments
To accomodate switching between Then again, it would also be nice to be able to easily switch In the case of |
Derp: Line 13 in 58775aa
Looks like it already runs as |
Actually, I would rather reopen this as the master process still runs as root:
|
@sagikazarmark as far as I can tell that is identical to many installs on non-container systems running apache/php or fpm:
|
and can be overcome by using $ dockr run -it --rm --user www-data php:fpm
[04-Aug-2016 18:09:04] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
[04-Aug-2016 18:09:04] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
[04-Aug-2016 18:09:04] NOTICE: fpm is running, pid 1
[04-Aug-2016 18:09:04] NOTICE: ready to handle connections |
Indeed. Actually I am not sure about this, because on side there is the security issue of running root inside the container, on the other side there is what you say. So what's the correct way of doing this? I read about security issues and recommendations to run processes with non-root UID. |
I think it depends wholly on your use case and your threat model. For most
typical use-cases, the existing behavior should be sufficient (especially
if combined with user namespaces on the daemon, thus making root in the
container non-root on the host). The extra paranoid will likely want to
run as some arbitrary UID that isn't consistent, which should also be
possible via "--user" (assuming file permissions are appropriately set to
handle the change as well).
|
Great, thanks @tianon |
When running as root, it cannot run on many container installations, because some do only allow running non-root containers. I don't see the problem that could arise when running as www-data by default. Is there any drawback? |
As it's written, the container will start as root and step down to |
Unfortunately that makes running this image on openshift online harder than it needs to be. Kubernetes (which is the basis of openshift) will automatically try to run the image with the configured I don't really see what the problem with running as www-data by default is. Is there any advantage in running as root? |
The ability to adjust filesystem permissions, bind "privileged" ports, etc
before becoming non-root are a couple examples.
|
As far as I know, the running mode of php-fpm is the leader follow model. It does not need tools like gosu. You can change the users of the php-fpm working process through the php-fpm-user and php-fpm-group parameters. In addition, when installing php-fpm on traditional servers, the management process is root, and the working process is run by other users, such as www. Running the php-fpm management process directly as a non-root user will cause many problems, such as the inability to create a sock file and port binding |
For the software running in the leader follow model, the management process only does the management work, unlike the working process, which will run the user code, so that the management process is safe, so it is safe to run as root user. The working process is different, because the working process will run the code of the user end, and the code of the user end may have vulnerabilities exploited by hackers. Some vulnerabilities can allow hackers to hack into the system, so it is necessary to run the working process as a non-root user, so even if the hacker hacks into the system, it can only be accessed as an ordinary user |
Unlike the
php:apache
image where Apache dropsroot
privileges towww-data
before running any PHP code, thephp:fpm
image is still running asroot
.Since it doesn't actually need root privileges, it would probably be best if
php:fpm
ran PHP code as a non-root
user. In the case ofphp:fpm
, it seems like it should work fine to use aUSER fpm
without pulling ingosu
or anything like that.The text was updated successfully, but these errors were encountered: