Linux - Server This forum is for the discussion of Linux Software used in a server related context. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
12-13-2010, 10:23 AM
|
#1
|
LQ Newbie
Registered: Jun 2008
Location: Near Boston, MA, USA
Distribution: SuSE
Posts: 7
Rep:
|
Why is apache user's filesystem access restricted?
In CGI scripts, there are certain files that are getting "permission denied" when it seems they should be accessible by the apache user. I am running the default package install of apache under fedora. Here is an example:
The following is /var/www/cgi-bin/test.pl
Code:
#!/usr/bin/perl
use strict;
use CGI;
print CGI->header, CGI->pre;
my $file = "/home/ep/x";
if(open FH, $file) {
while(<FH>) {
print;
}
} else {
print "Couldn't open $file: $!";
}
If I run it from the command line,
Code:
sudo -u apache /var/www/cgi-bin/test.pl
it runs fine, but when I open http://localhost/cgi-bin/test.pl I get this error message:
Code:
Couldn't open /home/ep/x: Permission denied
Here are file listings:
Code:
% ls -l /home/
total 4
drwxr-xr-x. 24 ep ep 4096 Dec 13 11:07 ep
% ls -l /home/ep/x
-rw-r--r--. 1 ep ep 447 Dec 13 10:50 /home/ep/x
It seems like apache should be able to open this file. When I set up the same things under ubuntu I have no problem. This is a big problem for me because I can't open my Perl modules from CGI scripts. What am I doing wrong?
Thanks,
Brad
|
|
|
12-13-2010, 07:45 PM
|
#2
|
Senior Member
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141
Rep: 
|
If the apache user can access that part of the file system then maybe the server configuration is preventing access. Have you tried setting up a directory entry in the .conf file to allow access to that directory?
|
|
|
12-13-2010, 09:02 PM
|
#3
|
LQ Newbie
Registered: Jun 2008
Location: Near Boston, MA, USA
Distribution: SuSE
Posts: 7
Original Poster
Rep:
|
Quote:
Originally Posted by gilead
If the apache user can access that part of the file system then maybe the server configuration is preventing access. Have you tried setting up a directory entry in the .conf file to allow access to that directory?
|
Thank you for the suggestion, gilead.
I tried adding the following to my httpd.conf file, then restarting apache:
Code:
<Directory /home/ep>
Order allow,deny
Allow from all
</Directory>
but it doesn't seem to change the result. Is this the kind of directive you had in mind? Does apache still have any say over filesystem access once the CGI program starts?
|
|
|
12-13-2010, 09:59 PM
|
#4
|
Senior Member
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141
Rep: 
|
Apache can control access to the filesystem - but I only found limited info on interaction between the Apache process and the running of CGI scripts.
Can you copy the /home/ep/x file to a location that you already know the scripts can see to confirm whether this might be the problem?
|
|
|
12-13-2010, 10:49 PM
|
#5
|
LQ Newbie
Registered: Jun 2008
Location: Near Boston, MA, USA
Distribution: SuSE
Posts: 7
Original Poster
Rep:
|
Quote:
Originally Posted by gilead
Apache can control access to the filesystem - but I only found limited info on interaction between the Apache process and the running of CGI scripts.
Can you copy the /home/ep/x file to a location that you already know the scripts can see to confirm whether this might be the problem?
|
Yes I can place the file in /var/www/cgi-bin/x or in /x and it seems to work fine. If I put it in /home/x it gives the "Permission denied" error. Relevant directory listings:
Code:
% ls -l /var/www/cgi-bin/x
-rw-rw-r--. 1 ep ep 80 Dec 13 14:16 /var/www/cgi-bin/x
% ls -l /x
-rw-rw-r--. 1 ep ep 80 Dec 13 14:16 /x
% ls -ld /home
drwxr-xr-x. 3 root root 4096 Dec 13 14:17 /home
% ls -l /home/x
-rw-r--r--. 1 root root 80 Dec 13 14:17 /home/x
% ls -ld /home/ep
drwxr-xr-x. 26 ep ep 4096 Dec 13 14:09 /home/ep
% ls -l /home/ep/x
-rw-rw-r--. 1 ep ep 447 Dec 13 14:09 /home/ep/x
Could /home somehow be toxic to CGI scripts in my configuration? Thanks for your help.
|
|
|
12-14-2010, 12:00 AM
|
#6
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,434
|
I'm pretty sure you have to set the ScriptAlias directive or equiv in the conf file. http://httpd.apache.org/docs/2.0/howto/cgi.html
|
|
|
12-14-2010, 10:24 AM
|
#7
|
LQ Newbie
Registered: Jun 2008
Location: Near Boston, MA, USA
Distribution: SuSE
Posts: 7
Original Poster
Rep:
|
Solution
I found the problem: SElinux is running. If I type
it says "Enforcing". If I turn it off with
then everything works fine! I guess SElinux is the default for fedora.
Thanks for everyone's help!
|
|
|
12-14-2010, 10:47 AM
|
#8
|
Moderator
Registered: May 2001
Posts: 29,415
|
While disabling SELinux at first glance seems to be the perfect solution do ask yourself if any "extra" security should really be disabled on 'net-facing networks, if you're a novice web developer or when running Pretty Horrific Programming (PHP) applications. SELinux has tunable settings ('getsebool -a | grep http') for allowing the web server access to content in /home and more.
|
|
1 members found this post helpful.
|
12-14-2010, 04:51 PM
|
#9
|
LQ Newbie
Registered: Jun 2008
Location: Near Boston, MA, USA
Distribution: SuSE
Posts: 7
Original Poster
Rep:
|
Quote:
Originally Posted by unSpawn
While disabling SELinux at first glance seems to be the perfect solution do ask yourself if any "extra" security should really be disabled on 'net-facing networks, if you're a novice web developer or when running Pretty Horrific Programming (PHP) applications. SELinux has tunable settings ('getsebool -a | grep http') for allowing the web server access to content in /home and more.
|
Thanks for the tips, unSpawn. A better solution would be to release only those resources necessary for my application. Time to read up on SElinux.
|
|
|
12-15-2010, 04:56 AM
|
#10
|
Moderator
Registered: May 2001
Posts: 29,415
|
If setroubleshootd and auditd are installed and enabled and you boot into runlevel 5 (GUI) then you should have seen warnings pop up. If you're in a CLI-only environment then you have to check things yourself. Quickest way in the GUI would be to browse events using 'sealert -b', in the CLI you could 'audit2allow -ave > /tmp/a2a.log; less /tmp/a2a.log' and review the explanations. If you have any questions wrt tool output or SELinux in general feel free to create a new thread in this or the Security forum.
|
|
1 members found this post helpful.
|
All times are GMT -5. The time now is 11:21 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|