I have a script that I want some of my users to be able to run that requires admin. Of course I don't want to give them admin privileges. How do I allow this script to run in a secure way?
Update: This is a Ubuntu 9.10 system.
|
I have a script that I want some of my users to be able to run that requires admin. Of course I don't want to give them admin privileges. How do I allow this script to run in a secure way? Update: This is a Ubuntu 9.10 system. |
||||
|
|
|
Just use sudo. You need to configure sudo in
Replace fred with the username, or use %group for a group. If you remove the NOPASSWD: option then they will be prompted for their password each time. setuid on a script is insecure and won't work on Linux. |
|||||||||
|
|
sudo and SUID are both very insecure. It's possible - and, depending on the scripting language, easy - to escape out of either of them. SUID is by far the worst, and some scripting languages won't even run if that's done. I have a blog post on how to do it securely, which I first wrote for running Nagios check plugins as root but is perfectly applicable here. There's a small C program (that's been floating around the Linux admin world for years) that just acts as a wrapper around the script. You just edit the C program source to include the full path to the script, compile it, and then set that SUID (or give sudo access to that). The source is on my site: setuid-prog.c. The inherent problem with running scripts as root (for non-root users) is that in many languages, using a variety of techniques (from poor input checking to overflows) it may be possible to break out of the running script and get full root access. Many old-time Unix guys recommend just writing a C program to do what you need - but then again, most of them were SAs when you needed to be able to write C competently. |
|||||
|
|
On which OS? On Linux/Unix you can allow them to run it via sudo. The /etc/sudoers file can be modified to grant them specific permissions on designated commands, to certain IDs (users). Alternatively, you can set the SUID bit on it, and change the script to be owned by a privileged user. That would set the script to run as that user, rather than the user running it. However, that is for all users running it. |
|||||||
|
|
There are two ways: The best is to set the SUID bit on it: Alternatively, you can give them access to modify it using |
|||||||||||
|