In this lesson, you will learn how to harden the Kubernetes API server and etcd to protect your cluster's management layer from unauthorized access.
The control plane is the "brain" of your cluster. If an attacker gains control over the API server or the etcd database where state is stored, they own the entire environment. Hardening these components starts by minimizing their exposure and enforcing strict identity verification.
Securing the API Server
The API server is the primary entry point for all administrative tasks. To harden it, you must ensure it is not accessible from the public internet. Furthermore, you should enable Auditing. By configuring an audit policy file, you create a trail of every request made to the API server, which is critical for detecting malicious activity.
You configure these settings in the API server manifest file (usually located at /etc/kubernetes/manifests/kube-apiserver.yaml):
spec:
containers:
- name: kube-apiserver
command:
- kube-apiserver
- --audit-policy-file=/etc/kubernetes/audit-policy.yaml
- --audit-log-path=/var/log/kubernetes/audit.log
- --anonymous-auth=false
Setting --anonymous-auth=false ensures that no request is processed unless it carries valid credentials, preventing unauthenticated probes.
Protecting etcd
etcd stores the entire state of your cluster. Because it does not natively verify the identity of the API server by default, you must enforce Mutual TLS (mTLS). By requiring both the API server and etcd to present valid certificates signed by a private Certificate Authority (CA), you ensure that only the legitimate API server can read or write cluster data.
When configuring your etcd startup flags, you must point to the authorized certificates:
--cert-file=/etc/kubernetes/pki/etcd/server.crt
--key-file=/etc/kubernetes/pki/etcd/server.key
--trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt
--client-cert-auth=true
By enabling --client-cert-auth=true, you instruct etcd to reject any connection that does not provide a certificate signed by your trusted CA. This prevents unauthorized nodes or users from interacting with your state store directly, even if they gain network access to the port.
Key Takeaway: Hardening the control plane requires disabling anonymous access to the API server and enforcing mutual TLS for all communications with the etcd database.