LinuxQuestions.org
Help answer threads with 0 replies.
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 11-07-2012, 03:54 PM   #1
acunacha
LQ Newbie
 
Registered: Nov 2012
Posts: 15

Rep: Reputation: Disabled
Sudoers and vi editor


Hi,

I need to configure on S2 the user jsmith as a sudoer to use vi to edit files in /etc/apache2, jsmith should require no password to edit files.
Also, on S1 i need to configure the lsmith user as a sudoer to shutdown the computer, lsmith requires a password shutdown.

What I did:

-- visudo
-- added the following lines:
User_Alias VIAPACHE = jsmith
Cmnd_Alias VI2APACHE = /usr/bin/vi /etc/apache2/
Host_Alias S2 = S2
VIAPACHE S2 = (root) NOPASSWD: VI2APACHE

I then save and close visudo, su jsmith, and try the command:

sudo vi /etc/apache2/httpd.conf

But after entering jsmith's password (which should not be asked) I get the error:

"Sorry, user jsmith is not allowed to execute '/usr/sbin/vi /etc/apache2/httpd.conf' as a root on S2"


Of course I am doing something wrong, could you please tell me what it is?

Thanks in advance,

Diego
 
Old 11-07-2012, 05:43 PM   #2
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Your Cmnd_Alias doesn't match the command you're running

Quote:
Cmnd_Alias VI2APACHE = /usr/bin/vi /etc/apache2/
/usr/sbin/vi /etc/apache2/httpd.conf
 
Old 11-07-2012, 05:43 PM   #3
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Your Cmnd_Alias doesn't match the command you're running

Quote:
Cmnd_Alias VI2APACHE = /usr/bin/vi /etc/apache2/
/usr/sbin/vi /etc/apache2/httpd.conf
 
Old 11-07-2012, 06:09 PM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
You never let a user run Vi or similar texteditors as root, even if you try to limit it to a few files only. Once Vi runs as root it can launch as many shells as root as the user want, in fact becoming root on the system without limitations.
 
2 members found this post helpful.
Old 11-07-2012, 08:16 PM   #5
acunacha
LQ Newbie
 
Registered: Nov 2012
Posts: 15

Original Poster
Rep: Reputation: Disabled
Thank you guys,

But, in this case, how would I allow jsmith to edit any config file in the /etc/apache2/ directory? What would you recommend?
 
Old 11-07-2012, 08:19 PM   #6
ph0rty
LQ Newbie
 
Registered: Sep 2012
Distribution: OpenSUSE, CentOS, RHEL
Posts: 8

Rep: Reputation: Disabled
Exclamation to vi or rvi , there is no question!

As mentioned below: (2 issues)
your Cmnd_Alias should have the filename specified, or *
eg:
/usr/sbin/vi /etc/apache2/httpd.conf
or
/usr/sbin/vi /etc/apache2/*

HOWEVER, (as mentioned as well) giving people access to vi via sudo is giving away a root shell.
you need to use
rvim or rvi instead, which will prevent users from exiting into a shell.
 
Old 11-07-2012, 08:26 PM   #7
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Here the point is not to give root access to an user, but to allow the user to edit a specific file. Using file-permissions for this is a much better approach here. Create a new group, change the group ownership of the files the user has to edit to that group, allow write-access for that group, than add the user to that group.
 
2 members found this post helpful.
Old 11-07-2012, 09:01 PM   #8
acunacha
LQ Newbie
 
Registered: Nov 2012
Posts: 15

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ph0rty View Post
As mentioned below: (2 issues)
your Cmnd_Alias should have the filename specified, or *
eg:
/usr/sbin/vi /etc/apache2/httpd.conf
or
/usr/sbin/vi /etc/apache2/*

HOWEVER, (as mentioned as well) giving people access to vi via sudo is giving away a root shell.
you need to use
rvim or rvi instead, which will prevent users from exiting into a shell.
Ok, so I guess I can just edit my Cmnd alias to be: Cmnd_Alias VI2APACHE = /usr/bin/rvim /etc/apache2/*? I will test it tomorrow, but a question, is it not going to cause any security breach just by changing vi to rvim?

Thanks for your help.
 
Old 11-07-2012, 09:43 PM   #9
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
Regardless of what editor is used (and whether it allows shell escape or writing files other than the one originally opened) you've probably got a security problem arising from potential changes to apache config.

http://httpd.apache.org/docs/2.4/mis...tml#serverroot

That can be avoided if the service is _started_ by the non-root account apache is to run as (a relatively uncommon configuration).
 
Old 11-07-2012, 10:50 PM   #10
ph0rty
LQ Newbie
 
Registered: Sep 2012
Distribution: OpenSUSE, CentOS, RHEL
Posts: 8

Rep: Reputation: Disabled
Thumbs up

Quote:
Originally Posted by acunacha View Post
Ok, so I guess I can just edit my Cmnd alias to be: Cmnd_Alias VI2APACHE = /usr/bin/rvim /etc/apache2/*? I will test it tomorrow, but a question, is it not going to cause any security breach just by changing vi to rvim?

Thanks for your help.
You are welcome. I cannot comment on the security of the apache config file and what the user configures, but at least you can be sure that your user will not be able to break out into a shell.
 
Old 11-08-2012, 01:26 AM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You might want to try ACLs instead ...
 
Old 11-08-2012, 12:05 PM   #12
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Quote:
Originally Posted by acunacha View Post
Hi,

I need to configure on S2 the user jsmith as a sudoer to use vi to edit files in /etc/apache2, jsmith should require no password to edit files.
Also, on S1 i need to configure the lsmith user as a sudoer to shutdown the computer, lsmith requires a password shutdown.

What I did:

-- visudo
-- added the following lines:
User_Alias VIAPACHE = jsmith
Cmnd_Alias VI2APACHE = /usr/bin/vi /etc/apache2/
Host_Alias S2 = S2
VIAPACHE S2 = (root) NOPASSWD: VI2APACHE

I then save and close visudo, su jsmith, and try the command:

sudo vi /etc/apache2/httpd.conf

But after entering jsmith's password (which should not be asked) I get the error:

"Sorry, user jsmith is not allowed to execute '/usr/sbin/vi /etc/apache2/httpd.conf' as a root on S2"


Of course I am doing something wrong, could you please tell me what it is?

Thanks in advance,

Diego
What OS are you running?

--C
 
Old 11-08-2012, 12:49 PM   #13
acunacha
LQ Newbie
 
Registered: Nov 2012
Posts: 15

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by custangro View Post
What OS are you running?

--C
Im running SUSE Linux Enterprise Server 11
 
Old 11-08-2012, 01:54 PM   #14
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Run this command and the output

Code:
 sudo dumpe2fs /path/to/disk  | grep acl
where /path/to/disk is the volume where /etc/apache2/httpd.conf lives

--C
 
Old 11-09-2012, 07:51 AM   #15
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,294
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
Noexec

In addition to rvim, there is also the NOEXEC option in sudoers. With NOEXEC, it is possible to prevent vi from running shells. The sudoers(5) manual page has a whole section on preventing shell escapes. So use both NOEXEC and rvim.
 
  


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
[SOLVED] User not in sudoers: How to add user? Permtion Denied for sudoers file esgol Linux - Newbie 3 07-13-2012 07:44 AM
Fedora /etc/sudoers file and sudoers.d directory davejjj Linux - Newbie 2 10-21-2011 06:19 PM
GUI/WEB interactive /etc/sudoers editor grayswander Linux - Software 8 03-25-2011 10:37 PM
I deleted /etc/sudoers and creates a new file call sudoers but now it doesnt for visu abefroman Linux - Software 1 11-10-2005 05:03 PM

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

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