Skip to content

KCSA: Overview of Cloud Native Security

14% of the KCSA exam, 6 competencies. Back to the KCSA overview.

Each competency lists what to know and the official documentation to read, then a demo you can run. Demos run on the demo lab, a throwaway kind cluster on your own machine; set it up once before you start.

Know

  • Cloud, cluster, container, code: each layer can only be as secure as the one around it.

Read

Demo: One check per layer

  1. Create a namespace for this demo and make it the default for your context.

    Terminal window
    kubectl create namespace kcsa-4cs
    kubectl config set-context --current --namespace=kcsa-4cs
  2. Cloud and node: the host kernel every container shares.

    Terminal window
    docker exec kind-worker uname -r
    kubectl run probe --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 -- sleep 3600 && kubectl wait --for=condition=Ready pod/probe --timeout=60s
    kubectl exec probe -- uname -r
  3. Cluster: how the API server authenticates and authorizes.

    Terminal window
    docker exec kind-control-plane grep -E -- '--(authorization-mode|anonymous-auth|enable-admission-plugins|client-ca-file)' /etc/kubernetes/manifests/kube-apiserver.yaml
  4. Container: what the process runs as by default.

    Terminal window
    kubectl exec probe -- id
    kubectl exec probe -- grep CapEff /proc/1/status

What you should see: The pod reports the same kernel as the node: a kernel exploit in any container is a node compromise. The API server uses Node,RBAC authorization and client certificates. The container runs as root with a set of default capabilities. Code, the fourth C, is the part only you can fix.

Clean up:

Terminal window
kubectl config set-context --current --namespace=default
kubectl delete namespace kcsa-4cs

Cloud Provider and Infrastructure Security

Section titled “Cloud Provider and Infrastructure Security”

Know

  • Lock down node access, the cloud metadata API, the control plane endpoint, and network paths to etcd.

Read

Demo: What a node exposes, and blocking the metadata service

  1. Create a namespace for this demo and make it the default for your context.

    Terminal window
    kubectl create namespace kcsa-infra
    kubectl config set-context --current --namespace=kcsa-infra
  2. List what listens on a node. Each port is attack surface.

    Terminal window
    docker exec kind-worker ss -tlnp
  3. Block pods from reaching the cloud metadata address while allowing everything else.

    Terminal window
    kubectl apply -f - <<'EOF'
    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy
    metadata:
    name: no-metadata
    spec:
    podSelector: {}
    policyTypes: ["Egress"]
    egress:
    - to:
    - ipBlock:
    cidr: 0.0.0.0/0
    except:
    - 169.254.169.254/32
    EOF
    kubectl get networkpolicy no-metadata -o yaml | sed -n '/^spec:/,$p'

What you should see: The node listens on the kubelet API (10250), kube-proxy’s health and metrics ports, and containerd’s local endpoints. kind runs on your machine, so there is no metadata service to reach; on a cloud node the same policy stops a compromised pod from fetching the node’s cloud credentials from 169.254.169.254.

Clean up:

Terminal window
kubectl config set-context --current --namespace=default
kubectl delete namespace kcsa-infra

Know

  • Preventive (RBAC, admission), detective (audit logs, runtime detection), and corrective controls, mapped to frameworks such as CIS Benchmarks and NIST.

Read

Demo: use the CKS demo for “Use CIS benchmark to review the security configuration of Kubernetes components (etcd, kubelet, kubedns, kubeapi)”. The CIS Kubernetes Benchmark is the framework you will meet most often; the CKS demo runs it against the lab cluster with kube-bench.

Know

  • Namespaces, RBAC, NetworkPolicies, node isolation with taints, sandboxed runtimes (gVisor, Kata) via RuntimeClass.

Read

Demo: What a pod sees with and without host namespaces

  1. Create a namespace for this demo and make it the default for your context.

    Terminal window
    kubectl create namespace kcsa-isolation
    kubectl config set-context --current --namespace=kcsa-isolation
  2. A normal pod sees only its own processes.

    Terminal window
    kubectl run normal --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 -- sleep 3600
    kubectl wait --for=condition=Ready pod/normal --timeout=60s
    kubectl exec normal -- ps
  3. A pod with hostPID: true sees every process on the node, including the kubelet.

    Terminal window
    kubectl run hostpid --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 --overrides='{"spec":{"hostPID":true}}' -- sleep 3600
    kubectl wait --for=condition=Ready pod/hostpid --timeout=60s
    kubectl exec hostpid -- sh -c 'ps | grep -E "kubelet|containerd" | grep -v grep | head -3'
  4. Ask the namespace to refuse that.

    Terminal window
    kubectl label namespace kcsa-isolation pod-security.kubernetes.io/enforce=baseline
    kubectl run hostpid2 --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 --overrides='{"spec":{"hostPID":true}}' -- sleep 3600

What you should see: The normal pod lists two processes. The hostPID pod lists the kubelet and containerd. Under the baseline level that pod is rejected with host namespaces (hostPID=true). Linux namespaces are the isolation; host namespaces switch it off.

Clean up:

Terminal window
kubectl config set-context --current --namespace=default
kubectl delete namespace kcsa-isolation

Know

  • Use private registries, scan images, pin by digest, and sign images.

Read

Demo: Pin by digest and see what the node trusts

  1. Create a namespace for this demo and make it the default for your context.

    Terminal window
    kubectl create namespace kcsa-artifacts
    kubectl config set-context --current --namespace=kcsa-artifacts
  2. Read the digest a tag resolved to, then run by digest.

    Terminal window
    kubectl run bytag --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- pause
    kubectl wait --for=condition=Ready pod/bytag --timeout=120s
    REF=$(kubectl get pod bytag -o jsonpath='{.status.containerStatuses[0].imageID}'); echo $REF
    kubectl run bydigest --image="$REF" -- pause
  3. Inspect the image on the node through the runtime.

    Terminal window
    NODE=$(kubectl get pod bytag -o jsonpath='{.spec.nodeName}')
    docker exec $NODE crictl inspecti registry.k8s.io/e2e-test-images/agnhost:2.66.1 | jq '.status.repoDigests, .status.size'

What you should see: A tag such as 2.66.1 can be re-pushed to point at different content; the sha256: digest can’t. Pinning by digest in manifests, together with signature verification (see the CKS supply chain demos), is how you make sure what runs is what you reviewed.

Clean up:

Terminal window
kubectl config set-context --current --namespace=default
kubectl delete namespace kcsa-artifacts

On this site

Know

  • Run as non-root, drop capabilities, read-only root filesystem, and keep secrets out of images.

Read

Demo: use the CKAD demo for “Understand Application Security (SecurityContexts, Capabilities, etc.)”. It locks down a pod with a non-root user, a read-only root filesystem, and no capabilities, and tests each control from inside.


Domain and competency names are from the CNCF KCSA curriculum (current curriculum (unversioned)), cncf/curriculum, licensed CC BY 4.0. Summaries, demos, and exercises are original to this site.