Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm pretty new at this. So I figured out that apache2 starts processes as www-data user. Suppose this user then starts untrusted code. What if I wanted to disallow this user to read any files (like /etc/fstab for example). How would I go about this? Ubuntu 11.04 by the way.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You could deny by chmoding those files so that www-data user can't read them.

One of tricks you could use would be to change group of those files to www-data group and set mod so that group can't read the files.

$ chgrp www-data /etc/fstab
$ chmod g-rwx /etc/fstab

From php side you can use open_basedir which would in some cases prevent reading files outside path set as open_basedir

share|improve this answer

Are there secrets in /etc/fstab you don't want users reading?

In general, you'd remove r access for others on the files, but fstab contain no secrets so you just likely to break things.

Specifically with Apache, you probably have the option to run it in a chroot, so it can't read outside of /var/www or where ever your httpd lives.

share|improve this answer
    
I was hoping I coud set read privileges per user instead of per files. Chroot is not an option since it looks like you can't run executables since they can't find shared libraries under new root. –  ren Sep 18 '11 at 12:58
1  
I wasn't suggesting you create a full jail for every application, rather the application you need has support for the chroot(2) call. Apache 1.3 and most other daemons in OpenBSD are examples of this. Instead, if you want to set read privs per user, you'd need something along the lines of SELinux or the TrustedBSD efforts for FreeBSD. –  Alex Holst Sep 22 '11 at 5:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.