#capabilities-vs-suid
What are Linux capabilities and why are they better than SUID?
Что отвечать
Capabilities split root privileges into about 40 separate bits (`CAP_NET_BIND_SERVICE`, `CAP_SYS_ADMIN`, `CAP_NET_RAW`, and so on). You can grant a binary just the slice of root it needs with `setcap cap_net_bind_service=+ep /path/to/binary`. It runs without SUID, as an unprivileged user, but with one specific capability. SUID gives ALL of root; capabilities grant exactly what is needed.
Что хотят услышать
A senior should: - name `CAP_NET_BIND_SERVICE` (binding ports below 1024 without root) as the classic example of replacing the SUID bit on nginx or apache - say that `ping` was historically SUID, and on modern Linux it uses the `cap_net_raw+ep` capability - tell apart the permitted, effective, and inheritable sets (the PIE flags in `setcap`) - mention `getcap -r /usr/bin 2>/dev/null` to audit what holds capabilities on the system - name ambient capabilities (Linux 4.3+) as the fix for 'how to pass a cap to a child process without SUID' in runuser scenarios
Подводные камни
- ✗ Saying capabilities fully replaced SUID. There are legacy binaries, and not every capability covers the scenario you need.
- ✗ Not separating permitted and effective: a binary with permitted but without effective runs as unprivileged.
- ✗ Thinking `setcap` survives a copy. No, the xattrs are lost through scp without `-p`, and through a docker build.
Follow-up
- ? Why is `setcap` lost when you `cp` a binary without flags?
- ? What are ambient capabilities, and what problem do they solve?
- ? Why is `CAP_SYS_ADMIN` called the new root?
Глубина в базе знаний
- Linux capabilities: privilege bits
- [[setuid-setgid-sticky]]
- File permissions: rwx and chmod