Question 650 of 997
Minimize Microservice VulnerabilitiesmediumMultiple ChoiceObjective-mapped

How runAsNonRoot and runAsUser Work Together in Pod SecurityContext

This CKS practice question tests your understanding of minimize microservice vulnerabilities. The scenario asks you to isolate a root cause — eliminate options that address a different problem before choosing. A key principle to apply: runAsNonRoot. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

A pod manifests with securityContext: { runAsNonRoot: true, runAsUser: 1001 }. However, the container image expects to run as root (UID 0). What will happen when the pod is created?

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

The container runs as user 1001

When `runAsNonRoot: true` is set, Kubernetes enforces that the container cannot run as root (UID 0). However, the pod also specifies `runAsUser: 1001`, which tells Kubernetes to run the container as UID 1001. Since UID 1001 is non-root, the `runAsNonRoot` constraint is satisfied. The container image's expectation to run as root is irrelevant because Kubernetes overrides the user with the specified `runAsUser`. Therefore, the container will start and run as user 1001.

Key principle: runAsNonRoot

Answer analysis

Option-by-option breakdown

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

  • The container runs as root because runAsUser overrides runAsNonRoot

    Why it's wrong here

    Incorrect. The pod specifies both `runAsNonRoot: true` and `runAsUser: 1001`. This does not result in running as root. The `runAsNonRoot` constraint prevents root execution, and `runAsUser` sets the user to 1001.

  • The container fails to start because it cannot run as root

    Why it's wrong here

    Incorrect. The container will not fail to start because it is not attempting to run as root. The `runAsUser: 1001` overrides the image's default user, and since 1001 is non-root, the `runAsNonRoot` constraint is satisfied.

  • The container runs as user 1001

    Why this is correct

    Correct. The `runAsUser: 1001` directive overrides the container's default user, causing the container to run as UID 1001, which is non-root and satisfies the `runAsNonRoot` constraint.

    Related concept

    runAsNonRoot

  • The pod runs, but the securityContext is ignored

    Why it's wrong here

    Incorrect. The `securityContext` is not ignored. Both `runAsNonRoot` and `runAsUser` are applied; the container runs as the specified non-root user.

Common exam traps

Common exam trap: answer the scenario, not the keyword

The trap is that candidates think `runAsNonRoot` alone blocks execution if the image expects root, but they overlook that `runAsUser` can override the image's user to a non-root UID. In this case, the container runs successfully as user 1001, not fails.

Detailed technical explanation

How to think about this question

Under the hood, the kubelet uses the `RunAsNonRoot` field in the PodSecurityContext to validate the container's user ID before starting the container. If the image's `USER` directive is set to root (UID 0) and `runAsNonRoot` is true, the container runtime (e.g., containerd) will reject the container creation. This is enforced by the `SecurityContext` validation in the kubelet's `PodSecurity` admission controller, which checks the effective UID against the `runAsNonRoot` constraint. A real-world scenario is when a container image built with a root default user is used in a cluster with a Pod Security Admission policy that enforces `restricted` level, causing the pod to fail to start.

KKey Concepts to Remember

  • runAsNonRoot
  • runAsUser
  • Container SecurityContext

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

runAsNonRoot

Real-world example

How this comes up in practice

A practitioner preparing for the CKS exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. runAsNonRoot Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.

What to study next

Got this wrong? Here's your next step.

Review runAsNonRoot, then practise related CKS questions on the same topic to reinforce the concept.

Related practice questions

Related CKS practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free CKS practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this CKS question test?

Minimize Microservice Vulnerabilities — This question tests Minimize Microservice Vulnerabilities — runAsNonRoot.

What is the correct answer to this question?

The correct answer is: The container runs as user 1001 — When `runAsNonRoot: true` is set, Kubernetes enforces that the container cannot run as root (UID 0). However, the pod also specifies `runAsUser: 1001`, which tells Kubernetes to run the container as UID 1001. Since UID 1001 is non-root, the `runAsNonRoot` constraint is satisfied. The container image's expectation to run as root is irrelevant because Kubernetes overrides the user with the specified `runAsUser`. Therefore, the container will start and run as user 1001.

What should I do if I get this CKS question wrong?

Review runAsNonRoot, then practise related CKS questions on the same topic to reinforce the concept.

What is the key concept behind this question?

runAsNonRoot

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Keep practising

More CKS practice questions

Last reviewed: Jul 4, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

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.