sudoers script and file access

Support for security such as Firewalls and securing linux
Post Reply
gw1500se
Posts: 222
Joined: 2012/05/07 13:53:35

sudoers script and file access

Post by gw1500se » 2019/07/20 14:01:53

I have a script that accesses a root owned file. I have the script in sudoers and the suid bit set. However, when the script runs, it gets a permissions denied when trying to access that file. Since it is a suid script owned by root should it not be running as root and have access to that script? Do I need to do something else with the script? TIA.

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

Re: sudoers script and file access

Post by TrevorH » 2019/07/20 14:58:53

Scripts can't have the suid bit set - well, they can but it's ignored. To get it to run via sudo you need to prefix the command with "sudo ".
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

gw1500se
Posts: 222
Joined: 2012/05/07 13:53:35

Re: sudoers script and file access

Post by gw1500se » 2019/07/20 20:19:16

The script is in the sudoers file so any user can run it without a password. The problem is the script needs to read a file with restricted access.

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

Re: sudoers script and file access

Post by TrevorH » 2019/07/21 12:31:20

So what command are you running when you have the problem with it not working with sudo? What exactly do you type?
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

gw1500se
Posts: 222
Joined: 2012/05/07 13:53:35

Re: sudoers script and file access

Post by gw1500se » 2019/07/23 13:20:11

Not sure how this helps but the command is my script named 'VPNsudo.py'. That entry in sudoers is:

ALL ALL=NOPASSWD: /usr/local/bin/VPNsudo.py

That script needs to run as root (setuid bit) in order to access the restricted file it needs.

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

Re: sudoers script and file access

Post by TrevorH » 2019/07/23 13:57:21

Again, you cannot set the suid bit on a script. Well, you can set it but it is ignored.

So to do what you need to do you need to run sudo /usr/local/bin/VPNsudo.py

If you don't run it prefixed with sudo then it is not run via sudo so /etc/sudoers has no effect. It's not magic.
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

Post Reply