Security
medium

Pregunta de Security #019e3a4f

Enunciado de la Pregunta
Security
#kubernetes
#security
#privilege-escalation
#container-security
Medio

Which of the following is a recommended security habit in Kubernetes?

A

Run the containers as the user with group ID 0 (root) and any user ID.

B

Disallow privilege escalation from within a container as the default option.

Correcto
C

Run the containers as the user with user ID 0 (root) and any group ID.

D

Allow privilege escalation from within a container as the default option.

Explicación Oficial / Explicaciones de la Comunidad

Summary

Disallowing privilege escalation from within a container is a recommended security habit in Kubernetes. This setting prevents processes inside the container from gaining more privileges than their parent process, which is a key defense against container breakout attacks.

How It Works

In Kubernetes, the SecurityContext field in a Pod or container specification allows administrators to control security-related settings. The AllowPrivilegeEscalation flag, when set to false, ensures that no process in the container can gain additional privileges (e.g., via setuid binaries or capabilities) beyond those initially granted. This is enforced by the Linux kernel through the no_new_privs flag, which blocks operations like setuid or setgid that would elevate privileges.

Why the Correct Answer is Right

Setting allowPrivilegeEscalation: false is a security best practice because it limits the impact of a compromised container. Even if an attacker gains access to the container, they cannot escalate to root or obtain additional capabilities. This is recommended by the Kubernetes documentation and security benchmarks like the CIS Kubernetes Benchmark.

Why the Incorrect Answers are Wrong

  • Running containers as root (user ID 0): This is insecure because root inside a container has broad capabilities and can potentially escape to the host if not properly restricted. Kubernetes security best practices recommend running containers with a non-root user.
  • Allowing privilege escalation as default: This is dangerous because it permits processes to gain more privileges, increasing the risk of container breakout. The default in Kubernetes is actually to allow privilege escalation, but it should be explicitly disabled for security.
  • Running containers with group ID 0 (root): Similar to running as root user, using the root group can grant unnecessary privileges. The principle of least privilege dictates using a non-root group.

Key Takeaway

Always disable privilege escalation (allowPrivilegeEscalation: false) in your Pod security contexts, and avoid running containers as root or with root group membership. Use a non-root user and group, and drop all unnecessary capabilities for a more secure Kubernetes deployment.