Appendix B: Final Exam
Twelve tasks from across the book. Solve them yourself first, then
look at the solution. The hands-on tasks run in your lab
(shop/attacker). You pass with 9 out of
12.
Questions
1. One pod gets 403 from the API on
list pods in its own namespace, another gets
401. What is the difference?
2. Why is impersonate on
groups effectively cluster-admin?
3. You may create pods in namespace x
but have no Secret rights. How do you still get at a Secret in
x?
4. Name the one command that opens a shell on the
node from a privileged+hostPID pod.
5. hostPath: / – which PSA profile
(baseline or restricted) already stops
this?
6. Why is a kubelet on :10250 that
returns 401 for anonymous requests still not complete
protection?
7. What does a NetworkPolicy with an
empty podSelector and no ingress rule do?
8. A password is set as an env value in
the pod spec. Name two places where this makes it readable.
9. Why is Base64 in etcd not encryption, and how do you check on RKE2 whether encryption at rest is on?
10. A Kyverno policy exists, but the forbidden pod runs anyway. Name two possible causes.
11. CVE-2020-8554 (externalIPs) – why does no version upgrade alone fix the problem?
12. Hands-on: Accidentally give the
default SA in attacker cluster-wide Secret
read access, prove it, revoke it again, and prove that it is gone.
Solutions
1. 401 = not authenticated (no or
invalid token); 403 = authenticated but not authorized
(known account without the RBAC right).
automountServiceAccountToken: false turns a
403 into a 401.
2. The group system:masters is
hard-wired to cluster-admin in the kube-apiserver. Anyone with
impersonate on groups sets the header
Impersonate-Group: system:masters and acts with full power
– without needing any rights themselves.
3. Create a pod with
serviceAccountName: <privilegierter-SA>; the pod
inherits its token and reads the Secret. “Create pods” = takeover of
every SA in the namespace.
4. nsenter -t 1 -m -u -i -n -p -- bash
(PID 1 = the node’s init process).
5. baseline – it already forbids
hostPath volumes. restricted goes further
(only a few safe volume types, non-root, capabilities dropped).
6. The port is still reachable from the pod network,
and with nodes/proxy RBAC or stolen kubelet credentials you
get around the 401. Protection additionally needs RBAC
hygiene and network segmentation.
7. Default deny for ingress: All pods in the namespace no longer accept incoming traffic until an allowing policy opens it selectively.
8. Among others:
kubectl get pod -o yaml/describe, the kubelet
proxy /pods (Day 7), the manifest in Git, audit/event logs.
(Two are enough.)
9. Base64 is only an encoding, trivially reversible
– anyone who reads etcd (or a snapshot) has the plaintext. Check:
sudo rke2 secrets-encrypt status →
Encryption Status: Enabled.
10. For example: policy in Audit mode
instead of Deny; scope too narrow (another namespace not
covered); operations without UPDATE;
failurePolicy: Ignore with a failed webhook. (Two are
enough.)
11. externalIPs is a legitimate API
field, not a code bug – an upgrade does not remove it. The defense is an
admission policy that forbids the field, plus RBAC on
services/status.
12. Hands-on:
# grant
kubectl apply -f - <<'EOF'
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata: {name: exam-reader}
rules: [{apiGroups: [""], resources: ["secrets"], verbs: ["get","list"]}]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata: {name: exam-reader}
subjects: [{kind: ServiceAccount, name: default, namespace: attacker}]
roleRef: {kind: ClusterRole, name: exam-reader, apiGroup: rbac.authorization.k8s.io}
EOF
# prove
kubectl auth can-i list secrets --as=system:serviceaccount:attacker:default -A # yes
# revoke
kubectl delete clusterrolebinding exam-reader
kubectl delete clusterrole exam-reader
# prove it is gone
kubectl auth can-i list secrets --as=system:serviceaccount:attacker:default -A # noAfter the exam
You have seen a cluster from the inside – as an attacker – and closed every gap yourself. That is the difference between “we have policies” and “I have proven that it is closed”. Take the cheat sheet (Appendix A) as your ongoing checklist and run a gameday (Day 15) every now and then. And remember the one rule: only your own clusters.