> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Reducing the Attack Surface

> Guidance on minimizing host attack surface in Kubernetes clusters by removing unnecessary software and services, enforcing least privilege, restricting kernel modules, limiting access, and automating configuration and patching.

In this lesson we cover practical principles and steps to reduce the attack surface on hosts in your cluster. Keeping each system minimal, consistent, and up to date limits potential entry points an attacker can use. Even one poorly configured or unpatched node can compromise the broader cluster through lateral movement or privilege escalation.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/WWXuSSf_CvRt0mlY/images/Certified-Kubernetes-Security-Specialist-CKS/System-Hardening/Reducing-the-Attack-Surface/reducing-attack-surface-worker-attack-vector.jpg?fit=max&auto=format&n=WWXuSSf_CvRt0mlY&q=85&s=446041e7ae7934b117669de53e58c8a5" alt="A slide titled &#x22;Reducing the Attack Surface&#x22; showing a boxed cluster of nodes labeled controlplane and worker, with an attacker icon and arrow pointing at one worker node to illustrate an attack vector." width="1920" height="1080" data-path="images/Certified-Kubernetes-Security-Specialist-CKS/System-Hardening/Reducing-the-Attack-Surface/reducing-attack-surface-worker-attack-vector.jpg" />
</Frame>

If an attacker gains control of a single node, they may move east–west across the cluster or escalate privileges to affect other workloads. The most common contributors to an expanded attack surface include:

* Unnecessary services and open ports
* Outdated or unpatched software
* Excessive user or process privileges
* Unrestricted kernel modules or drivers

Apply the principle of least privilege and strive for simplicity and consistency to limit exposure.

<Callout icon="lightbulb" color="#1CB2FE">
  Minimizing installed software, disabling unused services, and enforcing least privilege are fundamental controls that reduce the number of potential vulnerabilities an attacker can exploit.
</Callout>

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/WWXuSSf_CvRt0mlY/images/Certified-Kubernetes-Security-Specialist-CKS/System-Hardening/Reducing-the-Attack-Surface/reducing-attack-surface-security-measures.jpg?fit=max&auto=format&n=WWXuSSf_CvRt0mlY&q=85&s=8b0c09ce076f556edb54696e871ef28f" alt="A presentation slide titled &#x22;Reducing the Attack Surface&#x22; listing security measures. It lists: use the least privilege principle, limit access, restrict obsolete kernel modules, remove obsolete software, and remove obsolete services." width="1920" height="1080" data-path="images/Certified-Kubernetes-Security-Specialist-CKS/System-Hardening/Reducing-the-Attack-Surface/reducing-attack-surface-security-measures.jpg" />
</Frame>

Below are the key measures shown on the slide, with actionable guidance and examples.

| Measure | Why it matters | How to implement (examples) |
| - | - | - |
| Use the principle of least privilege | Limits damage from compromised accounts or services | Implement RBAC with minimal roles; avoid using `cluster-admin` for routine tasks |
| Limit access | Reduces exposure of management interfaces and services | Enforce network policies, firewalls, and use bastion/jump hosts instead of exposing management ports |
| Restrict obsolete kernel modules | Prevents loading of unnecessary drivers or features that increase attack surface | Blacklist modules via `/etc/modprobe.d/` and rebuild initramfs if needed |
| Remove obsolete software | Fewer packages means fewer potential vulnerabilities | Audit installed packages and uninstall unnecessary applications |
| Disable unused services | Prevents unnecessary daemons from listening on ports | Use `systemd` to disable and stop services that are not required |

Use the following practical recommendations and examples for each area.

* Use the principle of least privilege
  * Grant users, services, and processes only the permissions they require.
  * Prefer narrowly-scoped RBAC roles and role bindings. Reserve `cluster-admin` for tightly controlled admin tasks.

* Limit access
  * Restrict traffic using Kubernetes NetworkPolicies, perimeter firewalls, and host-based firewalls (iptables/nftables).
  * Use bastion hosts or VPNs for management plane access instead of exposing ports to broad networks.

* Restrict obsolete kernel modules
  * Blacklist modules you do not need to prevent them from loading and increasing the kernel attack surface.

```bash theme={null}
# Example: blacklist the floppy module
echo "blacklist floppy" | sudo tee /etc/modprobe.d/blacklist-floppy.conf
sudo update-initramfs -u   # Debian/Ubuntu: rebuild initramfs if needed
```

* Remove obsolete software
  * Regularly audit installed packages and remove anything unnecessary to reduce the number of vulnerable components.

```bash theme={null}
# Debian/Ubuntu
apt list --installed

# RHEL/CentOS
rpm -qa
```

* Remove or disable obsolete services
  * Identify enabled services and disable those not required, which prevents them from running or listening on ports.

```bash theme={null}
# Check enabled services
systemctl list-unit-files --type=service --state=enabled

# Disable and stop an unnecessary service
sudo systemctl disable --now example.service
```

Additional practical controls to keep the attack surface small:

* Use automated configuration management (for example, Ansible) or immutable images so hosts are consistent and reproducible.
* Apply automated patching and vulnerability scanning for OS packages and container images.
* Enforce runtime restrictions to reduce syscall exposure:
  * seccomp: [https://www.kernel.org/doc/html/latest/userspace-api/seccomp\_filter.html](https://www.kernel.org/doc/html/latest/userspace-api/seccomp_filter.html)
  * AppArmor: [https://apparmor.net/](https://apparmor.net/)
  * SELinux: [https://selinuxproject.org/page/Main\_Page](https://selinuxproject.org/page/Main_Page)
* Regularly audit and monitor for configuration drift, unexpected services, or new network listeners.

References and further reading:

* [Kubernetes Documentation](https://kubernetes.io/docs/)
* [Ansible — Automation for configuration management](https://www.ansible.com/)
* [Seccomp filters documentation](https://www.kernel.org/doc/html/latest/userspace-api/seccomp_filter.html)
* [AppArmor project](https://apparmor.net/)
* [SELinux project](https://selinuxproject.org/page/Main_Page)

Next, we will examine each of these measures in more detail.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/certified-kubernetes-security-specialist-cks/module/d67be5ee-871d-4435-a187-382610cb6a1f/lesson/94eeca72-72da-416a-babf-60e20ec46471" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.