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

Sources

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.

Knowledge check

  1. 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.
  2. 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.
  3. 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.
  4. 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