LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 02-18-2010, 03:50 PM   #1
Kearneyman
LQ Newbie
 
Registered: Sep 2004
Location: Austin, TX
Distribution: Alpine Linux, Bunsen Labs
Posts: 15

Rep: Reputation: 0
allow Apache to send SIGHUP to root process


I have been tasked with sending a kill -s SIGHUP (a reload) to a Daemon process owned by root running on a centOS 5.4 machine.

Obviously, Apache cannot normally do this, so I'm going to have to use the sudoers file.

My problem is, how do I allow the Apache user to only run the kill command? nothing else.

in testing, I've gotten Apache to basically run every command prefixed with sudo and no password prompting. But I want the added security to only run the kill command without the password being prompted everything else should prompt for a password.

I'm trying to understand the sudoers file, and i must say, its non-trivial.

is there a simple 1 line I can put in the sudoers file like

PHP Code:
apache   ALL=(ALL)   NOPASSWD: /bin/kill 
 
Old 02-18-2010, 04:07 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
There's nothing wrong with that line AFAICS... what other commands do you need the apache user to run ? ( as another user )
 
Old 02-18-2010, 04:11 PM   #3
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
This is a wee bit scary. Can you explain precisely the problem you're trying to solve?

---

Off the top of my head, I believe your sudoer entry would be:
Code:
apache  ALL = NOPASSWD: /path/to/program
But I could be wrong. Double check the manpages for sudoers(5), and of course you'll need to test.

All that said, what you're doing here is a bad idea. Even if your situation absolutely requires apache to kill/SIGHUP a process, you will want to do something like:

Code:
#!/bin/sh

#
# This script lives at /usr/local/bin/killer.sh. 
# You could parameterize the pid, or instead use
# pkill to match a pattern...
#

/bin/kill -s SIGHUP <pid_here>

exit 0
Next, # chown root /usr/local/bin/killer.sh ; chmod 700 /usr/local/bin/killer.sh

Then your sudoer entry will look more like:

Code:
apache  ALL = NOPASSWD: /usr/local/bin/killer.sh
This helps eliminate some of the ways to abuse the power you're granting.

Last edited by anomie; 02-18-2010 at 04:13 PM.
 
Old 02-18-2010, 04:57 PM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
<delete.. replied to wrong post>
 
Old 02-18-2010, 05:06 PM   #5
Kearneyman
LQ Newbie
 
Registered: Sep 2004
Location: Austin, TX
Distribution: Alpine Linux, Bunsen Labs
Posts: 15

Original Poster
Rep: Reputation: 0
first thank you both for the responses.

@kbp: you are correct there was nothing wrong with that line. I appeared to have fat-fingered the sudoers file.

@anomie:
Sure, I'll go into further detail.

my company is using a multi-threaded PHP Daemon
( project page if you're interested http://code.google.com/p/phpmultithreadeddaemon/ ) to monitor a directory and parse files.

There are certain times when we get more files than usual. So, I was asked to create a general web interface where anyone from within the server team could go in and increase/decrease the number of processes being spawned.

after the person changes the number of threads, and clicks the save button, the Daemon needs to be notified of the changes, which is only possible via a SIGHUP (the multi-threaded daemon application is already coded to handle SIGHUPs).

I must say, however, creating a script and giving Apache permission to only run that script is a much preferred way instead of giving Apache the kill command.

when the daemon starts, it writes its process ID to /var/run/pmtd.pid so I think instead of using pkill I'd just cat the PID from the file written to at start up.

PHP Code:
!#/bin/sh

# Get the PID from the file written to at start-up
/bin/kill -s SIGHUP `cat /var/run/pmtd.pid`
exit 
0
I greatly appreciate the help. And thank you for explaining in detail what you were doing each step.

I have been using Linux for years now and I must say, I learn something new every day.

I noticed you ended the script with exit 0; why is that? Does that have an added benefit as opposed to just letting the script run the kill command?

if you have any other questions, please feel free to ask.
 
Old 02-18-2010, 05:13 PM   #6
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
That all makes sense. Given the requirements, I don't have a substantially better solution than what you've put together...

The exit 0 is really just a formality in this case. It sticks to a convention where a script or program explicitly sets a return code to demonstrate that it finished "OK".

There's a quick writeup on exit here:
Advanced Bash-Scripting Guide: Chapter 6. Exit and Exit Status
 
Old 02-19-2010, 01:02 AM   #7
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
Your daemon can every X second check time-stamp of the config file written by web interface.
This way you don't sudo to send daemon SIGHUP
 
  


Reply



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
how a father process know which child process send the signal SIGCHLD icoming Programming 10 07-20-2010 07:26 AM
Send mail to root but it send to other email smart_jija Solaris / OpenSolaris 5 07-01-2009 01:33 AM
IPC fails between user process and root process zaryab Linux - Newbie 1 09-22-2008 01:25 AM
send process to the background ugp Programming 3 02-08-2006 10:28 PM
how to send some info to a process? puishor Programming 1 11-28-2005 03:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 10:33 AM.

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