1

I build a website that automatically manages a dedicated server. It does all sorts of things like creating users and apache settings to point to their home directory.

The home directories host game binaries, and the home folder can be accessed from the web, but only non-essential resource files (.wav .mdl .spr etc) can be accessed, that's how apache is configured. So for this to work, I need execute and read permissions on all files.

The problem is that binaries run in one user's home folder can access other users' home folder, read and write to files in there.

How can I make a user's home directory unaccessible to anyone else but him and via apache? Here's what the folder tree looks like:

http://i.imgur.com/LVFMle2.png (no rep to show image directly)

Aron
  • 13
  • 3
  • @Matt the files are not created by apache, apache merely executes cp -rp to copy a folder and it's contents and keep all permissions intact. That means that all I have to do is change permissions on the "source" folder and the same permissions will be present on user files. Your answer seems unrelated though. – Aron Aug 12 '15 at 21:03

2 Answers2

2

Set an ACL on each user's home directory, to which Apache needs access. This lets you avoid silly tricks with groups, which can actually cause more problems than they solve.

For example:

setfacl -R -m u:httpd:rx,d:u:httpd:rx /home/username

will allow the httpd user to read everything in that directory, including subdirectories and any newly created files.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
0

I'd suggest having each user's home directory being owned by the user and the user's group and only user and group can get into the directory (770), and then make Apache be a member of each user's group.

Also, be sure to implement some form of symlink attack protection (see https://documentation.cpanel.net/display/EA/Symlink+Race+Condition+Protection for some options - this link does not just apply to cPanel).

An approach which would keep things simple and not require symlink attack protection would be to use MPM ITK if you don't mind the speed hit (and see also the "Quirks and Warnings" on its homepage). In that case Apache runs as each individual website user.

You can also check out Multi-site hosting - important vulnerability being missed to secure sites from each other? for a discussion of multi-site hosting security and some other approaches.

Disclaimer: I can't promise that any suggestion above is 100% secure so use at your own risk =).

sa289
  • 1,308
  • 2
  • 17
  • 42
  • 1
    I will probably set up containers because I need them anyways for resource management. That should keep things safe, right? I wanted to know how other people fix this though because I thought I understood permissions well enough, but I don't. – Aron Aug 12 '15 at 21:21