TExcelTAD
Home › Cloud & Container Security › The Kubernetes Attack Surface: API Server, kubelet and etcd

The Kubernetes Attack Surface: API Server, kubelet and etcd

A Kubernetes cluster is a distributed system whose components talk to each other over the network, and each of those conversations is an attack surface. The API server is the front door for people, pipelines and controllers; the kubelet on every node runs whatever the API server tells it to and has its own API; etcd stores the whole cluster state, Secrets included. Exposed or weakly authenticated components have led to some of the most common cluster compromises seen in the wild: dashboards and API servers answering anonymous requests, kubelets accepting commands from anyone who can reach port 10250, and etcd reachable without client certificates. This lesson maps those surfaces and checks a cluster's configuration against them; the following lessons go inside the API (RBAC, pod security, network policy, admission). Kubernetes Architecture explains the components themselves.

The map

users, CI,attackers kube-apiserver :6443authn, authz, admission etcd :2379all state, Secrets worker node kubelet :10250(:10255 read-only, old) podsSA token mounted NodePort 30000-32767kube-proxy, CNI exec, logs,run pods in-cluster API calls IMDS 169.254.169.254 (node identity) is reachable from here unless blocked
Component Port What an attacker wants from it Must-have settings
API server 6443 (443 on managed services) anything RBAC allows: Secrets, pods/exec, creating privileged pods --anonymous-auth=false or anonymous bound to nothing; --authorization-mode=Node,RBAC; audit logging; private endpoint or authorized networks
kubelet 10250 (HTTPS), 10255 (read-only HTTP, legacy) exec/run in any pod on the node, pod specs with env secrets authentication.anonymous.enabled: false, authentication.webhook.enabled: true, authorization.mode: Webhook, readOnlyPort: 0
etcd 2379 client, 2380 peer a full copy of cluster state, all Secrets client certificate auth (--client-cert-auth=true), TLS for peers, reachable only from the control plane, encryption at rest for Secrets via the API server's EncryptionConfiguration
Service account tokens (inside every pod by default) an identity in the API from any compromised pod automountServiceAccountToken: false where unused; short-lived projected tokens (mounted by default since 1.22; since 1.24 no long-lived token Secrets are created automatically)
Dashboards, metrics, NodePorts various admin UIs, information disclosure, unauthenticated apps no public dashboards; NodePorts closed at the cloud firewall

On managed clusters (EKS, AKS, GKE) the provider runs the API server and etcd, so etcd exposure and most API server flags are theirs; the endpoint's network exposure, authentication integration, RBAC, the nodes' kubelets and everything inside are yours (Shared Responsibility).

Checking a cluster's configuration

The program reads the relevant flags of a self-managed lab cluster (as you would collect them from the control-plane manifests and the kubelet config file) and checks them against the table, in the style of the CIS Kubernetes Benchmark's control-plane and node sections.

python · try it yourself
import yaml

apiserver_flags = ["--anonymous-auth=true", "--authorization-mode=AlwaysAllow", "--audit-log-path=",
                   "--encryption-provider-config=", "--profiling=true", "--tls-min-version=VersionTLS12"]
etcd_flags = ["--client-cert-auth=true", "--peer-client-cert-auth=true", "--listen-client-urls=https://0.0.0.0:2379"]
kubelet_config = yaml.safe_load("""
authentication:
  anonymous: {enabled: true}
  webhook: {enabled: false}
authorization: {mode: AlwaysAllow}
readOnlyPort: 10255
protectKernelDefaults: false
rotateCertificates: true
""")
endpoint = {"public": True, "authorized_networks": []}

def flags(lst):
    return dict(f.lstrip("-").split("=", 1) for f in lst)

api, etcd = flags(apiserver_flags), flags(etcd_flags)
checks = [
    ("API", "anonymous requests disabled", api.get("anonymous-auth") == "false"),
    ("API", "authorization includes Node and RBAC", set(api.get("authorization-mode", "").split(",")) >= {"Node", "RBAC"}),
    ("API", "audit log enabled", bool(api.get("audit-log-path"))),
    ("API", "Secrets encrypted at rest (encryption provider config)", bool(api.get("encryption-provider-config"))),
    ("API", "profiling disabled", api.get("profiling") == "false"),
    ("API", "endpoint private or limited to authorized networks", not endpoint["public"] or bool(endpoint["authorized_networks"])),
    ("etcd", "client certificate authentication", etcd.get("client-cert-auth") == "true"),
    ("etcd", "peer certificate authentication", etcd.get("peer-client-cert-auth") == "true"),
    ("etcd", "listens only on control-plane addresses", "0.0.0.0" not in etcd.get("listen-client-urls", "")),
    ("kubelet", "anonymous auth disabled", kubelet_config["authentication"]["anonymous"]["enabled"] is False),
    ("kubelet", "webhook authentication", kubelet_config["authentication"]["webhook"]["enabled"] is True),
    ("kubelet", "webhook authorization (not AlwaysAllow)", kubelet_config["authorization"]["mode"] == "Webhook"),
    ("kubelet", "read-only port 10255 disabled", kubelet_config.get("readOnlyPort", 0) == 0),
    ("kubelet", "client certificate rotation", kubelet_config.get("rotateCertificates") is True),
]
failed = [c for c in checks if not c[2]]
for comp, text, ok in checks:
    print(f"{'PASS' if ok else 'FAIL'}  {comp:8} {text}")
print(f"\n{len(checks) - len(failed)}/{len(checks)} passed")
critical = {"anonymous requests disabled", "authorization includes Node and RBAC", "webhook authorization (not AlwaysAllow)",
            "anonymous auth disabled"}
print("fix first:", [f"{c[0]}: {c[1]}" for c in failed if c[1] in critical])
FAIL  API      anonymous requests disabled
FAIL  API      authorization includes Node and RBAC
FAIL  API      audit log enabled
FAIL  API      Secrets encrypted at rest (encryption provider config)
FAIL  API      profiling disabled
FAIL  API      endpoint private or limited to authorized networks
PASS  etcd     client certificate authentication
PASS  etcd     peer certificate authentication
FAIL  etcd     listens only on control-plane addresses
FAIL  kubelet  anonymous auth disabled
FAIL  kubelet  webhook authentication
FAIL  kubelet  webhook authorization (not AlwaysAllow)
FAIL  kubelet  read-only port 10255 disabled
PASS  kubelet  client certificate rotation

3/14 passed
fix first: ['API: anonymous requests disabled', 'API: authorization includes Node and RBAC', 'kubelet: anonymous auth disabled', 'kubelet: webhook authorization (not AlwaysAllow)']

This lab cluster fails almost everything that matters. The worst pair is AlwaysAllow authorization on the API server with anonymous requests enabled: every unauthenticated request is authorised, so the cluster belongs to anyone who can reach port 6443, and the endpoint is public. The kubelets repeat the mistake one level down: anonymous, AlwaysAllow, so anyone who reaches a node's port 10250 can run commands in its pods. Encryption at rest and audit logging are missing too, so Secrets sit in etcd unencrypted (the base64 you see in Secret manifests is an encoding of the API, not encryption) and nobody would see the abuse.

How exposure is detected

  • Configuration: the checks above, automated by kube-bench (which runs the CIS Kubernetes Benchmark checks on nodes and control plane) or the provider's CIS checks for managed clusters; Trivy's trivy k8s and Kubescape run similar checks against a live cluster.
  • Network: from outside, in scope only, check which of 6443, 10250, 10255, 2379 and NodePorts answer; cloud security groups and flow logs show who connects to them.
  • Audit logs: requests by system:anonymous, pods/exec from unexpected users, and kubelet API use show in API server audit logs and node logs (the last lesson of this section).

How it is fixed

  • API server: --anonymous-auth=false (or keep anonymous only for health endpoints with no RBAC bindings), --authorization-mode=Node,RBAC, audit policy and log, encryption configuration for Secrets (KMS provider preferred), private endpoint or authorized networks.
  • kubelet: anonymous off, webhook authentication and authorization, read-only port 0, certificate rotation, protectKernelDefaults: true.
  • etcd: client and peer TLS with certificate authentication, listening only on control-plane interfaces, firewall to the API servers only, encrypted backups.
  • On managed clusters: private API endpoints, provider IAM integration for humans, envelope encryption of Secrets with your KMS key (an option on EKS, AKS and GKE).

Pitfalls

  • Testing RBAC carefully and leaving AlwaysAllow in front of it: authorization modes are evaluated in order, and AlwaysAllow approves everything.
  • Fixing the API server and forgetting the kubelets, which have their own API with equally powerful operations.
  • Assuming a managed cluster's public endpoint is harmless because it needs authentication: credentials leak, and an endpoint restricted to known networks turns a leaked kubeconfig into a failed login.

Practice

1. Change the kubelet's authorization.mode to Webhook but leave anonymous enabled. What can an anonymous caller do now?

The kubelet asks the API server whether system:anonymous may perform the action (a SubjectAccessReview). With proper RBAC that is nothing, so requests are refused (403). Still disable anonymous: one careless ClusterRoleBinding to system:unauthenticated would reopen it.

2. Which three changes give the biggest reduction in risk for this cluster, in order?
  1. API server authorization Node,RBAC and anonymous off (the cluster stops being public property). 2. Kubelet webhook authn/authz and anonymous off (nodes stop accepting commands from anyone). 3. Restrict the API endpoint to authorized networks. Then audit logging and Secret encryption.
3. Why does it matter that etcd listens on 0.0.0.0 even with client certificate authentication on?

Certificate authentication protects it, but any bug, leaked client certificate or misissued certificate is then exploitable from every network that can route to it. Defence in depth: listen on the control-plane address and firewall it to the API servers.

Test yourself

What does --authorization-mode=AlwaysAllow on the API server mean?

  1. Only admins are allowed
  2. Every authenticated (and, with anonymous auth on, every anonymous) request is authorised
  3. RBAC is evaluated first
  4. Requests are logged

Why is the kubelet's port 10250 a target?

  1. It serves the dashboard
  2. Its API can run commands in pods and read pod specs on that node
  3. It stores etcd data
  4. It is the NodePort range

Without an encryption provider configured, how are Secrets stored in etcd?

  1. Encrypted with AES
  2. Unencrypted, readable by anyone with etcd access or an etcd backup
  3. Hashed
  4. Not at all

Which tool runs the CIS Kubernetes Benchmark checks on nodes?

  1. kube-bench
  2. kubectl diff
  3. helm lint
  4. etcdctl