When developing a program that uses/requires specific capabilities (e.g. cap_net_raw
), what is the recommended method for integrating the process of granting capabilities into the build process?
If I've understood the capabilities inheritance correctly, in order for the build system (e.g. CMake
) to be able to invoke setcap
to modify the capabilities of the build outputs, it would have to have the cap_setfcap
capability itself, or be ran with sudo
. And same for the parent context, be it a shell (e.g. bash
) or an IDE (e.g. VS Code).
The scheme above works nicely for debugging, e.g. to debug a program that requires cap_X
, I needed to give the same capability to gdb
and configure it to NOT start the program in a shell (to avoid having to give the same capability to bash
; I.e. the method outlined in this excellent thread: gdb appears to ignore executable capabilities)
Now, my obvious first choice would be to give the build system ( CMake
) the cap_setfcap
capability so that it can give the required capabilities to the build targets. This doesn't feel like proper solution, but more like an attempt to circumvent the whole capabilities system/framework, instead of operating within it.
Invoking setcap
using sudo
from the build also sounds like a bad idea, because it doesn't work nicely when invoking builds from within an IDE.
I figured I could add the following into sudo configuration:
<my-username-here> ALL=(ALL) NOPASSWD: /sbin/setcap
But this (use of sudo) also feels like a workaround and not a proper solution.