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:

  1. Current Validation:

    • Blocks: CAP_SYS_ADMIN when allowPrivilegeEscalation: false
    • Allows: CAP_NET_ADMIN, CAP_SYS_MODULE, CAP_SYS_PTRACE, etc.
  2. 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
  1. 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)

Most upvoted comments

The challenge with having a VAP or in-built control which tries to stop privilege escalation is that it’s not (AFAIK) generally agreed which capabilities can allow for privilege escalation 😃 For example you could go with something based on the classic post on caps from 2011 from spender on the grsecurity forums, but I’m not sure in reality that would apply to container scenarios in a lot of cases.

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/

allowPrivilegeEscalation: Controls whether a process can gain more privileges than its parent process. This bool directly controls whether the no_new_privs flag gets set on the container process. allowPrivilegeEscalation is always true when the container:

  • is run as privileged, or
  • has CAP_SYS_ADMIN

That means the process at runtime cannot gain more capabilities. You can still explicitly grant it permissions.

Extend the validation to block all dangerous capabilities when allowPrivilegeEscalation is set to false.

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=False together with CAP_SYS_ADMIN. In addition to helping reduce confusion about what allowPrivilegeEscalation=False does, 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=False would 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_ADMIN doesn’t actually add the capability but adding SYS_ADMIN does add the capability. If you have allowPrivilegeEscalation: false and add SYS_ADMIN it’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: false and add CAP_SYS_ADMIN (not sure what happens if you add SYS_ADMIN in 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. 🎉