A container is run --user 1000:1000 --cap-add chown and tries to chown a file, but gets Operation not permitted. Why?
Capabilities apply to the root user (UID 0). As a non-root user (UID 1000) the process isn't the file owner and isn't root, so even with CAP_CHOWN granted it can't change ownership — the two controls stack.
This card ties two defences together and shows they are independent, additive layers:
- Capabilities govern what a privileged (root) process may do.
CAP_CHOWNlets root change any file's owner. - Running
--user 1000:1000means the process is not root. Ordinary permission rules still apply: a non-owner, non-root user may notchowna file, full stop.
So granting --cap-add chown to a non-root process doesn't help — capabilities refine root's powers, they don't elevate a normal user to be able to do root-only things in general. The chown is denied by the ordinary DAC permission check before the capability ever comes into play.
The security takeaway is reassuring: combining non-root and dropped capabilities is stronger than either alone. An attacker would need both a way to become root in the container and the specific capability for the operation — defence in depth. (By contrast, running as root --cap-add chown does let the chown succeed, because then the process is UID 0.)
* Non-root AND dropped capabilities stack — defence in depth. *
Go deeper:
man7.org: capabilities(7) — how capabilities refine root's powers but don't elevate a normal user.