Your own Kubernetes cluster: blast radius, settings and reachability
Unit 5 of 5 in Active Directory, cloud and cluster assessment.
You will be able to build a practice cluster, say what one compromised pod could see and reach, read kubelet and workload settings, and prove a network policy with a before-and-after matrix.
Lesson
A cluster you can break
kind runs local Kubernetes clusters using Docker containers as nodes, so a cluster can be created from a config file, assessed and thrown away on your own machine. The first lab builds one practice cluster with a written register of nine documented misconfigurations, so every later lab assesses, measures and fixes the same system and the series reads as one assessment.
Blast radius: what can one pod reach?
Start from the question a defender would ask: assume one pod is taken over, what can it see and reach? Kubernetes gives each pod the credentials of its assigned service account, the default one unless you name another, unless automatic mounting is turned off in the pod specification; since version 1.22 the token is short-lived and rotated. What that credential may do is decided by RBAC.
The Kubernetes RBAC good-practice page says to give minimal rights, to assign permissions at namespace level where possible, to avoid wildcard permissions (a wildcard also covers object types created in the future), to avoid cluster-admin except where specifically needed, and not to give pods service accounts with powerful permissions. The lab answers the blast-radius question in four dimensions (files, environment, API permissions and network) and deliberately reads no secret: it asks the API what is allowed instead of trying it.
The kubelet and API server are settings to read
The kubelet documentation says that by default requests to the kubelet's HTTPS endpoint that are not rejected by another authentication method are treated as anonymous, with the username system:anonymous, and that anonymous access can be disabled so unauthenticated requests get a 401 response. It also says that the kubelet's own default authorization mode is AlwaysAllow, and that authorization can be delegated to the API server instead.
Distributions and installers can set these differently, which is exactly why the lab reads the real configuration file on a node and the API server's flags in its manifest instead of trusting the documentation's defaults, then proves one setting by changing it, testing it by status code from inside the cluster and putting it back.
Network policy: measure, apply, measure again
The Kubernetes network policy page says policies are implemented by a network plugin and that creating a NetworkPolicy without a controller that implements it has no effect. By default a pod is not isolated for ingress or egress, so all connections are allowed; a pod becomes isolated for a direction once a policy selects it for that direction, and the effects of several policies combine additively.
Together that means the policy file proves nothing. A matrix of which pod can reach which service, measured before and after, does. The lab writes the measuring script, tests the tester with a known-closed port, applies a default-deny rule plus one allow rule, and diffs the two matrices, which also exposes a policy that was accepted by the API but not enforced.
Dangerous workload settings, and a guardrail
The Pod Security Standards define three profiles: Privileged, an unrestricted policy that allows known privilege escalations; Baseline, a minimally restrictive policy that prevents known privilege escalations; and Restricted, a heavily restricted policy following current hardening practice. Pod Security Admission enforces them with three modes: enforce rejects a pod that violates the policy, audit adds an annotation to the audit log, and warn shows a warning to the user.
The workload lab exports every pod as JSON and writes a program that lists risky settings cluster-wide, scored against your register of weaknesses, then separates real findings from the expected privileges of system components. The capstone fixes them in order of risk, adds a guardrail that rejects a weak pod, tries to bring a weak pod back to prove it, and writes a retest note with what is fixed, accepted and open.
Key points
- Ask the blast-radius question: what can one pod see and reach, in files, environment, API permissions and network.
- Pods receive their service account's credentials by default; RBAC decides what they can do; avoid wildcards and cluster-admin.
- Read the real kubelet and API server settings; defaults in documentation are not what your cluster runs.
- A network policy file proves nothing: measure reachability before and after, and test the tester.
Sources
- kind: Kubernetes in Docker (project home)
- Kubernetes documentation: Service Accounts
- Kubernetes documentation: Role Based Access Control good practices
- Kubernetes documentation: Kubelet authentication and authorization
- Kubernetes documentation: Network Policies
- Kubernetes documentation: Pod Security Standards
- Kubernetes documentation: Pod Security Admission
Lecture
Container and Kubernetes security basics: The controls this unit measures: least-privilege container settings, RBAC, network policies and Pod Security Standards.
Practice in the labs
Build your practice cluster, then assess it from inside a pod, from its node settings, from its network and from its workload definitions. The capstone fixes it.
- Install kubectl and kind, and bring up a local Kubernetes cluster you can break: You install kubectl and kind, bring up a local cluster, check your own permissions and delete it again. Skip it if you already have a working kind cluster.
- Build a deliberately weak kind cluster (on YOUR machine) to assess for the rest of the series: You build one cluster with nine documented misconfigurations and a register that names each one, the subject of every later lab.
- Assess what one pod can see and reach in YOUR OWN kind cluster, then close it: You write a blast-radius statement for one pod in four dimensions, without reading any secret.
- Audit the kubelet and API server settings of YOUR OWN kind cluster by hand: You read kubelet and API server settings where they live on a node, test the kubelet port from inside the cluster, and prove one setting by changing it and restoring it.
- Build a pod reachability matrix in YOUR OWN kind cluster and diff it after default-deny: You measure pod to service reachability with your own script, apply default-deny, and diff the before and after matrices.
- Find dangerous workload settings across YOUR OWN cluster with kubectl and jq: You write a jq program that lists risky workload settings across the cluster, score it against your register and explain what it misses.
Knowledge check
- You apply a NetworkPolicy but the cluster has no network plugin that enforces policies. What happens? Answer: Nothing: a NetworkPolicy without a controller that implements it has no effect. The documentation says policies are implemented by the network plugin, which is why a measured before-and-after matrix beats trusting the policy file.
- Why does the blast-radius lab ask the API what is allowed instead of reading secrets? Answer: An access review answers the question without touching sensitive data, which keeps the test inside its rules. The assessment is about what a credential could do, and you can learn that without reading what it protects.
- What does the Restricted Pod Security Standard represent? Answer: A heavily restricted policy following current pod hardening practice. The standards define Privileged as unrestricted, Baseline as minimally restrictive and Restricted as heavily restricted.
- Why should you read a node's real kubelet configuration instead of relying on the documentation's defaults? Answer: Installers and distributions can set the values differently from the kubelet's own defaults. The documentation describes the defaults of the component; your cluster may override them, so the finding is what your cluster actually does.
Back to the syllabus or see all classes.
Related
- Active Directory, cloud and cluster assessment
- Install kubectl and kind, and bring up a local Kubernetes cluster you can break
- Build a deliberately weak kind cluster (on YOUR machine) to assess for the rest of the series
- Assess what one pod can see and reach in YOUR OWN kind cluster, then close it
- Audit the kubelet and API server settings of YOUR OWN kind cluster by hand
- Build a pod reachability matrix in YOUR OWN kind cluster and diff it after default-deny
- Find dangerous workload settings across YOUR OWN cluster with kubectl and jq
- All classes
- Free cyber labs