Hi, I have a series of websites hosted on two CentOS 7 servers, using Apache virtual hosts. One of these servers is a "sandbox" machine, to test things and to fiddle around. On the sandbox server, I have a few dummy websites I'm hosting. # ls /var/www/html/ default phpinfo slackbox-mail slackbox-site unixbox-mail unixbox-site Since Apache is running as system user 'apache' and system group 'apache', I thought it sensible that hosted files be owned by that process. # ls -l /var/www/html/ total 24 drwxr-x---. 3 apache apache 4096 6 juil. 09:37 default drwxr-x---. 3 apache apache 4096 6 juil. 10:01 phpinfo drwxr-x---. 3 apache apache 4096 6 juil. 09:41 slackbox-mail drwxr-x---. 3 apache apache 4096 6 juil. 09:37 slackbox-site drwxr-x---. 3 apache apache 4096 6 juil. 09:42 unixbox-mail drwxr-x---. 3 apache apache 4096 6 juil. 09:38 unixbox-site Directories are all drwxr-x---, while files are -rw-r-----. Now some guy on the french forum fr.centos.org told me that I got everything wrong, and that my setup is a security flaw, without elaborating any further though. So I thought I'd ask on this list (which is a little bit more urbane than the french forum). 1. What is wrong with my setup ? 2. What do you suggest ? BTW, I don't mind to RTFM, even extensively. Cheers from the sunny South of France, Niki Kovacs -- Microlinux - Solutions informatiques durables 7, place de l'?glise - 30730 Montpezat Web : http://www.microlinux.fr Mail : info at microlinux.fr T?l. : 04 66 63 10 32
> > Since Apache is running as system user 'apache' and system group > 'apache', I thought it sensible that hosted files be owned by that process. > > # ls -l /var/www/html/ > total 24 > drwxr-x---. 3 apache apache 4096 6 juil. 09:37 default > drwxr-x---. 3 apache apache 4096 6 juil. 10:01 phpinfo > drwxr-x---. 3 apache apache 4096 6 juil. 09:41 slackbox-mail > drwxr-x---. 3 apache apache 4096 6 juil. 09:37 slackbox-site > drwxr-x---. 3 apache apache 4096 6 juil. 09:42 unixbox-mail > drwxr-x---. 3 apache apache 4096 6 juil. 09:38 unixbox-site > > Directories are all drwxr-x---, while files are -rw-r-----. > > Now some guy on the french forum fr.centos.org told me that I got > everything wrong, and that my setup is a security flaw, without > elaborating any further though.> So I thought I'd ask on this list (which is a little bit more urbane > than the french forum). > > 1. What is wrong with my setup ?Possibly what he means is that having the files and directories writeable by the process that the web server runs as is a security issue. i.e. if there are any security issues with httpd, or the code that runs on the sites, then without a privilege escalation the exploit would run as the apache user, which means that the exploit can write to those directories resulting at the least a defaced site or at worst the upload of a more problematic exploit.> > 2. What do you suggest ?Have as few directories/files owned by the web server process as possible. If you have an application that needs to write to a file or upload to a directory, then they do need to be owned & writeable by apache. The files do need to be readable by the apache user, so the file permissions are usually 644 (with directories 755) and owned by root.root - although the actual owner doesn't matter so long as apache can read the files. I suppose if you are really paranoid, then set the owner to nobody.nobody> > BTW, I don't mind to RTFM, even extensively. >There's lots of pages out there about hardening Apache and what file ownership and permissions the site should have. Everyone has their opinion and the defaults for different distros varies. But the underlying idea is that the web server files should not be owned by the process that the web server runs as. P.
On Friday, July 7, 2017 5:25:29 AM CDT Nicolas Kovacs wrote:> Hi, > > I have a series of websites hosted on two CentOS 7 servers, using Apache > virtual hosts. One of these servers is a "sandbox" machine, to test > things and to fiddle around. > > Since Apache is running as system user 'apache' and system group > 'apache', I thought it sensible that hosted files be owned by that process. > > # ls -l /var/www/html/ > total 24 > drwxr-x---. 3 apache apache 4096 6 juil. 09:37 default > drwxr-x---. 3 apache apache 4096 6 juil. 10:01 phpinfo > drwxr-x---. 3 apache apache 4096 6 juil. 09:41 slackbox-mail > drwxr-x---. 3 apache apache 4096 6 juil. 09:37 slackbox-site > drwxr-x---. 3 apache apache 4096 6 juil. 09:42 unixbox-mail > drwxr-x---. 3 apache apache 4096 6 juil. 09:38 unixbox-siteHi Niki - Pete Biggs has weighed in with one way of setting Apache permissions. His basic contention is right on: The user under which the Apache process runs should not have write permissions. The method we adopted at my last job goes like this: All of our CentOS7 servers are members of Active Directory. We created an AD group which contains the user names of our web developers. We do not have any Web services that require writing data back to the server, so we do not have that complication to deal with. We also have nothing that writes to a database. On the CentOS server everything is owned by nobody and has a group of devs at ad.com. chown -R nobody:devs at ad.com /var/www/html File permissions are 574. Note that owners are NOT required to have higher permissions than groups! find /var/www/html -type f -exec chmod 574 {} \; Directory permissions are 575. The eXecute bit must be set so that Apache can navigate into the subdirectories. find /var/www/html -type d -exec chmod 575 {} \; The group sticky bit is set on directories. That means any new directories created by the developers will have a group of devs at ad.com. find /var/www/html -type d -exec chmod g+s {} \; We also set ACLs on the directories so that new files and directories have the desired permissions. I don't remember the exact command for that. Setfacl is pretty finicky! The end result can be a bit messy since new files in the html directory will be owned by the developer who copied them up. I have not found a way to force ownership to nobody. That doesn't matter, though, since Apache does not use owner permissions and web developers get permissions through the group settings. If you are picky about this, it is easy to set a cron job that runs chown on a regular basis. -- Bill Gee
On Fri, 7 Jul 2017, Bill Gee wrote:> File permissions are 574. Note that owners are NOT required to have higher > permissions than groups!But the owner can change the permissions, no? 574 is a properly perculiar permission to set. jh
> > File permissions are 574. Note that owners are NOT required to have higher > permissions than groups! > > find /var/www/html -type f -exec chmod 574 {} \;Normal files really shouldn't have their execute bit set. There is no need to (since they aren't going to be executed) and just sets up security issues If you want to have only group write permissions on normal files you should set the permissions to 464 (-r--rw-r--). P.
Le 07/07/2017 ? 12:53, Pete Biggs a ?crit :> There's lots of pages out there about hardening Apache and what file > ownership and permissions the site should have. Everyone has their > opinion and the defaults for different distros varies. But the > underlying idea is that the web server files should not be owned by the > process that the web server runs as.Thanks very much. I just updated the relevant information on my blog. https://blog.microlinux.fr/apache-centos/ https://blog.microlinux.fr/apache-ssl-centos/ Cheers, Niki -- Microlinux - Solutions informatiques durables 7, place de l'?glise - 30730 Montpezat Web : http://www.microlinux.fr Mail : info at microlinux.fr T?l. : 04 66 63 10 32