Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

If I want to set a capability (capabilities(7)), such as CAP_NET_BIND_SERVICE, on an executable file and that file is a script, do I have to set the capability (setcap(8)) on the interpreter starting that script or is it sufficient to set it on the script file itself?

Note: the question concerns Scientific Linux 6.1 in particular, but I think it can be answered generically.

share|improve this question

1 Answer

up vote 3 down vote accepted

Setting capability on the script will not be effective. It's the similar situation as not working setuid bit on script. Similar as in the latter case it's the implementation of how execve handles shebang and the security reasoning behind it (for details see: Allow setuid on shell scripts).

I think you have these options

  1. set the capabilities on interpreter itself (actually rather a copy of it)

    • you have a problem here that anybody who is able to execute it will run with those elevated capabilities (be able to execute some arbitrary script or start it interactively)
  2. write a wrapper executable which will have a hardcoded logic to execute your script, and set desired capabilities on this executable

    • make sure that nobody is able to modify nor remove / replace the script
    • still by doing chroot one might missuse such wrapper

In both cases you would have to make sure capabilities set will survive execve by setting inheritable flag. You might also use pam_cap distributed with libcap usually, to actually activate desired capabilities by configuration only for selected users.

And in general you want to make sure nobody is able to modify behavior of your interpreter by changing environment eg. PYTHON_PATH or something similar.

share|improve this answer
 
Thanks for the answer. However, I think for this particular capability this is fine. It won't open a big hole and at the same time will allow me to run the script as unprivileged user on port 80 (and eventually 443). –  0xC0000022L Aug 19 at 20:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.