Two possible approaches to determine required capabilities at runtime:
- Subsequently run your program under
strace
without root privileges. Determine which system calls failed with EPERM
and add corresponding capabilities to your program. Repeat this until all capabilities are gathered.
- Use
SystemTap
, DTrace
or Kprobes
to log or
intercept capability checks in kernel made for your program. (e.g. use capable
from BCC tools suite as described here)
Unit tests with good coverage will help a lot, I guess. Also note that capabilities(7) manual page lists system calls that may require each capability (although it is not a complete list).
Update:
The article referenced by @RodrigoBelem mentions capable_probe
module, which is based on KProbes
.
Original article with this module was "POSIX file capabilities: Parceling the power of root" and it's not availble now (it was hosted here). But you can find the source code and some docs in the Internet.