Skip to content

KCSA: Kubernetes Cluster Component Security

22% of the KCSA exam, 11 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

  • The only component that talks to etcd. Protect it with TLS, authentication, authorization, admission, and audit logging; never expose it anonymously.

Read

Demo: What the API server answers to strangers

  1. Call the API server with no credentials from the control plane node.

    Terminal window
    docker exec kind-control-plane curl -sk https://127.0.0.1:6443/version | head -5
    docker exec kind-control-plane curl -sk https://127.0.0.1:6443/api/v1/namespaces/kube-system/secrets
  2. See which bindings allow anonymous requests at all.

    Terminal window
    kubectl get clusterrolebinding system:public-info-viewer -o jsonpath='{.subjects}{"\n"}'
    kubectl describe clusterrole system:public-info-viewer

What you should see: /version answers anonymously; listing secrets returns 403 User "system:anonymous" cannot list resource "secrets". Anonymous access is on, but RBAC only gives system:unauthenticated the health and version endpoints. If someone binds a broad role to system:anonymous or system:unauthenticated, the cluster is open to anyone who can reach port 6443.

On this site

Know

  • Runs with powerful credentials; secure its kubeconfig and use per-controller service account credentials.

Read

Demo: Local-only ports and per-controller identities

  1. Read the flags that matter for security.

    Terminal window
    docker exec kind-control-plane grep -E -- '--(bind-address|use-service-account-credentials|service-account-private-key-file|root-ca-file)' /etc/kubernetes/manifests/kube-controller-manager.yaml
  2. Health is public, metrics are not.

    Terminal window
    docker exec kind-control-plane curl -sk https://127.0.0.1:10257/healthz; echo
    docker exec kind-control-plane curl -sk -o /dev/null -w '%{http_code}\n' https://127.0.0.1:10257/metrics
  3. Each controller runs as its own service account.

    Terminal window
    kubectl get serviceaccounts -n kube-system | grep -E 'controller|deployment|replicaset' | head

What you should see: The controller manager binds to 127.0.0.1 only. /healthz returns ok while /metrics returns 403 to an anonymous caller. With --use-service-account-credentials=true, a compromised controller has only its own controller’s permissions.

Know

  • A compromised scheduler can place pods anywhere; restrict access to its configuration and bind it to localhost.

Read

Demo: Same pattern as the controller manager

  1. Read its flags and probe its port.

    Terminal window
    docker exec kind-control-plane grep -E -- '--(bind-address|kubeconfig|authentication-kubeconfig|authorization-kubeconfig)' /etc/kubernetes/manifests/kube-scheduler.yaml
    docker exec kind-control-plane curl -sk https://127.0.0.1:10259/livez; echo
    docker exec kind-control-plane curl -sk -o /dev/null -w '%{http_code}\n' https://127.0.0.1:10259/metrics
  2. What the scheduler is allowed to do.

    Terminal window
    kubectl auth can-i --list --as=system:kube-scheduler | head -20

What you should see: Bound to 127.0.0.1, public health endpoint, protected metrics. Its own identity, system:kube-scheduler, can bind pods to nodes but can’t read Secrets. Someone who can change the scheduler can still decide where every pod runs, so its manifest and kubeconfig need the same protection as the API server’s.

Know

  • Disable anonymous access, use webhook authorization, and restrict its API. The Node authorizer and NodeRestriction admission limit what a kubelet can change.

Read

Demo: Call the kubelet API with and without credentials

  1. Anonymous calls to the kubelet are refused.

    Terminal window
    docker exec kind-control-plane curl -sk -o /dev/null -w '%{http_code}\n' https://kind-worker:10250/pods
  2. Read the kubelet’s live configuration through the API server.

    Terminal window
    kubectl get --raw /api/v1/nodes/kind-worker/proxy/configz | jq '.kubeletconfig | {authentication, authorization, readOnlyPort}'
  3. Who may proxy to kubelets: that permission is as strong as exec.

    Terminal window
    kubectl auth can-i get nodes/proxy --as=system:serviceaccount:default:default
    kubectl get clusterroles -o json | jq -r '.items[] | select(any(.rules[]?; (.resources // []) | index("nodes/proxy"))) | .metadata.name'

What you should see: The kubelet returns 401 to an anonymous caller: anonymous.enabled is false and authorization is Webhook, so the API server decides. readOnlyPort is 0 (off). Any role that grants nodes/proxy lets its holder talk to kubelets directly; audit those roles.

Know

  • The runtime enforces namespaces, cgroups, seccomp, and AppArmor. Keep it patched; sandboxed runtimes add a stronger boundary.

Read

Demo: The runtime socket and runtime classes

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

    Terminal window
    kubectl create namespace kcsa-runtime
    kubectl config set-context --current --namespace=kcsa-runtime
  2. Whoever can reach this socket controls every container on the node.

    Terminal window
    docker exec kind-worker ls -l /run/containerd/containerd.sock
    docker exec kind-worker crictl info | jq '.config.containerd.runtimes // .config | keys' 2>/dev/null | head
  3. Ask for a runtime the node doesn’t have.

    Terminal window
    kubectl apply -f - <<'EOF'
    apiVersion: node.k8s.io/v1
    kind: RuntimeClass
    metadata:
    name: gvisor
    handler: runsc
    EOF
    kubectl run sandboxed --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 --overrides='{"spec":{"runtimeClassName":"gvisor"}}' -- sleep 3600
    sleep 15; kubectl describe pod sandboxed | sed -n '/Events:/,$p'

What you should see: The socket is owned by root with mode srw-rw----. Mounting it into a pod (a hostPath to /run/containerd/containerd.sock) hands that pod the node. The gvisor pod fails to start with an event saying no runtime is configured for runsc: a RuntimeClass only selects a handler, and each node must have that handler installed.

Clean up:

Terminal window
kubectl delete runtimeclass gvisor
kubectl config set-context --current --namespace=default
kubectl delete namespace kcsa-runtime

Know

  • Programs node networking for Services; its metrics and health endpoints should not be exposed outside the node.

Read

Demo: What kube-proxy writes on every node

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

    Terminal window
    kubectl create namespace kcsa-kubeproxy
    kubectl config set-context --current --namespace=kcsa-kubeproxy
  2. Find its mode and its identity.

    Terminal window
    kubectl get configmap kube-proxy -n kube-system -o jsonpath='{.data.config\.conf}' | grep -E '^mode|metricsBindAddress|healthzBindAddress'
    kubectl get daemonset kube-proxy -n kube-system -o jsonpath='{.spec.template.spec.serviceAccountName}{"\n"}'
  3. Create a Service and find its rules on a node.

    Terminal window
    kubectl create deployment web --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- /agnhost netexec --http-port=8080
    kubectl expose deployment web --port=80 --target-port=8080
    IP=$(kubectl get service web -o jsonpath='{.spec.clusterIP}')
    docker exec kind-worker sh -c "iptables-save -t nat | grep $IP"

What you should see: kind runs kube-proxy in iptables mode by default. The Service’s cluster IP appears in the node’s NAT table, pointing at a chain that load-balances to pod IPs. kube-proxy runs privileged with host networking; anyone who can change its ConfigMap or DaemonSet can redirect Service traffic on every node.

Clean up:

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

Know

  • The unit of isolation: security context, service account, volumes, and host access settings decide its blast radius.

Read

Demo: Privileged versus unprivileged, from inside

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

    Terminal window
    kubectl create namespace kcsa-pod
    kubectl config set-context --current --namespace=kcsa-pod
  2. Compare what two pods can see.

    Terminal window
    kubectl run plain --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 -- sleep 3600
    kubectl run priv --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 --overrides='{"spec":{"containers":[{"name":"priv","image":"registry.k8s.io/e2e-test-images/busybox:1.37.0-2","command":["sleep","3600"],"securityContext":{"privileged":true}}]}}'
    kubectl wait --for=condition=Ready pod/plain pod/priv --timeout=60s
    for p in plain priv; do echo "$p: $(kubectl exec $p -- sh -c 'ls /dev | wc -l') devices, $(kubectl exec $p -- grep CapEff /proc/1/status)"; done
  3. A privileged pod can mount the node’s disk.

    Terminal window
    kubectl exec priv -- sh -c 'ls /dev | grep -E "^(sd|vd|nvme|xvd)" | head -3'

What you should see: The plain pod sees a handful of devices and a limited capability set; the privileged one sees the node’s devices with every capability (000001ffffffffff). Privileged is root on the node in all but name, which is why baseline and restricted both forbid it.

Clean up:

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

Know

  • Holds all cluster state, including Secrets. Use TLS between members and clients, restrict network access, and encrypt Secrets at rest.

Read

Demo: Client certificates and plain-text Secrets

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

    Terminal window
    kubectl create namespace kcsa-etcd
    kubectl config set-context --current --namespace=kcsa-etcd
  2. etcd refuses clients without a certificate signed by its CA.

    Terminal window
    docker exec kind-control-plane curl -s --cacert /etc/kubernetes/pki/etcd/ca.crt https://127.0.0.1:2379/version; echo "exit code $?"
    docker exec kind-control-plane curl -s --cacert /etc/kubernetes/pki/etcd/ca.crt \
    --cert /etc/kubernetes/pki/etcd/healthcheck-client.crt --key /etc/kubernetes/pki/etcd/healthcheck-client.key \
    https://127.0.0.1:2379/version; echo
  3. Read a Secret straight out of etcd.

    Terminal window
    kubectl create secret generic plain --from-literal=password=VisibleInEtcd
    kubectl -n kube-system exec etcd-kind-control-plane -- etcdctl --endpoints=https://127.0.0.1:2379 \
    --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key \
    get /registry/secrets/kcsa-etcd/plain | grep -a -o VisibleInEtcd

What you should see: Without a client certificate the TLS handshake fails. With one, /version answers. The Secret value comes back as plain text from etcd, because kind (like kubeadm) doesn’t enable encryption at rest by default. Anyone with etcd access or a copy of its disk or backups has every Secret; the CKS secrets demo turns encryption on.

Clean up:

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

On this site

Know

  • Flat pod networking means any pod can reach any pod until NetworkPolicies say otherwise.

Read

Demo: Pods can reach more than you think

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

    Terminal window
    kubectl create namespace kcsa-cni
    kubectl config set-context --current --namespace=kcsa-cni
  2. From an ordinary pod, reach the kubelet port on a node and a pod in another namespace.

    Terminal window
    kubectl run probe --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- pause
    kubectl create namespace kcsa-other
    kubectl create deployment target -n kcsa-other --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- /agnhost netexec --http-port=8080
    kubectl expose deployment target -n kcsa-other --port=8080
    kubectl rollout status deployment/target -n kcsa-other
    NODEIP=$(kubectl get node kind-worker -o jsonpath='{.status.addresses[0].address}')
    kubectl exec probe -- sh -c "nc -zv -w 2 $NODEIP 10250; wget -qO- -T 3 http://target.kcsa-other:8080/hostname; echo"
  3. Default-deny egress for the namespace, except DNS.

    Terminal window
    kubectl apply -f - <<'EOF'
    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy
    metadata:
    name: egress-dns-only
    spec:
    podSelector: {}
    policyTypes: ["Egress"]
    egress:
    - to:
    - namespaceSelector:
    matchLabels:
    kubernetes.io/metadata.name: kube-system
    podSelector:
    matchLabels:
    k8s-app: kube-dns
    ports:
    - {protocol: UDP, port: 53}
    - {protocol: TCP, port: 53}
    EOF
    kubectl exec probe -- sh -c "nc -zv -w 2 $NODEIP 10250; wget -qO- -T 3 http://target.kcsa-other:8080/hostname; echo"

What you should see: Before the policy, the pod opens the kubelet port and reads from a pod in another namespace: the default network is flat and open. After it, both fail while DNS still resolves. Default-deny plus explicit allows is the baseline every namespace should start from.

Clean up:

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

On this site

Know

  • Kubeconfig files are credentials. Prefer short-lived tokens from an identity provider over long-lived client certificates.

Read

Demo: What is inside your kubeconfig

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

    Terminal window
    kubectl create namespace kcsa-client
    kubectl config set-context --current --namespace=kcsa-client
  2. Decode the client certificate kubectl uses.

    Terminal window
    kubectl config view --minify --raw -o jsonpath='{.users[0].user.client-certificate-data}' | base64 -d \
    | openssl x509 -noout -subject -issuer -enddate
  3. Check what that identity can do, then make a scoped kubeconfig instead.

    Terminal window
    kubectl auth whoami
    kubectl create serviceaccount ci-reader
    kubectl create rolebinding ci-reader --clusterrole=view --serviceaccount=kcsa-client:ci-reader
    kubectl create token ci-reader --duration=1h | cut -c1-40; echo '...'

What you should see: The subject is CN=kubernetes-admin, O=kubeadm:cluster-admins with a one-year expiry, and the private key sits next to it in the file. Anyone who copies that file is cluster-admin until the certificate expires; client certificates can’t be revoked. Short-lived, scoped tokens (like the one-hour ci-reader token) are the safer thing to hand out.

Clean up:

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

Know

  • Encrypt volumes at rest, restrict hostPath, and treat PV reclaim policy as a data-disposal decision.

Read

Demo: A hostPath mount reaches the node

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

    Terminal window
    kubectl create namespace kcsa-storage
    kubectl config set-context --current --namespace=kcsa-storage
  2. Mount the node’s root filesystem read-only and read the cluster CA key.

    Terminal window
    kubectl label namespace kcsa-storage pod-security.kubernetes.io/warn=baseline
    kubectl apply -f - <<'EOF'
    apiVersion: v1
    kind: Pod
    metadata:
    name: hostpath
    spec:
    nodeName: kind-control-plane
    tolerations:
    - operator: Exists
    containers:
    - name: app
    image: registry.k8s.io/e2e-test-images/busybox:1.37.0-2
    command: ["sleep", "3600"]
    volumeMounts:
    - name: host
    mountPath: /host
    readOnly: true
    volumes:
    - name: host
    hostPath:
    path: /
    EOF
    kubectl wait --for=condition=Ready pod/hostpath --timeout=60s
    kubectl exec hostpath -- ls -l /host/etc/kubernetes/pki/ca.key

What you should see: apply prints a warning that the pod would violate the baseline policy (hostPath volumes), but warn mode still lets it in, and the pod can read the cluster CA private key. Read-only doesn’t help: reading is the damage. This is why baseline forbids hostPath; use enforce, not only warn.

Clean up:

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

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.