Practice Questions: System Hardening
Practice Environment
These questions are designed for a Kind cluster or any local Kubernetes lab environment. Each question simulates a realistic CKS exam scenario focused on System Hardening topics.
Setup a Kind cluster if you don't have one:
kind create cluster --name cks-lab --config - <<EOF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
EOFQuestion 1
Difficulty: Easy
Scenario: Your security team requires that all pods in the web-apps namespace use the container runtime's default seccomp profile.
Task:
- Create a namespace called
web-apps - Create a pod named
web-serverin theweb-appsnamespace using thenginx:1.27image - Ensure the pod uses the
RuntimeDefaultseccomp profile at the pod level - Verify the pod is running
Question 2
Difficulty: Easy
Scenario: A pod named legacy-app is running in the default namespace with excessive capabilities. It currently runs with default container capabilities.
Task:
- Create a pod named
legacy-appusing thebusybox:1.36image with the commandsleep 3600 - Drop ALL capabilities from the container
- The pod should run successfully without any capabilities
- Verify the pod is running and has no capabilities
Question 3
Difficulty: Easy
Scenario: The production namespace needs to enforce the Baseline Pod Security Standard to prevent clearly dangerous pod configurations.
Task:
- Create a namespace called
production - Label the namespace to enforce the
baselinePod Security Standard - Also configure the namespace to
warnat therestrictedlevel - Verify that a privileged pod is rejected in this namespace
Question 4
Difficulty: Easy
Scenario: Your organization requires all application pods to run as non-root users.
Task:
- Create a pod named
nonroot-appin thedefaultnamespace using thepython:3.12-slimimage - Configure the pod to run as user ID
1000and group ID1000 - Set
runAsNonRoot: true - Set
allowPrivilegeEscalation: false - The command should be:
python -m http.server 8080 - Verify the pod is running and the process is running as UID 1000
Question 5
Difficulty: Easy
Scenario: You need to create a pod with a read-only root filesystem for an nginx web server.
Task:
- Create a pod named
readonly-nginxusingnginx:1.27 - Set
readOnlyRootFilesystem: true - Mount emptyDir volumes at
/var/cache/nginx,/var/run, and/tmpso nginx can function - Verify the pod runs successfully
- Verify that writing to
/etcinside the container fails
Question 6
Difficulty: Medium
Scenario: A custom seccomp profile must be deployed to restrict a specific container from making network-related syscalls.
Task:
- Create a seccomp profile JSON file that uses
SCMP_ACT_ALLOWas the default action but blocks the following syscalls:socket,connect,bind,listen,accept,accept4,sendto,recvfrom - Place the profile at
/var/lib/kubelet/seccomp/profiles/block-networking.jsonon the node - Create a pod named
no-net-podusingbusybox:1.36with commandsleep 3600that uses this custom profile - Verify the pod is running and that network operations fail inside the container
Question 7
Difficulty: Medium
Scenario: You need to create a deployment where all pods meet the Restricted Pod Security Standard requirements.
Task:
- Create a namespace called
restricted-nsand enforce therestrictedPod Security Standard - Create a Deployment named
secure-apiinrestricted-nswith 2 replicas - Use the
python:3.12-slimimage with command["python", "-m", "http.server", "8080"] - The deployment must meet all Restricted PSS requirements:
- Run as non-root (UID 1000)
- Drop ALL capabilities
- Set
allowPrivilegeEscalation: false - Use
RuntimeDefaultseccomp profile - Use read-only root filesystem with a writable
/tmpvolume
- Verify all pods are running
Question 8
Difficulty: Medium
Scenario: An AppArmor profile needs to be loaded on the node and applied to a pod that prevents the container from writing to any location on the filesystem.
Task:
- Create an AppArmor profile named
k8s-deny-writethat denies all write operations while allowing reads and network access - Load the profile on the Kind cluster node (use
docker execto access the node) - Create a pod named
readonly-enforcedusingbusybox:1.36with commandsleep 3600that uses this AppArmor profile - Verify the AppArmor profile is active on the container
- Verify that write operations are denied
Question 9
Difficulty: Medium
Scenario: Multiple namespaces in your cluster need different levels of Pod Security Standards.
Task:
- Create three namespaces:
ns-privileged,ns-baseline,ns-restricted - Apply appropriate PSS labels:
ns-privileged: enforceprivilegedns-baseline: enforcebaseline, warnrestrictedns-restricted: enforcerestricted, warnrestricted, auditrestricted
- Verify that:
- A privileged pod can be created in
ns-privileged - A privileged pod is rejected in
ns-baseline - A normal nginx pod (without hardening) is rejected in
ns-restricted
- A privileged pod can be created in
Question 10
Difficulty: Medium
Scenario: You need to create a pod that combines multiple security hardening measures: seccomp, capabilities, and non-root execution.
Task:
- Create a pod named
hardened-appusingnginx:1.27image - Apply the following security configurations:
- RuntimeDefault seccomp profile (pod level)
- Drop ALL capabilities, add only
NET_BIND_SERVICE - Run as non-root is NOT required (nginx needs root to start)
- Set
allowPrivilegeEscalation: false - Read-only root filesystem
- Mount emptyDir at
/var/cache/nginx,/var/run,/tmp
- Verify the pod is running and serving on port 80
Question 11
Difficulty: Medium
Scenario: A seccomp profile needs to be created that logs (audits) syscalls instead of blocking them, for use during a security assessment.
Task:
- Create a seccomp profile that uses
SCMP_ACT_LOGas the default action (allows all syscalls but logs them) - Place it at
/var/lib/kubelet/seccomp/profiles/audit-all.jsonon the node - Create a pod named
audit-podusingbusybox:1.36with command["sh", "-c", "wget -qO- http://kubernetes.default.svc 2>&1; sleep 3600"]that uses this profile - Verify the pod is running
Question 12
Difficulty: Medium
Scenario: You need to identify and fix a pod running with dangerous host namespace settings.
Task:
- Create a pod named
dangerous-podwith the following (intentionally insecure) settings:- Image:
nginx:1.27 hostNetwork: truehostPID: trueprivileged: true
- Image:
- Identify all the security violations in this pod
- Create a fixed version named
safe-podwith the same image that:- Does NOT use host networking
- Does NOT share host PID namespace
- Is NOT privileged
- Drops ALL capabilities, adds only
NET_BIND_SERVICE - Runs with RuntimeDefault seccomp
- Uses a read-only root filesystem (with necessary writable mounts)
Question 13
Difficulty: Hard
Scenario: You need to deploy a complete hardened nginx stack with AppArmor, seccomp, capabilities, and Pod Security Standards all working together.
Task:
- Create a namespace
hardened-webwithrestrictedPSS enforcement - Create an AppArmor profile
k8s-nginx-restrictedon the node that:- Allows file reads everywhere
- Allows writes only to
/var/cache/nginx/**,/var/run/**,/tmp/**, and/dev/null - Allows TCP networking
- Allows capabilities:
net_bind_service,setuid,setgid,chown,dac_override - Denies
sys_admincapability
- Create a pod named
nginx-fortressinhardened-webthat:- Uses the AppArmor profile
- Uses RuntimeDefault seccomp
- Drops ALL capabilities, adds
NET_BIND_SERVICE,CHOWN,SETUID,SETGID,DAC_OVERRIDE - Runs with
allowPrivilegeEscalation: false - Has read-only root filesystem with writable volumes for cache, run, and tmp
- Note: The restricted PSS requires
runAsNonRoot: trueand dropping ALL capabilities with onlyNET_BIND_SERVICEallowed. The pod spec must be adjusted to satisfy PSS while maintaining nginx functionality. If the standard nginx image cannot comply with restricted PSS, create it in a namespace with baseline enforcement instead and document why.
Question 14
Difficulty: Hard
Scenario: Create a seccomp profile that implements an allowlist for a web server -- only permitting the exact syscalls needed and blocking everything else.
Task:
- Create a strict allowlist seccomp profile with
SCMP_ACT_ERRNOas the default action - Allow only the following syscalls:
accept4,arch_prctl,bind,brk,clone,close,connect,dup2,epoll_create1,epoll_ctl,epoll_wait,execve,exit,exit_group,fchown,fcntl,fstat,futex,getdents64,getpid,getppid,getuid,ioctl,listen,lseek,madvise,mmap,mprotect,munmap,nanosleep,newfstatat,openat,pipe2,pread64,prlimit64,read,recvfrom,recvmsg,rt_sigaction,rt_sigprocmask,rt_sigreturn,sendmsg,sendto,set_robust_list,set_tid_address,setgid,setgroups,setuid,setsockopt,socket,stat,uname,write,writev - Place it at
/var/lib/kubelet/seccomp/profiles/nginx-strict.jsonon the node - Create a pod named
strict-nginxusingnginx:1.27that uses this profile - Verify the pod starts and nginx is functional (can serve HTTP requests)
Question 15
Difficulty: Hard
Scenario: You discover several pods across multiple namespaces that have security issues. You need to audit and fix them.
Task:
- Create the following intentionally insecure pods in the
defaultnamespace:pod-a:nginx:1.27withprivileged: truepod-b:busybox:1.36(sleep 3600) withhostPID: trueandhostNetwork: truepod-c:nginx:1.27with capabilitiesSYS_ADMINandNET_ADMINadded
- Write kubectl commands to identify:
- All pods with
privileged: true - All pods with
hostPID: true - All pods with
SYS_ADMINcapability
- All pods with
- Create fixed replacements for each pod:
pod-a-fixed: Not privileged, drop ALL capabilities, addNET_BIND_SERVICEpod-b-fixed: No host namespaces, drop ALL capabilitiespod-c-fixed: No dangerous capabilities, drop ALL, add onlyNET_BIND_SERVICE
Question 16
Difficulty: Hard
Scenario: Configure a namespace with Pod Security Standards and then create pods that demonstrate the boundary between what's allowed and what's blocked.
Task:
- Create namespace
pss-testwithbaselineenforcement andrestrictedwarning - Create pod
test-baseline-pass-- a pod that passes baseline (no privileged, no hostNet/PID/IPC) usingnginx:1.27 - Create pod
test-baseline-fail-- attempt a pod withprivileged: true(should be rejected) - Note the warning messages when
test-baseline-passtriggers restricted-level warnings - Document which specific restricted-level violations the nginx pod has
- Create pod
test-restricted-passthat passes even the restricted level in the same namespace
Question 17
Difficulty: Hard
Scenario: An AppArmor profile that restricts network access needs to be deployed to prevent a container from making any outbound network connections.
Task:
- Create an AppArmor profile named
k8s-deny-networkthat:- Allows all file operations
- Denies all network access (
deny network)
- Load the profile on the Kind node
- Create a pod named
isolated-appusingbusybox:1.36with commandsleep 3600 - Apply the AppArmor profile to the pod
- Verify:
- The pod is running
- File operations work:
ls /,cat /etc/hostname - Network operations fail:
wget -qO- http://kubernetes.default.svcshould fail - DNS resolution fails:
nslookup kubernetes.defaultshould fail
Question 18
Difficulty: Hard
Scenario: You need to create a comprehensive security policy for a multi-tier application with different security requirements for each tier.
Task:
- Create namespace
multi-tierwithbaselineenforcement - Create a frontend pod named
frontendwith:- Image:
nginx:1.27 - Drop ALL capabilities, add
NET_BIND_SERVICE allowPrivilegeEscalation: false- RuntimeDefault seccomp
- Read-only root filesystem (with nginx writable volumes)
- Image:
- Create a backend pod named
backendwith:- Image:
python:3.12-slim - Command:
["python", "-m", "http.server", "8080"] - Drop ALL capabilities
- Run as user 1000 (non-root)
allowPrivilegeEscalation: false- RuntimeDefault seccomp
- Read-only root filesystem (with
/tmpwritable)
- Image:
- Create a worker pod named
workerwith:- Image:
busybox:1.36 - Command:
["sh", "-c", "while true; do echo working; sleep 60; done"] - Drop ALL capabilities
- Run as user 1000 (non-root)
allowPrivilegeEscalation: false- RuntimeDefault seccomp
- Read-only root filesystem (with
/tmpwritable)
- Image:
- Verify all three pods are running
Question 19
Difficulty: Hard
Scenario: Create a comprehensive seccomp + capability configuration that demonstrates the interaction between the two security mechanisms.
Task:
- Create a seccomp profile that blocks the
ptrace,mount,umount2,kexec_load,reboot,setns,unshare, andbpfsyscalls (usingSCMP_ACT_ALLOWas default andSCMP_ACT_ERRNOfor the blocked ones) - Place it on the node at
/var/lib/kubelet/seccomp/profiles/hardened-default.json - Create a pod named
double-hardenedusingbusybox:1.36with commandsleep 3600:- Use the custom seccomp profile
- Drop ALL capabilities
- Run as user 1000
allowPrivilegeEscalation: falsereadOnlyRootFilesystem: truewith/tmpwritable
- Verify:
- The pod is running
mountoperations fail- Cannot trace processes
- File reads work
- Writing to
/tmpworks - Writing to
/etcfails
Question 20
Difficulty: Hard
Scenario: You are performing a security audit. Several pods are running across the cluster with various security configurations. You need to audit them, generate a report, and fix the most critical issues.
Task:
- Create the following pods in namespace
audit-ns(create the namespace first):web-exposed:nginx:1.27withhostNetwork: truedb-privileged:busybox:1.36(sleep 3600) withprivileged: trueapp-overcapped:busybox:1.36(sleep 3600) with capabilitiesSYS_ADMIN,SYS_PTRACE,NET_ADMINaddedworker-ok:busybox:1.36(sleep 3600) withrunAsUser: 1000,runAsNonRoot: true, capabilities dropped ALL
- Run audit commands to:
- List all pods with host namespace sharing
- List all privileged pods
- List all pods with dangerous capabilities
- Identify the one pod that is properly hardened
- Delete the three insecure pods
- Create hardened replacements (
web-fixed,db-fixed,app-fixed) that:- Do not use host namespaces
- Are not privileged
- Drop ALL capabilities (add
NET_BIND_SERVICEonly for the web pod) - Set
allowPrivilegeEscalation: false - Use RuntimeDefault seccomp
- Apply
baselinePSS enforcement to theaudit-nsnamespace to prevent future insecure pods - Verify the enforcement by attempting to create a privileged pod (should be rejected)
Exam Preparation Strategy
- Practice under time pressure -- aim to complete each Easy question in 3-5 minutes, Medium in 5-8 minutes, and Hard in 8-12 minutes
- Memorize key YAML structures -- SecurityContext, seccomp profiles, AppArmor configurations
- Use
kubectl explain--kubectl explain pod.spec.securityContextis available during the exam - Use
--dry-run=server-- test pod creation against PSS without actually creating the pod - Know the Kubernetes docs -- bookmark the security context and PSS documentation pages