LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-03-2016, 09:22 AM   #1
RicCrouch
LQ Newbie
 
Registered: Jun 2001
Posts: 6

Rep: Reputation: 0
CGI scripts that require elevated privilege


Hi,
First, the situation.... user has two servers: one live, one development. User wants the capability to swap between the two using a button/link on a web page. This would result in a change to a config file which the web user obviously wouldn't ordinarily have access to.

I figure I can use a link to trigger a CGI script which changes the config file, but how do I allow the script to have the access to the config file without hardcoding the password into it?

Sorry this isn't terribly detailed--I can fill in the gaps as need be, but I didn't want to get too "in the weeds" right off the bat if it's not needed.

Thanks,
Ric
 
Old 03-03-2016, 09:31 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
You could add the webserver user to sudoers for a specific task and then have your CGI script call "sudo /whatever/the/script/is"
 
Old 03-03-2016, 09:35 AM   #3
RicCrouch
LQ Newbie
 
Registered: Jun 2001
Posts: 6

Original Poster
Rep: Reputation: 0
But how does the webserver enter the sudo password? By that I mean if I am sitting at a terminal and use "sudo <command>", I am checked against the sudoers file then prompted for my password.

(I am brand new to CGI,so I'm not used to having communicate back to an HTML page! )

Thanks!
 
Old 03-03-2016, 09:38 AM   #4
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
sudoers can be set up to execute without a password. Just make sure you restrict it to only run the one script elevated.
 
1 members found this post helpful.
Old 03-05-2016, 09:19 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by RicCrouch View Post
But how does the webserver enter the sudo password? By that I mean if I am sitting at a terminal and use "sudo <command>", I am checked against the sudoers file then prompted for my password.

(I am brand new to CGI,so I'm not used to having communicate back to an HTML page! )
As TenTenths noted, you can set that user up to not need a sudo password. But, what kind of security will you have on that web page, to make sure some random person doesn't click that button?

You could put some rudimentary security in place with a .htaccess file, so unless you were set up beforehand, you couldn't load the page. If it's database driven, a simple web form to prompt for user/password that's already in the database would suffice. And neither may be needed in your situation...just an observation.
 
Old 03-05-2016, 09:26 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,841

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
I would rather use different files to read those setups and user only allowed to change which one to use.
 
Old 03-05-2016, 10:01 AM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by TB0ne View Post
As TenTenths noted, you can set that user up to not need a sudo password. But, what kind of security will you have on that web page, to make sure some random person doesn't click that button?
You can also set it up so that the "NOPASSWD" applies just to one, specific command, including a specific set of arguments. For example, one line of my sudoers file is
Code:
rnichols omega-3g,localhost = NOPASSWD: /sbin/iptables -t mangle -vnxL
which allows my otherwise unprivileged cron job to examine the packet and byte counts in some iptables rules without needing a password. But, that's all it can do. Anything else would require a password.
 
Old 03-05-2016, 10:57 AM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by rknichols View Post
You can also set it up so that the "NOPASSWD" applies just to one, specific command, including a specific set of arguments. For example, one line of my sudoers file is
Code:
rnichols omega-3g,localhost = NOPASSWD: /sbin/iptables -t mangle -vnxL
which allows my otherwise unprivileged cron job to examine the packet and byte counts in some iptables rules without needing a password. But, that's all it can do. Anything else would require a password.
Very true, and well noted. I was thinking more towards web-page security...even with a single-command sudoer's file, I personally wouldn't want some random person just clicking a button to modify system configs.
 
Old 03-06-2016, 08:43 PM   #9
RicCrouch
LQ Newbie
 
Registered: Jun 2001
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks for all the help!

Unsurprisingly, faced with the issues, the user decided it was just too complex.



Thanks, all!
Ric
 
  


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
Cant seem to run any cgi scripts in cgi-bin folder, confused? j.smith1981 Linux - Server 5 02-14-2011 05:38 AM
running shell scripts that require root priv. in ubuntu bbb125 Linux - Newbie 5 08-23-2010 03:51 AM
Urgent : Automated scripts require to check device file in hpux manish_meet_in Linux - Newbie 4 01-26-2007 01:45 PM
Apache 2.0.52 and CGI scripts ZC1 Linux - General 3 05-18-2006 01:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:21 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