Certified Kubernetes Security Specialist (CKS) Exam-style mock test
CKS Certified Kubernetes Security Specialist Practice Exams|Practice test
Full explanations
Exam format
Pass line 67%
33 USD One-time · lifetime access
Enroll →
Sample questions
Example1 · Cluster Setup
A retail e-commerce platform runs a 'payments' namespace whose pods must never receive traffic from any other namespace, yet the namespace currently has no NetworkPolicy objects and all pods freely accept connections. Which single NetworkPolicy best establishes the required baseline before adding specific allow rules?
・A policy with podSelector {} and policyTypes Egress but no egress rules, so the pods lose their outbound reach entirely
Incorrect. Restricting Egress controls outbound traffic, but the requirement is to stop inbound traffic from other namespaces.
・A policy listing every other namespace under namespaceSelector so each is matched and blocked
Incorrect. A listed namespaceSelector under ingress defines allowed sources, so naming namespaces there would permit them rather than deny them.
✓A policy with podSelector {} and policyTypes Ingress declared but no ingress rules defined at all
Correct. An empty podSelector selects all pods in the namespace, and declaring Ingress with zero rules denies all inbound connections as a default-deny baseline.
・A policy using ipBlock with cidr 0.0.0.0/0 under an ingress from clause to capture every possible source address
Incorrect. Placing 0.0.0.0/0 in an ingress from clause explicitly allows every source IP, which is the opposite of a default-deny posture.
Explanation
A default-deny ingress policy is the correct starting baseline: selecting all pods and declaring the Ingress policy type with no rules drops all inbound traffic. Specific allow policies are then layered on top as additive exceptions.
Example2 · Cluster Hardening
A retail e-commerce platform runs a kube-apiserver whose flags include --anonymous-auth=true. A reviewer notes unauthenticated clients can reach the API and receive responses as the 'system:anonymous' user. Which change best closes this gap without breaking the health-check probes used by the load balancer?
✓Set --anonymous-auth=false while still permitting the probe paths /healthz, /livez, and /readyz to stay reachable
Correct. Disabling anonymous auth rejects unauthenticated requests, while the health endpoints stay reachable because they are served and can be allowed without anonymous access.
・Keep anonymous auth on but bind system:anonymous to a Role granting get on pods in kube-system
Incorrect. Narrowing the binding still leaves anonymous requests authenticated as a real principal, which is the exposure the reviewer flagged.
・Delete the system:anonymous user object so no credentials can map to that built-in identity again
Incorrect. system:anonymous is a built-in virtual identity, not a deletable object, so this action does nothing.
・Enable the AlwaysPullImages admission controller to block anonymous image pulls here
Incorrect. AlwaysPullImages governs image pull authorization on pods and has no effect on anonymous API authentication.
Explanation
Anonymous authentication is controlled by the --anonymous-auth kube-apiserver flag; setting it to false is the direct hardening step. Health endpoints can still be permitted separately, so probes keep working.
Example3 · System Hardening
A retail e-commerce platform wants every workload in the checkout namespace to run under the kubelet's default seccomp profile unless a Pod explicitly declares otherwise. Which securityContext snippet applied at the Pod level achieves this with the least custom maintenance?
・seccompProfile with type: Localhost and a localhostProfile path that points at a vendor file bundled on each node
Incorrect. Localhost requires you to author and distribute a custom profile file to every node, which is the opposite of least maintenance.
・A privileged: true container flag so the kernel trusts the workload and skips the syscall filter
Incorrect. Running privileged disables confinement and increases attack surface rather than applying the default profile.
✓seccompProfile with type: RuntimeDefault, which tells the container runtime to apply its built-in default filter
Correct. RuntimeDefault applies the container runtime's built-in default seccomp filter without any node-side files to maintain.
・An annotation container.seccomp.security.alpha.kubernetes.io/pod set to docker/default placed on the Pod metadata object
Incorrect. The alpha seccomp annotation is removed in current Kubernetes and the securityContext field is the supported mechanism.
Explanation
RuntimeDefault lets the runtime enforce its maintained default syscall filter with zero per-node files. Localhost profiles must be distributed to every node, and privileged mode removes confinement entirely.
Example4 · Minimize Microservice Vulnerabilities
A genomics pipeline runs a container that must bind a raw network device for low-level packet capture, which the kernel permits only when the process holds CAP_NET_RAW. The platform team wants this one container to gain exactly that capability while still dropping every other Linux capability it inherits by default. Which securityContext.capabilities block satisfies this?
・add: ["ALL"] combined with drop: ["NET_BIND_SERVICE"] on the container
Incorrect. Adding ALL grants the full capability set and dropping one entry still leaves a massively over-privileged container.
・drop: ["NET_RAW"] combined with privileged: true on the container
Incorrect. Dropping NET_RAW removes the very capability needed, and privileged mode grants far more than this single capability.
✓drop: ["ALL"] combined with add: ["NET_RAW"]
Correct. Dropping ALL removes every default capability, then adding NET_RAW grants back only the single capability the packet-capture process requires.
・add: ["NET_RAW"] on its own without any drop entry present
Incorrect. Without drop ALL the container keeps its full default capability set alongside NET_RAW, violating least privilege.
Explanation
Least-privilege capability handling means dropping ALL first and then adding back only the specific capabilities a workload proves it needs. Adding ALL or enabling privileged mode defeats the hardening goal entirely.
Example5 · Supply Chain Security
A genomics platform ships a Go analytics service in a container derived from ubuntu:22.04 that bundles bash, apt, and a full package manager. Auditors flag the large attack surface. Which rebuild of the image most directly minimizes the base image footprint while keeping the compiled binary runnable?
・Keep the ubuntu base but add a USER directive so the process drops root
Incorrect. Switching to a non-root USER reduces privilege but leaves every shell, apt, and library in the image, so the footprint and attack surface are unchanged.
✓Use a multi-stage build that copies only the static binary into a distroless or scratch final stage
Correct. A multi-stage build discards the builder toolchain and ships only the static binary on distroless or scratch, removing the shell and package manager.
・Keep the ubuntu base but run apt-get remove on bash and the package manager as the final RUN layer
Incorrect. Deleting packages in a later layer does not remove them from earlier layers, so the files remain recoverable in the image history.
・Keep the ubuntu base and attach a seccomp profile that blocks the execve syscall commonly used by interactive shells
Incorrect. A seccomp profile constrains runtime syscalls but the shell binaries and package manager still ship in the image, so the footprint is unchanged.
Explanation
Minimizing the base image means not shipping unnecessary binaries at all. A multi-stage build to distroless or scratch leaves only the application, whereas USER, late deletions, or seccomp do not remove the bundled tooling.
Example6 · Monitoring, Logging and Runtime Security
A hospital's EHR platform runs Falco as a DaemonSet. Security wants an alert whenever a process inside any container opens an interactive shell, since the clinical pods should never spawn one. Which Falco rule condition most directly expresses this detection?
・evt.type in (connect, sendto) and fd.sname contains the string shell
Incorrect. Matching connect/sendto socket events with an fd socket name watches network activity, not the spawning of a shell process in a container.
✓proc.name in (sh, bash, zsh) and container.id != host
Correct. Detecting a shell binary (sh, bash, zsh) launched inside a container (container.id not equal to host) is exactly the spawned-shell behavior Falco flags with the proc.name and container fields.
・ka.verb = create and ka.target.resource = pods and ka.uri contains exec
Incorrect. A ka.verb condition inspects Kubernetes audit events for pod exec API calls, so it misses a shell started by an already-running in-container process.
・evt.type = execve and user.uid = 0 and fd.directory = /etc
Incorrect. Filtering execve by uid 0 and the /etc directory keys on root file access patterns and would miss non-root shells and shells launched elsewhere.
Explanation
Falco's syscall source exposes proc.name and container fields, so a rule keying on known shell binaries running inside a container is the canonical shell-spawn detector. Audit-log conditions (ka.*) only see API-server exec calls, not shells started by existing container processes.
Example7 · Cluster Setup
A fleet-telemetry namespace runs pods for a logistics tracking API. By default every pod in the namespace can reach every other pod on any port. The security team wants a baseline that drops all ingress and egress, so that only explicitly allowed flows remain, which later policies will add back. Which NetworkPolicy spec establishes this default-deny baseline for the namespace?
・A policy with podSelector matching app=tracking-api plus an ingress rule allowing traffic from namespaceSelector {}
Incorrect. Scoping to app=tracking-api leaves other pods unaffected and the namespaceSelector {} rule actually opens ingress from all namespaces rather than denying it.
・A policy with an empty podSelector {} and an egress rule permitting UDP port 53 to the kube-dns service only
Incorrect. This allows DNS egress for all pods but does nothing to deny ingress, so inbound traffic remains fully open and the baseline is incomplete.
・A policy with podSelector {} and policyTypes Ingress only, which leaves all egress traffic unselected and unrestricted
Incorrect. Listing Ingress only denies inbound while egress is never selected, so outbound connections stay permitted and dropping both directions is not met.
✓A policy using an empty podSelector {} that selects every pod and declares policyTypes listing both Ingress and Egress with all rule blocks left empty
Correct. Selecting all pods with an empty podSelector {} and declaring both Ingress and Egress in policyTypes, while leaving every rule block empty so nothing is explicitly allowed, isolates every pod for both directions as the canonical default-deny baseline.
Explanation
A default-deny baseline requires an empty podSelector to catch all pods plus both Ingress and Egress in policyTypes with no allow rules. Omitting a direction from policyTypes leaves that direction unrestricted, and narrowing the podSelector misses other pods.
Example8 · Cluster Setup
On a manufacturing-plant cluster, workloads run on cloud VMs. A compromised pod in the sensors namespace was observed harvesting IAM credentials by querying the cloud instance metadata service at 169.254.169.254. Without changing the node OS or the cloud provider configuration, which Kubernetes-native control blocks pods in that namespace from reaching the metadata endpoint?
✓A NetworkPolicy with an egress rule using ipBlock cidr 0.0.0.0/0 and an except for 169.254.169.254/32
Correct. An egress NetworkPolicy allowing 0.0.0.0/0 except 169.254.169.254/32 permits normal outbound traffic while dropping packets to the link-local metadata IP for the selected pods.
・A PodSecurity admission label set to the restricted level on the sensors namespace so privileged escalation is denied
Incorrect. The restricted Pod Security Standard constrains securityContext fields such as privilege escalation but imposes no network path restrictions, so metadata access is unaffected.
・An audit policy at the Metadata level logging every request that any pod makes to 169.254.169.254
Incorrect. An audit policy only records API server activity; it neither observes pod-to-metadata traffic nor blocks the connection.
・A ResourceQuota capping the number of pods allowed to run in the sensors namespace at any given time
Incorrect. A ResourceQuota limits object counts and resource consumption and has no effect on which network endpoints a pod may contact.
Explanation
Protecting node metadata from pods is a network-layer concern solved with an egress NetworkPolicy that excepts the 169.254.169.254/32 link-local address. Pod Security, audit policy, and quotas address different attack surfaces and do not block the metadata path.
Example9 · Cluster Setup
An operations engineer runs kube-bench against the control plane of a warehouse-robotics cluster and sees several FAIL results for the API server. Which remediations correctly address genuine CIS Benchmark API server findings? (Choose TWO.)
✓Set --anonymous-auth=false on the kube-apiserver so unauthenticated requests are rejected
Correct. CIS checks that anonymous authentication is disabled; setting --anonymous-auth=false prevents unauthenticated API access.
✓Ensure --authorization-mode does not include AlwaysAllow and uses Node,RBAC instead
Correct. CIS requires that AlwaysAllow is not used; Node,RBAC enforces proper authorization decisions on API requests.
・Add --insecure-port=8080 to the kube-apiserver flags so legacy clients can still connect
Incorrect. Opening the insecure port exposes an unauthenticated, unencrypted endpoint, which is exactly what the benchmark flags as a failure.
・Enable --basic-auth-file to let operators authenticate with a username and password quickly
Incorrect. Basic auth files are deprecated and insecure; CIS explicitly expects basic auth to be unused, so enabling it introduces a finding.
・Configure --token-auth-file as the primary authentication method for all cluster service accounts
Incorrect. Static token files are a weak, non-rotatable credential mechanism that the benchmark discourages, and service accounts already use bound tokens.
Explanation
kube-bench maps directly to CIS controls that disable anonymous auth and forbid AlwaysAllow authorization. Insecure ports, basic-auth files, and static token files are legacy mechanisms the benchmark treats as failures rather than remediations.
Example10 · Cluster Setup
A B2B SaaS tenant namespace 'billing' has no NetworkPolicy. The platform team applies a policy selecting all pods in 'billing' with 'policyTypes: [Ingress]' and an empty 'ingress: []'. A debugging engineer reports that pods in 'billing' can still reach an external payment API over the internet. Why does outbound traffic still work?
・NetworkPolicy objects are fundamentally unable to filter any traffic leaving the cluster toward public internet addresses
Incorrect. Egress NetworkPolicy can and does restrict traffic to external CIDRs when an Egress rule is present.
✓The empty ingress rule governs inbound only, and egress stays unrestricted
Correct. With only Ingress in policyTypes and an empty ingress block, the pods are default-deny for inbound but egress stays fully open because no Egress type was declared.
・An empty ingress array is read by the CNI as allow-all, granting traffic in both directions
Incorrect. An empty ingress array means deny-all inbound, not allow-all, and it never affects egress.
・The policy requires a matching default-deny egress policy in kube-system before any namespace egress rule becomes active
Incorrect. No kube-system prerequisite policy is required; egress control is per-namespace and self-contained.
Explanation
A NetworkPolicy only restricts a direction that is named in policyTypes. Listing only Ingress with an empty rule produces default-deny inbound while leaving egress untouched, so pods keep their outbound internet access.
Example11 · Cluster Setup
An online gaming studio hosts an Ingress for 'play.studio.gg' and wants browsers to see a trusted certificate. The platform engineer created a Secret of type 'kubernetes.io/tls' holding tls.crt and tls.key. Which Ingress field must reference this Secret so the ingress controller terminates HTTPS for that host?
・The 'spec.backend.resource' field, which points the controller to the certificate object bound to that service
Incorrect. spec.backend.resource references a default backend object, not a TLS certificate source.
・An annotation 'nginx.ingress.kubernetes.io/ssl-certificate' set to the namespace-qualified name of the TLS Secret
Incorrect. TLS termination is driven by spec.tls, not by an ssl-certificate annotation, and that annotation name is not standard.
✓The 'spec.tls' list, pairing the host 'play.studio.gg' with the Secret name under 'secretName'
Correct. The spec.tls block maps one or more hosts to a secretName containing the TLS keypair, telling the controller which certificate to present for that host.
・The 'spec.rules.http.paths.backend.service.port' entry configured to 443 so the controller loads the certificate
Incorrect. Setting a backend port to 443 selects an upstream target and does not make the controller load the Secret's certificate.
Explanation
Ingress TLS termination is configured through spec.tls, which pairs hostnames with a kubernetes.io/tls Secret via secretName. Backend fields and ports route traffic but never supply the serving certificate.
Example12 · Cluster Setup
A state university research cluster hosts a 'grades' namespace. Auditors require that no Pod in any other namespace may open connections to the grades Pods, yet the grades Pods must still reach the DNS service and an external billing API. A default-deny-ingress NetworkPolicy already exists in the grades namespace. Which added policy satisfies the requirement without over-permitting?
・An ingress policy selecting all grades Pods and allowing every namespace carrying the shared label
Incorrect. Allowing every namespace with a shared label opens ingress broadly, violating the no-other-namespace requirement.
✓An egress policy in grades allowing only DNS and the billing CIDR, leaving default-deny ingress to block inbound
Correct. The default-deny ingress blocks all inbound, and an egress policy explicitly allowing kube-dns and the billing CIDR restores only the needed outbound paths.
・A cluster-wide policy that denies egress everywhere and then separately whitelists the DNS endpoints used by research workloads
Incorrect. A cluster-wide deny-egress is not a native NetworkPolicy scope and would also break the billing API reachability.
・An ingress allow rule that permits any namespace whose tier label happens to match and is later supposed to be tightened down
Incorrect. A tier-based ingress allow still admits inbound connections, breaking the rule that no other namespace may connect.
Explanation
NetworkPolicy is namespaced; combining a default-deny ingress with a narrowly scoped egress allow (DNS + billing CIDR) isolates inbound while preserving required outbound. Any ingress allow rule re-admits cross-namespace connections.
Example13 · Cluster Setup
On a public-sector cluster, pods in a low-trust 'kiosk' namespace keep querying the cloud instance metadata endpoint 169.254.169.254 to steal the node's IAM credentials. You want a namespaced control that stops this without touching the CNI gateway config. Which NetworkPolicy approach blocks it?
・An ingress policy on kiosk Pods dropping inbound packets from the link-local metadata range
Incorrect. Metadata access is outbound, so an ingress policy on the pods has no effect on their egress to the endpoint.
・A policy that sets the metadata IP as an except entry under an ingress ipBlock while allowing all other inbound traffic
Incorrect. Placing the metadata IP in an ingress except block addresses inbound and leaves the egress to metadata fully open.
・A cluster egress firewall rule that quietly rewrites the destination of each metadata request toward a dummy sink service
Incorrect. NetworkPolicy cannot rewrite or redirect destinations; it only allows or denies, so this is not a valid control.
✓A default-deny-egress policy in kiosk with an allowlist for DNS and service CIDRs that omits the metadata IP
Correct. Default-deny egress with an allowlist that omits 169.254.169.254 prevents the pods from reaching the metadata endpoint while keeping needed traffic.
Explanation
Protecting node metadata from untrusted pods is an egress concern: a default-deny-egress policy with an allowlist that excludes the link-local metadata CIDR cuts off credential theft. Ingress policies and destination rewriting do not apply.
Example14 · Cluster Setup
A travel-booking platform runs pods in namespace 'reservations'. Its security team requires that these pods accept inbound connections only from pods carrying the label app=gateway, while all other ingress is dropped. A NetworkPolicy is applied that selects the reservations pods and lists a single 'from' entry with a podSelector matching app=gateway. Before this works as intended, which prerequisite must the cluster actually satisfy?
・The policyTypes field must be omitted so that Kubernetes automatically infers both ingress and egress enforcement for the selected pods
Incorrect. Omitting policyTypes does not enable both directions; with only an ingress rule present, the policy defaults to Ingress and egress stays unrestricted.
✓An installed CNI plugin that enforces NetworkPolicy, since the API object alone does nothing without an enforcing backend
Correct. NetworkPolicy objects are only enforced by a CNI plugin that supports them (Calico, Cilium, etc.); without such a backend the policy is stored but silently ignored.
・A default-allow policy has to be created first in the namespace to establish the baseline that the restrictive rule then narrows down afterward
Incorrect. No default-allow object is needed; selecting a pod with an ingress policy already isolates it so only the listed sources are permitted.
・The gateway pods must first obtain a ClusterRole permitting them to open connections into the reservations namespace
Incorrect. NetworkPolicy enforcement is not an RBAC concern; ClusterRoles govern API access, not pod-to-pod network reachability.
Explanation
NetworkPolicy resources are declarative and inert unless the installed CNI enforces them. Selecting a pod with any ingress rule flips it to default-deny for ingress, so the single app=gateway entry is sufficient once an enforcing plugin is present.
Example15 · Cluster Setup
An insurance claims service in namespace 'claims' must be fully isolated so that its pods can reach only the cluster DNS service on UDP/TCP 53 and nothing else outbound. An engineer writes a NetworkPolicy selecting all pods in the namespace with policyTypes including Egress, and an egress rule allowing port 53 to the kube-dns pods. External claims-status lookups then start failing even though DNS resolves. What is the most likely cause?
・UDP port 53 cannot be combined with TCP port 53 in one egress block, so the configured DNS allowance never activates at all
Incorrect. A single egress block may list both UDP/53 and TCP/53; mixing the two protocols for the same port is fully supported.
・Egress policies require a matching ingress policy on the destination side, which the remote external API endpoint cannot ever provide
Incorrect. Egress enforcement is independent of ingress on the remote side; external endpoints are not Kubernetes pods and need no NetworkPolicy.
・The kube-dns podSelector listed in one rule silently disables every other egress rule defined in the same NetworkPolicy object
Incorrect. A podSelector in one rule does not disable sibling rules; rules in a policy are additive, not mutually exclusive.
✓Only DNS resolution on port 53 was explicitly permitted, so all remaining outbound traffic to the external claims-status API endpoint is dropped by default
Correct. Once Egress is in policyTypes, everything not explicitly allowed is denied; only DNS resolution on port 53 was permitted, so all remaining outbound traffic to the external claims-status API endpoint is dropped by design.
Explanation
Adding Egress to policyTypes makes the selected pods default-deny for all outbound traffic. Only the DNS allowance was written, so legitimate external API calls fail until an explicit egress rule for that destination is added.
▶ Try 10 free questions (graded)