/etc/sudoers and piping

Support for security such as Firewalls and securing linux
Post Reply
ant2ne
Posts: 23
Joined: 2015/01/26 22:14:59

/etc/sudoers and piping

Post by ant2ne » 2015/03/24 17:40:27

Why wont this work?!

Code: Select all

nagios   ALL=(ALL) NOPASSWD: /sbin/iptables -S INPUT | /usr/bin/wc -l

Code: Select all

[nagios@server ~]$ sudo  /sbin/iptables -S INPUT | /usr/bin/wc -l
[sudo] password for nagios:

User avatar
TrevorH
Site Admin
Posts: 33218
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: /etc/sudoers and piping

Post by TrevorH » 2015/03/24 17:49:02

Because it doesn't work like that. You need to allow it to run /sbin/iptables -S INPUT as that's the part that needs root privileges. Once the sudo part sends its output out, the next portion after the pipe runs as the user who invoked sudo and wc doesn't need root privileges.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

poky
Posts: 108
Joined: 2013/03/27 12:18:03

Re: /etc/sudoers and piping

Post by poky » 2015/03/24 18:15:48

echo "/sbin/iptables -S INPUT | /usr/bin/wc -l" | sudo sh

User avatar
TrevorH
Site Admin
Posts: 33218
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: /etc/sudoers and piping

Post by TrevorH » 2015/03/24 18:31:44

There is zero requirement to run wc as root.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

ant2ne
Posts: 23
Joined: 2015/01/26 22:14:59

Re: /etc/sudoers and piping

Post by ant2ne » 2015/03/24 18:41:56

Access to /sbin/iptables -S is insecure. It gives nagios the ability to see what ports are open and from where. I can't give him that kind of power. I don't mind him knowing the number of rules, just not the details of those rules. Basically I'm trying to secure a monitoring script that I found on the net which checks to see if iptables is up or not. If it isn't up, it flags an alert and I can put it back up. Sometimes an SA may troubleshoot an issue and forget to re-enable iptables.

I can't add the path and script to the sudoers. Then if the script is compromized then nagios has reign on the box.

I can't allow nagios to gather more information than absolutely necessary to do its job.

One work around may be to have cron run

Code: Select all

 /sbin/iptables -S INPUT | /usr/bin/wc -l > /tmp/iptcount
and then nagios read /tmp/iptcount but that is another level of complexity I'd rather not manage.

Code: Select all

echo "/sbin/iptables -S INPUT | /usr/bin/wc -l" | sudo sh
also prompted for a password.

ant2ne
Posts: 23
Joined: 2015/01/26 22:14:59

Re: /etc/sudoers and piping

Post by ant2ne » 2015/03/24 18:46:54

I'm going to go another route. Thanks.

i still would like to know why the sudoers file hates the pipe "|"

Post Reply