LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-13-2010, 10:23 AM   #1
apomatix
LQ Newbie
 
Registered: Jun 2008
Location: Near Boston, MA, USA
Distribution: SuSE
Posts: 7

Rep: Reputation: 0
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
 
Old 12-13-2010, 07:45 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
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?
 
Old 12-13-2010, 09:02 PM   #3
apomatix
LQ Newbie
 
Registered: Jun 2008
Location: Near Boston, MA, USA
Distribution: SuSE
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by gilead View Post
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?
 
Old 12-13-2010, 09:59 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
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?
 
Old 12-13-2010, 10:49 PM   #5
apomatix
LQ Newbie
 
Registered: Jun 2008
Location: Near Boston, MA, USA
Distribution: SuSE
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by gilead View Post
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.
 
Old 12-14-2010, 12:00 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,349

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
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
 
Old 12-14-2010, 10:24 AM   #7
apomatix
LQ Newbie
 
Registered: Jun 2008
Location: Near Boston, MA, USA
Distribution: SuSE
Posts: 7

Original Poster
Rep: Reputation: 0
Solution

I found the problem: SElinux is running. If I type

Code:
sudo getenforce
it says "Enforcing". If I turn it off with

Code:
sudo setenforce 0
then everything works fine! I guess SElinux is the default for fedora.

Thanks for everyone's help!
 
Old 12-14-2010, 10:47 AM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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.
Old 12-14-2010, 04:51 PM   #9
apomatix
LQ Newbie
 
Registered: Jun 2008
Location: Near Boston, MA, USA
Distribution: SuSE
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by unSpawn View Post
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.
 
Old 12-15-2010, 04:56 AM   #10
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
apache setup help needed: cannot access user's homepage parv Linux - Networking 7 02-07-2006 04:24 PM
is it possible to read from the user's filesystem irfanhab Programming 2 02-01-2006 10:36 AM
Webmin Restricted Access newinlinux Debian 4 11-28-2005 09:47 PM
Restricted access sachinh Linux - Security 2 09-29-2004 03:30 AM
encrypted filesystem with apache needing access stoffell Linux - Security 1 10-14-2003 10:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration