Courseiva
Supply Chain Security →easyMultiple Choice

CKS Supply Chain Security Practice Question

Which YAML field in a Deployment specifies the container user should not run as root?

⚠ Common exam trap

The CKS exam often tests the distinction between `runAsNonRoot` (which enforces a non-root user) and `runAsUser: 0` (which explicitly sets root), and candidates mistakenly think setting `runAsUser` to a non-zero value is equivalent to `runAsNonRoot`, but `runAsNonRoot` is a boolean enforcement that rejects root regardless of the image's default user.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

spec.containers[].securityContext.runAsNonRoot

`spec.containers[].securityContext.runAsNonRoot: true` explicitly enforces that the container's user ID is non-zero, preventing the container from running as root. This is a key Pod Security Standard (PSS) control for the 'Restricted' profile, ensuring compliance with the principle of least privilege. The field rejects the container if the user is set to root (UID 0) or if no user is specified and the image defaults to root.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    spec.containers[].securityContext.readOnlyRootFilesystem

    Why it's wrong here

    Setting readOnlyRootFilesystem mounts the container's root filesystem as read-only, preventing writes to the container layer, but it has no effect on the user ID under which the process executes. A container running as UID 0 (root) is still root even with a read-only root filesystem, so this field does not enforce non-root execution. The requirement to run as non-root is satisfied by runAsNonRoot, not by filesystem mount permissions.

  • ✗

    spec.containers[].securityContext.runAsUser: 0

    Why it's wrong here

    runAsUser: 0 explicitly sets the container's effective user ID to 0, which is the root user. This is the exact opposite of the requirement to run as non-root — it forces the container into a root context, which can allow privileged operations. The correct field to enforce a non-zero UID is runAsNonRoot, which verifies the UID is not 0 and will reject the pod start if the image or configuration specifies root.

  • ✓

    spec.containers[].securityContext.runAsNonRoot

    Why this is correct

    runAsNonRoot is a Boolean field in the container's securityContext that enforces non-root execution. When set to true, the kubelet checks that the container's user ID is non-zero, and if the image or a runAsUser setting would cause the process to run as UID 0, the pod is denied with an error. This is the standard mechanism to guarantee the container does not run as root, either by validating an existing non-root USER in the image or by pairing with a non-zero runAsUser value.

  • ✗

    spec.containers[].securityContext.allowPrivilegeEscalation

    Why it's wrong here

    allowPrivilegeEscalation controls whether a process can gain more privileges than its parent, such as through setuid binaries or Linux capabilities. It does not determine the initial user ID of the container; a container with allowPrivilegeEscalation: false can still run as root if the image specifies root as the USER or if runAsUser is set to 0. Thus, this field addresses privilege escalation, not the identity of the running user, so it does not fulfill the non-root requirement.

About these practice questions

Courseiva writes every CKS question from scratch — 845 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This CKS practice question is part of Courseiva's free CNCF certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the CKS exam.