in reply to Re^3: Best way to write to a file owned by root?
in thread Best way to write to a file owned by root?
System files like /etc/hosts are not owned by user root, group root (or bin) by chance, but intentionally. Making them writable for the webserver (or any other group) opens a way for remote file modification. One stupid bug in a CGI or a PHP script might be sufficient.
A much cleaner approach would be a dedicated service (i.e. a daemon) whose sole purpose is to modify files as root. An unprivileged program (like a CGI, or a user program) contacts the service, and passes either a modification command or a completely new file. Typically, this would be done via a named pipe (FIFO) or a unix domain socket. The service does three things:
The first check may prevent any user but the administrative webserver's run accound to modify files; it also prevents access to arbitary files. You usually don't want to allow anybody to overwrite /etc/passwd.
The second check prevents garbage files that may make the system unusable.
Together, this prevents direct and unverified modification by arbitary programs, without giving out privileges to an entire group of programs.
A quite large system that uses this technique (Privilege separation) is postfix. Unlike sendmail, which runs as a monolithic setuid root binary, postfix uses various services, with as few privileges as possible.
Update: Found a related PDF by Theo de Raadt of OpenBSD regarding privilege separation, enforced by the OpenBSD kernel.
Alexander
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Best way to write to a file owned by root?
by nysus (Parson) on Mar 14, 2017 at 22:25 UTC | |
by afoken (Chancellor) on Mar 15, 2017 at 06:42 UTC | |
by nysus (Parson) on Mar 15, 2017 at 14:09 UTC | |
by hippo (Archbishop) on Mar 15, 2017 at 14:52 UTC | |
by nysus (Parson) on Mar 15, 2017 at 15:23 UTC | |
|