kubernetes: allowPrivilegeEscalation:false insufficient for privilege escalation prevention
The issue relates to how allowPrivilegeEscalation: false doesn’t prevent all forms of privilege escalation through dangerous capabilities.
When a container’s security context sets allowPrivilegeEscalation: false, the current validation only blocks CAP_SYS_ADMIN capability. However, other dangerous capabilities that can also lead to privilege escalation are still allowed.
Technical Details:
-
Current Validation:
- Blocks: CAP_SYS_ADMIN when allowPrivilegeEscalation: false
- Allows: CAP_NET_ADMIN, CAP_SYS_MODULE, CAP_SYS_PTRACE, etc.
-
Example:
apiVersion: v1
kind: Pod
spec:
containers:
- name: busybox
image: busybox
securityContext:
allowPrivilegeEscalation: false
capabilities:
add: ["CAP_NET_ADMIN", "CAP_SYS_MODULE"] # This is allowed but can lead to privilege escalation
- Dangerous Capabilities Still Allowed:
- CAP_NET_ADMIN: Network stack manipulation, potential for network namespace escape
- CAP_SYS_MODULE: Loading kernel modules
- CAP_SYS_PTRACE: Process debugging and memory access
- CAP_DAC_READ_SEARCH: Bypass file permission checks
- CAP_SYS_RAWIO: Direct I/O access
- CAP_AUDIT_CONTROL: Audit system manipulation
Impact:
- False sense of security when using allowPrivilegeEscalation: false
- Privilege escalation still possible through allowed capabilities
Proposed Fix: Extend the validation to block all dangerous capabilities when allowPrivilegeEscalation is set to false.
I’d love to hear your thoughts! Have you run into situations where allowPrivilegeEscalation: false didn’t cut it?
Thanks
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 18 (14 by maintainers)
I generally agree with this statement, but also this is what the baseline pod security standard is attempting to do, and is enforceable through pod security admission. IMO we should lean more into these mechanisms, rather than trying to define something in API validation. This is a policy decision, not an issue with invalid specification.
I think this is a misunderstanding but the actual behavior is documented?
Perhaps it should’ve been named “
noNewPrivs: true” instead …https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
That means the process at runtime cannot gain more capabilities. You can still explicitly grant it permissions.
Changing this would be a breaking API change.
See: https://www.kernel.org/doc/Documentation/prctl/no_new_privs.txt https://github.com/kubernetes/design-proposals-archive/blob/main/auth/no-new-privs.md
See also though https://github.com/kubernetes/kubernetes/issues/119568
I also like the idea of removing the API validation requirement that prevents using
allowPrivilegeEscalation=Falsetogether withCAP_SYS_ADMIN. In addition to helping reduce confusion about whatallowPrivilegeEscalation=Falsedoes, it could also help enable certain niche workloads.A containerized workload could potentially implement some classic UNIX-style privilege-separation hardening measures: the initial process could start up with high privileges in order to spawn out several coordinating unprivileged child processes and then drop all its own privileges. In such a case,
allowPrivilegeEscalation=Falsewould be a valuable hardening measure to help ensure none of the privileges could be regained.@ritazh do you think SIG Auth would have an appetite to relax the API validation on
allowPrivilegeEscalation?So looking through some old issues and PRs and doing some experiments myself, this issue seems interesting. On any cluster with Containerd as the runtime adding
CAP_SYS_ADMINdoesn’t actually add the capability but addingSYS_ADMINdoes add the capability. If you haveallowPrivilegeEscalation: falseand addSYS_ADMINit’s allowed just fine and adds the capability, the only blocked combination is one that doesn’t do anything! My experiments confirming that are here.On CRI-O backed clusters it will apparently block (I’ve not got one to test) if you have
allowPrivilegeEscalation: falseand addCAP_SYS_ADMIN(not sure what happens if you addSYS_ADMINin that setup).So really this validation at the moment (in the majority of clusters) doesn’t do anything at all apart from cause some confusion 😃
https://github.com/kubernetes/kubernetes/pull/105237 was the oldest mention of this I’ve seen.
@christophetd wrote an excellent blog post about this last year: https://blog.christophetd.fr/stop-worrying-about-allowprivilegeescalation/
In general, I think, that this misunderstanding is really common, and Kubernetes could benefit from something to help with it.
Discussing this in the SIG Security meeting presently. 🎉