Sorry if this isn't the right QA forum. I couldn't think of where else to post this question.
The Linux kernel has supported capability-based security for quite some time but I don't see many distributions taking advantage of it. For example, if I want to fiddle around with packet filtering rules I just sudo su - like a madman and run iptables from the shell. If I want start/stop some VMs, boom it's sudo su - again and then virsh or whatever. This is horribly insecure and worse, it's easy to do something I didn't intend.
It seems like using capabilities would work better. If I want my user foo to be able to modify rules for network stack, I should
- Create a
network_admingroup - Create a binary with
CAP_NET_ADMINthat prompts the user for their password and then spawns a shell - Set the permission bits on the binary so that only members of
network_admincan start the shell - Add
footo mynetwork_admingroup
This is essentially what most distros do with the sudoers or wheel group, except it's only one capability: full control of the system. I don't see any distros directly supporting something similar to this kind of capabilty-based admin workflow, and it makes me think I am misunderstanding the usefulness of such a setup.
Is there a good reason that most major distros still use sudo as a swiss-army knife instead of a more granular capability-based approach?
iptableswill do something beyondCAP_NET_ADMINthen I understand your concern. If you're afraid you will type something you didn't intend then IMO the first thing is not to start an elevated shell. I start an elevated shell only when there's a risk of locking myself out in a regular shell; and I still don't use it, it's there just in case. I runsudo specialized_commandwhere needed, and I don't usesudowhere not needed (including parts of pipelines). Working in an elevated shell is likesudo-ing an entire script. – Kamil Maciorowski Nov 08 '23 at 06:11sh <(curl "whatever")and then you get a sudo prompt. – Ben Little Nov 08 '23 at 18:34