CKS Supply Chain Security Practice Question
Which of the following is a BEST practice for securing container images in a Dockerfile?
⚠ Common exam trap
The CKS exam often tests the misconception that running as root is acceptable if you drop capabilities or use a read-only filesystem, but it emphasizes that a non-root user is a fundamental defense-in-depth layer that must be explicitly set in the Dockerfile.
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
✓
Use the USER directive to specify a non-root user
The USER directive in a Dockerfile sets the user for the container process, and using a non-root user (e.g., USER 1000) follows the principle of least privilege. This reduces the attack surface by preventing an attacker who gains code execution from having root access to the host or container, which is a critical security requirement for containerized workloads.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Use the USER directive to specify a non-root user
Why this is correct
The USER directive in a Dockerfile (or pod securityContext runAsNonRoot) enforces a non-root user for the container's process. This follows the principle of least privilege, limiting filesystem access and kernel namespace capabilities, so an attacker who compromises the application does not inherit root privileges on the host. Combined with a properly configured group and file ownership, it significantly reduces the blast radius of a container breakout.
- ✗
Store secrets in environment variables in the image
Why it's wrong here
Storing secrets in environment variables inside the image is insecure because the values become visible in image layers, accessible via 'docker history' or 'docker inspect', and are copied when the image is pulled. These secrets persist in registries and are inherited by any container from that image, making them impossible to rotate cleanly. Instead, use Docker secrets or Kubernetes Secrets mounted as files or injected at runtime, and never commit them to a Dockerfile.
- ✗
Run the container as root to simplify permission management
Why it's wrong here
Running a container as root nullifies the security benefits of namespace isolation because a root process inside the container maps to root on the host for many operations, especially if kernel capabilities are granted. Any vulnerability in the application or kernel can lead to privilege escalation and host takeover. Even though Docker restricts root capabilities by default, giving it unnecessary privileges violates least privilege and complicates audit controls like SELinux and AppArmor policies.
- ✗
Use the 'latest' tag to always get the newest base image
Why it's wrong here
Using the 'latest' tag makes container images non-reproducible and unpredictable, as it changes over time with base image updates that may introduce breaking changes or security regressions. A digital digest (SHA-256) uniquely identifies the exact content, allowing verified and repeatable deployments that align with supply chain security best practices. Tagging 'latest' also gives attackers a moving target for vulnerability scanning and makes rollback difficult.
Go deeper
Related to this question
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 →
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.