I have an apache running under user apache with a lot of permissions (rw to multiple directories). Now I want to let some users upload programs/scripts via webform and execute them, with php function exec() in file upload php page. However, I don't want those programs to be able to write anything to hard drive. It seems program sudo might do what I need, but I don't know how to use it.Shorter: how to run programs and scripts in readonly mode under powerful user?In case it matters, my system is Centos 6.
Run program in readonly mode
permissions;apache httpd;readonly;sandbox
You're right, sudo to a user with read but not write permission will run a command in a way that only has write access to files you give it permission for.sudo -u some_user cmdnameRunning arbitrary user-uploaded programs requires extreme security precautions.  Local-root exploits are unfortunately not uncommon in Linux.  Letting users run programs they upload without some kind of jail / containment, if not a virtual machine, is unwise.You should build your system so it's still at least probably secure even if the uploaded program takes advantage of an unpatched root exploit, to elevate its privileges from nobody to root.