[SOLVED] Using sudo to give read access to specific directory
Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
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.
Using sudo to give read access to specific directory
I have a log server that collects logs from all the cisco devices on our network. The company policy states that any logs should only be accessible by root. So I have the following permissions set on the directory, as well as everything inside the directory where the cisco logs are kept.
Code:
drwx------ 65 root root 4096 Apr 29 7:38 rsyslog
The cisco folks are requesting access to these logs, which is allowed by company policy. Now here is where it gets complicated. I need to give the cisco folks access to the logs without, 1 giving them access to root, 2 changing the permissions on the files.
So I was thinking, is there anyway I can give them access through sudo? I know you can limit sudo to certain commands, is there a way I can use sudo to give them read access to the above directory?
You can use acl to limit their access. You don't have to give them sudo access.
To use acl you have to enable the partition for acl.
Let me know on which partition and directory under which these logs are located is mounted and output of your /etc/fstab so that I can have a look on which partition you need to set acl option.
The cisco folks are requesting access to these logs, which is allowed by company policy. Now here is where it gets complicated. I need to give the cisco folks access to the logs without, 1 giving them access to root, 2 changing the permissions on the files.
If we will give them access using sudoers I think that will give them little more than what they require :-)
In a mathematical sense you are bypassing the requirement:when you use an ACL to give other users access to it. It can be done with sudo though:
Code:
Cmnd_Alias LIST = /usr/bin/less /var/rsyslog/messages
%cisco ALL = (root) NOPASSWD: LIST
in /etc/sudoers.
I am going to do a write up on both possibilities and present them to my boss. I will let him make the decision on how this should be done, or at least give him the option to make the decision.
@T3RM1NVT0R Thank you kindly for this, I think this is the way we will go.
@Reuti inside the /var/log/rsyslog directory is about 50 directories, on for each cisco device on the network. Is there a way to use a wild card to give them sudo access to all those directories under /var/log/rsyslog?
for example:
Code:
Cmnd_Alias LIST = /usr/bin/less /var/rsyslog/*
%cisco ALL = (root) NOPASSWD: LIST
Also, using sudo in this way would limit them to using less correct? They would not be able to tail, cat, etc...
Yes, you can use an asterisk but it would allow them to specify: /var/rsyslog/../spool/anyfile It would be more safe to list the exact file. You can use the shell's matching of wildcards though. Maybe all sub-directories start with the same prefix or so.
Yes, it's exactly one command you allow. You can specify more in the Cmnd_Alias and separate them by a comma or define another Cmnd_Alias.
rwx= read, write, execute
user will be the switch
username will be the username of the user whom you want to give access
To verify if the acl you set is working type getfacl /var/log/rsyslog
Edit:: Make sure you take backup of /etc/fstab before making any modifications.
I have change the options in /etc/fstab and remounted. I have added the acl with the setfacl command but we do not want them to have write permissions so I used r-x only.
The company policy states that any logs should only be accessible by root
Who wrote that policy? What that means, if I'm reading correctly, is that you must give root to cisco in order for them to access the logs.
If it's allowed to give them access, then do it the right way, make a group called "logreaders" and add the cisco user to that group. then change the ownership/permissions so it looks like:
Code:
drwxr-x--- 65 root logreaders 4096 Apr 29 7:38 rsyslog/
-rw-r----- XX root logreaders <========= everything under rsyslog/
Then your cisco user need only do:
Code:
cat /var/log/rsyslog/XXXXX
Doing it with sudo is dangerous. I can think of a number of bypasses that can be effectively carried out with a sudoers that will be written in a hasty manner.
I've found that using setfacl also changes the base entry of the group, and some programs check for this (for security). Is there any way to give access to a second user without giving access to a group? Thanks.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.