Courseiva

CCNA Container Security Questions

13 questions · Container Security topic · All types, answers revealed

1
MCQhard

A GSEC analyst is reviewing the deployment pipeline for a containerized Node.js service. The Dockerfile contains a layer that runs `curl -fsSL https://example.com/install.sh | sh` during the build, before the image is pushed to an internal registry. The registry enforces vulnerability scanning, and the image is deployed to a Kubernetes cluster with a restrictive NetworkPolicy. Which of the following is the primary supply chain risk introduced by this Dockerfile instruction?

A.The remote script is fetched without integrity verification, so the image may include tampered or malicious content that scanning cannot reliably detect.
B.The instruction allows the build host's environment variables, including registry credentials, to be exfiltrated by the remote script.
C.The curl command creates a writable layer that persists at runtime and can be modified by an attacker after deployment.
D.The instruction bypasses Kubernetes NetworkPolicy because build-time traffic does not originate from a pod in the cluster.
AnswerA

Piping a remote script directly into a shell executes whatever the endpoint returns at build time, with no hash or signature check. If the endpoint or DNS is compromised, malicious code becomes part of a legitimate image layer, and later vulnerability scanning may not flag novel or obfuscated payloads, making this the primary supply chain risk.

Why this answer

Fetching and executing a remote script during a Docker build introduces unverified third-party code into the image. Because there is no checksum or signature validation, a compromised endpoint can inject malicious content that becomes part of a trusted image. Registry scanning may not catch bespoke or obfuscated payloads, so the integrity of the supply chain is the primary concern.

Exam trap

The trap here is assuming that registry vulnerability scanning will catch any malicious code introduced during the build, when scanning primarily targets known CVEs in packages, not arbitrary injected scripts.

2
MCQmedium

A GSEC candidate is reviewing a Docker Compose file for a web application. The file includes a service definition that mounts the Docker socket into the container. What is the primary security risk of this configuration?

A.It prevents the container from writing to its own filesystem, causing application failures.
B.It allows the container to access the host's Docker daemon, enabling privilege escalation and full host compromise.
C.It exposes the container's internal ports to the host network, increasing the attack surface.
D.It allows the container to bypass network policies and communicate with other containers without restriction.
AnswerB

Mounting the Docker socket (/var/run/docker.sock) into a container grants that container control over the Docker daemon, which typically runs as root. An attacker could use the Docker API to create privileged containers, mount host filesystems, or escape to the host, leading to full compromise.

Why this answer

Mounting the Docker socket into a container effectively gives that container root-level control over the host's Docker daemon. An attacker who compromises the container can use the Docker API to start privileged containers, mount host directories, or execute commands on the host, resulting in full system compromise. This is a critical misconfiguration that should be avoided.

Exam trap

The trap here is assuming that mounting the Docker socket only affects container networking or filesystem isolation, when in fact it grants control over the host's Docker daemon and can lead to full host compromise.

3
MCQhard

A platform team runs a Kubernetes cluster where a container was compromised through a remote code execution flaw in a web application. The attacker attempted to read the service account token, query the API server, and list secrets in the namespace. The team wants to reduce the impact of such a compromise in the future. Which of the following changes most directly limits what the compromised pod's service account can do against the API server?

A.Enabling audit logging on the API server to record all requests made by service accounts.
B.Disabling the automountServiceAccountToken field on the pod spec so no token is projected into the container.
C.Applying a NetworkPolicy that blocks egress from the pod to the API server's ClusterIP.
D.Binding a tightly scoped Role to the service account that grants only the specific verbs and resources the application requires, instead of cluster-admin or broad default permissions.
AnswerD

RBAC bindings define exactly which API verbs and resources a service account may access. Replacing broad permissions with a least-privilege Role ensures that even if the container is compromised, the token cannot list secrets or perform privileged operations. This directly limits the blast radius against the API server, matching the team's objective.

Why this answer

RBAC least privilege is the authoritative control over what a service account can do against the API server. Binding a narrowly scoped Role that grants only the required verbs and resources means a compromised pod's token cannot enumerate secrets or perform privileged actions, directly containing the blast radius from the RCE compromise.

Exam trap

The trap here is treating observability or network controls as equivalent to authorization, when only RBAC scope determines what a service account is permitted to do.

4
MCQeasy

A security analyst is examining a Kubernetes Pod specification that includes the following securityContext: runAsUser: 0. What is the security implication of this setting?

A.The container will be unable to write to any mounted volumes due to permission restrictions.
B.The container will run as the root user, increasing the risk of privilege escalation if compromised.
C.The container will run as a non-privileged user, enhancing security by default.
D.The container will automatically drop all Linux capabilities, reducing its attack surface.
AnswerB

Setting runAsUser: 0 explicitly runs the container process as the root user (UID 0). If an attacker compromises the container, they gain root privileges within the container, which can be leveraged to escape to the host or access sensitive resources, especially if combined with other misconfigurations like hostPath mounts.

Why this answer

Specifying runAsUser: 0 in a Kubernetes securityContext forces the container to run as the root user. This violates the principle of least privilege and increases the potential impact of a container compromise. Best practice is to run containers as a non-root user, often defined in the image or via runAsUser with a high UID.

Exam trap

The trap here is misinterpreting runAsUser: 0 as a security hardening measure, when it actually runs the container as root and weakens security.

5
MCQmedium

A security engineer wants to ensure that container images are not modified after they are built and pushed to a registry. Which mechanism provides the strongest assurance of image integrity and authenticity?

A.Implementing a read-only filesystem for the container at runtime.
B.Using SHA-256 image digests instead of mutable image tags.
C.Applying cryptographic digital signatures to container images.
D.Scanning images for known vulnerabilities using a static analyzer.
AnswerC

Digital signatures provide a verifiable link between the image and the build process. By using a private key to sign the image manifest, the organization ensures that any subsequent modifications to the image data will cause the signature validation check to fail upon deployment.

Why this answer

Content trust and image signing using tools like Notary or Cosign ensure that the image pulled by a runtime is exactly the same one pushed by the CI/CD pipeline. By cryptographically signing the manifest, organizations prevent man-in-the-middle attacks and unauthorized registry modifications. This is vital in modern DevSecOps, as compromised images could introduce persistent backdoors or vulnerabilities into the production environment without triggering standard application-level alerts.

Exam trap

Candidates often confuse vulnerability scanning tools with integrity mechanisms, incorrectly assuming that finding bugs prevents unauthorized modification or guarantees the authenticity of the container image pushed to the registry.

6
MCQmedium

A security engineer is evaluating a container runtime for a production Kubernetes cluster. The requirement is that the runtime must not share the host kernel with containers, providing stronger isolation than standard runc-based containers. Which of the following runtimes best satisfies this requirement?

A.runc with user namespaces enabled
B.CRI-O with the default runtime configured for SELinux enforcement
C.containerd configured with the default runc shim
D.Kata Containers, which runs each pod inside a lightweight virtual machine
AnswerD

Kata Containers launches each pod in a lightweight VM with its own guest kernel, so container workloads do not share the host kernel. This provides hardware-virtualization-based isolation that satisfies the requirement. A kernel exploit in the guest does not automatically compromise the host, making Kata the correct choice for stronger isolation.

Why this answer

Kata Containers runs each pod in a lightweight virtual machine with its own guest kernel, so workloads do not share the host kernel. This hardware-virtualization-based isolation provides a stronger boundary than runc, containerd with runc, or CRI-O with SELinux, all of which share the host kernel and are therefore vulnerable to kernel-level escapes.

Exam trap

The trap here is equating hardening features like user namespaces or SELinux with kernel isolation, when only VM-based runtimes such as Kata provide a separate kernel per pod.

7
MCQmedium

Refer to the exhibit. What is the security impact of the provided Kubernetes security context configuration?

A.The pod will be unable to pull the image from the registry.
B.The container is protected against setuid-based privilege escalation.
C.The pod will block all network traffic from the container.
D.The application will automatically have its vulnerabilities patched.
AnswerB

By setting 'allowPrivilegeEscalation' to false, the container runtime prevents the process from gaining more privileges than its parent. This effectively neutralizes setuid binaries that could otherwise be leveraged by an attacker to elevate their privileges from a standard user to root within the container's isolated execution environment.

Why this answer

This configuration enforces the principle of least privilege by ensuring the container cannot run as root and preventing any process from gaining more privileges than its parent. 'allowPrivilegeEscalation: false' is a critical setting that prevents setuid binaries from changing the process effective user ID, which is a common technique used by attackers to escalate privileges within a container after achieving initial execution.

Exam trap

Candidates often misread 'allowPrivilegeEscalation: false' as completely disabling the container execution or restricting root file system writes, rather than focusing specifically on blocking setuid escalation vectors.

8
MCQmedium

When designing a secure container orchestration strategy, which approach best minimizes the impact of a compromised container on the host kernel?

A.Disable all kernel modules on the host operating system.
B.Use a specialized container runtime like gVisor to intercept system calls.
C.Increase the memory limit for every container in the cluster.
D.Run all containers with the --privileged flag to ensure compatibility.
AnswerB

gVisor acts as a user-space kernel that intercepts and handles system calls. By limiting the number of system calls that reach the host kernel, it drastically reduces the available attack surface for privilege escalation and kernel exploits, effectively containing the potential damage from a compromised application within the guest.

Why this answer

Kernel vulnerabilities are a primary vector for container escapes. By using technologies like gVisor or Kata Containers, the container environment uses a hardened kernel or a separate micro-VM, providing an additional layer of isolation. Standard containers share the host kernel directly; if the kernel is exploited via a system call, the attacker can break out of the container boundary entirely, leading to full system compromise of the underlying host node.

Exam trap

Candidates often select standard namespace isolation or network policies, which do not protect the host kernel from system call exploitation, the primary method for container breakouts.

9
MCQmedium

A security engineer is hardening a Kubernetes cluster that runs multi-tenant workloads. Several pods have been observed running as the root user inside their containers, which the engineer wants to prevent. The engineer applies a Pod Security Admission (PSA) label to the namespace that enforces the 'restricted' profile. Which of the following best describes the enforcement action taken by the 'restricted' profile when a pod violates its policy?

A.The pod is rejected and the API server returns an error, preventing it from being scheduled.
B.The pod is admitted but an audit annotation is added to the pod's metadata for later review.
C.The pod is scheduled but the kubelet forcibly changes the container's user to a non-root UID at runtime.
D.The pod is admitted and a warning is written to the API server logs, but no enforcement action is taken.
AnswerA

The restricted profile is the most stringent of the Pod Security Standards and directly rejects pods that violate its controls, such as running as root or lacking a seccomp profile. Rejection occurs at admission time, so the non-compliant pod never reaches a node, which directly addresses the engineer's goal of preventing root-running pods.

Why this answer

The restricted Pod Security Standard is the most restrictive of the three built-in profiles and enforces controls such as requiring non-root execution, dropping all capabilities, and mandating a seccomp profile. When a namespace enforces this profile, non-compliant pods are denied at admission, directly preventing root-running containers from being scheduled.

Exam trap

The trap here is confusing the audit and warn modes with enforce mode, assuming that a violation only produces a log entry rather than a rejection.

10
MCQhard

A GSEC consultant is hardening a Kubernetes cluster that runs multi-tenant workloads. A developer reports that a pod in the tenants namespace was able to read the contents of the kubelet's host filesystem at /var/lib/kubelet. The pod spec includes hostPath: {path: /var/lib/kubelet, type: Directory} under volumes and mounts it at /host. The cluster has Pod Security Admission enabled with the restricted profile enforced cluster-wide, but the tenants namespace was labeled pod-security.kubernetes.io/enforce: privileged to unblock a legacy job. Which action most directly closes this exposure?

A.Enable the NodeRestriction admission plugin and rotate the kubelet client certificates on all worker nodes.
B.Add a seccomp profile of RuntimeDefault to the pod and set allowPrivilegeEscalation to false in its securityContext.
C.Create an OPA Gatekeeper constraint that denies pods whose namespaces carry the privileged enforcement label.
D.Remove the privileged label from the tenants namespace so the restricted profile is enforced there, and refactor the legacy job to run without a hostPath mount.
AnswerD

The hostPath volume is what exposes the node's kubelet directory to the pod, and the namespace's privileged enforcement label is what allowed that volume to be admitted despite the cluster-wide restricted profile. Restoring restricted enforcement blocks hostPath volumes entirely and forces the legacy job to be reworked, directly removing the pod's ability to read node files. The other options leave the mount or the permissive label in place.

Why this answer

Pod Security Admission decides admission based on the namespace's pod-security.kubernetes.io/enforce label, and the privileged value on the tenants namespace overrode the cluster-wide restricted profile. That exemption is precisely what let a pod mount the node's /var/lib/kubelet directory via hostPath. Removing the label restores restricted enforcement, which forbids hostPath volumes, and refactoring the legacy job removes the need for the exemption so the exposure cannot be recreated.

Exam trap

The trap here is focusing on pod-level runtime hardening such as seccomp or privilege-escalation flags, when the actual enabler was a namespace-level admission exemption that permitted the hostPath mount in the first place.

11
MCQeasy

Which of the following is the most effective way to prevent secrets (such as API keys) from being leaked via container images?

A.Encrypt the Dockerfile using a secret key before building.
B.Use orchestrator-native secret management to inject secrets at runtime.
C.Delete the secrets in a subsequent RUN layer during the build.
D.Set the file permissions on the secret to 600 after copying it.
AnswerB

Runtime injection ensures that secrets reside only in the memory of the container and are not persisted in the image layers. This prevents secrets from being exposed through registry access or image analysis, allowing for easier rotation and centralized auditing of secret usage within the containerized application environment.

Why this answer

Secrets should never be baked into container images because they remain in the image layers even if deleted in later steps. Once an image is pushed to a registry, those secrets are accessible to anyone with pull access. Using orchestrator-native secret management (like Kubernetes Secrets or Vault) ensures that sensitive data is injected at runtime, keeping it out of the persistent image layers and the source control history.

Exam trap

Candidates frequently select multi-stage builds or container image scanning, forgetting that while these reduce image size or find bugs, they do not prevent secrets from persisting in image layers.

12
MCQmedium

An enterprise development team is designing a Kubernetes cluster deployment where application containers frequently interact with cloud provider APIs. To minimize security blast radius, which architectural practice provides the most effective credential isolation per pod?

A.Store cloud provider credentials in base64-encoded Kubernetes Secret objects and mount them as environment variables.
B.Configure cluster-wide IAM roles on the underlying worker nodes and allow all hosted pods to inherit administrative permissions.
C.Implement service account token volume projection with short-lived auditable tokens scoped to individual application requirements.
D.Embed the static cloud API keys directly into the container base image layers to ensure consistency across deployments.
AnswerC

Projected service account tokens provide automatically rotated, cryptographically signed tokens with strict audience limitations. This ensures that even if a token is exfiltrated, its lifespan is extremely short and its usability is strictly bounded to intended APIs.

Why this answer

Service account token volume projection utilizes short-lived tokens cryptographically signed by the cluster, mounting them securely into specific pods with restricted audiences. This approach replaces static long-lived credentials stored in environment variables or generic secrets, significantly reducing lateral movement risks if an application is compromised.

Exam trap

Candidates often suggest static secrets or Kubernetes Secrets objects, failing to realize that these are long-lived and pose a higher risk compared to short-lived, projected tokens.

13
MCQeasy

A developer is building a container image for a Python web application. During review, a security engineer notices the Dockerfile copies a .env file containing database credentials into the image and deletes it in a later RUN instruction. The engineer explains that this pattern still leaks the credentials. Which of the following best explains why the credentials remain exposed in the final image?

A.The .env file is recreated automatically by the base image's entrypoint at container start.
B.Each Dockerfile instruction creates a layer, and the layer containing the .env file persists in the image history even after a later deletion.
C.Docker automatically backs up deleted files into a hidden volume that is mounted into every container.
D.The .env file is cached in the Docker daemon's build cache and pushed to the registry alongside the image manifest.
AnswerB

Docker builds images as a stack of immutable layers. Deleting a file in a subsequent layer only adds a whiteout marker; the original layer still contains the file's bytes and can be extracted by anyone with the image. This is why secrets copied into any layer remain recoverable, directly explaining the leak the engineer observed.

Why this answer

Container images are composed of immutable layers, one per Dockerfile instruction. Removing a file in a later RUN step only records a deletion in that new layer; the bytes remain in the earlier layer and can be recovered by extracting the image. Secrets must therefore be injected at runtime via secrets management, never copied into any layer.

Exam trap

The trap here is believing that deleting a file in a later Dockerfile instruction removes it from the image, when layer immutability preserves the original bytes.

Ready to test yourself?

Try a timed practice session using only Container Security questions.