Created on 2026-11-28


Kubernetes Hardening L2: Immutable Node OS, Kubelet Boundaries, and Host Firewalls

TL;DR: Every container in a standard Kubernetes pod shares the host Linux kernel, and the kubelet agent on each node holds credentials capable of reading secrets and reporting node state. If you run Kubernetes on a mutable general-purpose OS with an open SSH daemon, package managers, and a permissive kubelet configuration, a single container escape or lateral network hop hands the attacker permanent node root. Hardening Layer 2 means replacing general-purpose distros with immutable, API-driven container OSs (Bottlerocket or COS on cloud; Talos Linux or Flatcar Container Linux [CNCF Incubating] on bare metal), enforcing strict KubeletConfiguration boundaries, locking down kernel sysctl parameters, and deploying a Cilium (CNCF Graduated) eBPF Host Firewall.

The Premise: A Kubernetes Node Is an Appliance, Not a Pet Server

Historically, teams built Kubernetes nodes the same way they built legacy VM fleets: start with Ubuntu Server or RHEL, install openssh-server, distribute SSH keys or an Ansible service account, install containerd and kubelet via apt or dnf, and patch in place.

In a containerized environment, that model creates three high-severity failure modes:

  1. Living-off-the-land post-exploitation: When an attacker escapes a container onto a standard Ubuntu or RHEL node, they find /bin/bash, curl, python3, apt, gcc, systemd, and a writable /etc. Installing a persistent rootkit or harvesting credentials takes seconds.
  2. Configuration drift: In-place package upgrades and emergency ssh hotfixes mean no two nodes in a 100-node cluster have the exact same kernel modules or sysctl state.
  3. Exposed node daemons: By default on unhardened bootstrap setups, the kubelet HTTPS API (10250) may accept anonymous requests or use self-signed serving certificates, and host ports sit unprotected from compromised pods running with hostNetwork: true or flat underlay routes.

Managed (EKS / GKE / AKS) vs. Self-Hosted Bare Metal

Cloud providers now offer purpose-built, read-only container OS images and automated node-replacement lifecycles. On bare metal, you select and lifecycle-manage the OS image, kernel parameters, kubelet flags, and host-level firewall yourself.

Security Dimension AWS EKS Google GKE Azure AKS Self-Hosted Bare Metal
Immutable / Purpose-Built OS Bottlerocket (read-only rootfs, dm-verity, API-driven, no host SSH) or AL2023 Container-Optimized OS (COS) (locked-down rootfs, dm-verity, stateless /etc) Azure Linux (minimal container host) Talos Linux (SquashFS root in RAM via signed UKI, zero SSH/shell, mTLS gRPC API) or Flatcar Container Linux (immutable /usr, atomic A/B swaps)
Max Node Lifetime / Auto-Rotation EKS Auto Mode rotates nodes automatically at <= 21 days; Karpenter (disruption.budgets + expireAfter) GKE Autopilot manages node rotation and auto-repair transparently Node Image Auto-Upgrade + Automatic OS image channels You own it: Cluster API (CAPI) + Metal3 (CNCF Incubating) or Sidero Omni rolling A/B image upgrades
Kubelet Config (10250) Pre-hardened (anonymousAuth: false, Webhook authz) on managed AMIs Pre-hardened by GKE Pre-hardened by AKS You own it: Must explicitly configure KubeletConfiguration + CSR approval controller
Host Firewall VPC Security Groups + Network ACLs VPC Firewall Rules Network Security Groups (NSGs) Cilium Host Firewall (hostFirewall.enabled: true + nodeSelector CCNPs) or host nftables
Rootless Kubelet (Beta 1.37) Managed by provider rollout Managed by provider rollout Managed by provider rollout You own it: Configurable via KubeletInUserNamespace feature gate (Beta in K8s 1.37)

Ephemeral Node Rotation on Managed Clouds

One of the strongest security properties of modern managed Kubernetes is short maximum node lifetime. In EKS Auto Mode, compute nodes have a hard maximum lifetime of 21 days - nodes are automatically cordoned, drained, and replaced with fresh immutable instances before drift or unpatched kernel CVEs can accumulate.

If you run standard EKS with Karpenter (a Kubernetes SIG Autoscaling subproject), enforce the same ephemeral rotation policy declaratively in your NodePool using expireAfter and disruption.budgets:

apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
  name: hardened-bottlerocket
spec:
  disruption:
    consolidationPolicy: WhenEmptyOrUnderutilized
    consolidateAfter: 5m
    budgets:
      - nodes: "10%"
  template:
    spec:
      nodeClassRef:
        group: karpenter.k8s.aws
        kind: EC2NodeClass
        name: bottlerocket-encrypted
      # Force every node to be replaced with a fresh image at least every 14 days
      expireAfter: 336h
      requirements:
        - key: kubernetes.io/arch
          operator: In
          values: ["amd64", "arm64"]
        - key: karpenter.sh/capacity-type
          operator: In
          values: ["on-demand"]
---
apiVersion: karpenter.k8s.aws/v1
kind: EC2NodeClass
metadata:
  name: bottlerocket-encrypted
spec:
  role: "KarpenterNodeRole-prod-eks"
  subnetSelectorTerms:
    - tags:
        karpenter.sh/discovery: "prod-eks"
        tier: "private"
  securityGroupSelectorTerms:
    - tags:
        karpenter.sh/discovery: "prod-eks"
  amiSelectorTerms:
    # Pin to your cluster's validated Bottlerocket release tag and bump via GitOps
    - alias: [email protected]
  # Enforce IMDSv2 with hopLimit 1 so pods cannot steal the node IAM role
  metadataOptions:
    httpEndpoint: enabled
    httpProtocolIPv6: disabled
    httpPutResponseHopLimit: 1
    httpTokens: required
  blockDeviceMappings:
    - deviceName: /dev/xvda
      ebs:
        volumeSize: 4Gi
        volumeType: gp3
        encrypted: true
    - deviceName: /dev/xvdb
      ebs:
        volumeSize: 50Gi
        volumeType: gp3
        encrypted: true

Bare Metal Deep Dive: Immutable Container OSs

On bare metal, the two premier open-source choices for an immutable node OS are Talos Linux and Flatcar Container Linux.

Mutable vs Immutable Container OS Layout

Why Talos Linux Eliminates Entire Classes of Node Attacks

Talos Linux takes the appliance philosophy to its logical conclusion:

  • No SSH daemon, no shell (/bin/sh or /bin/bash do not exist), no package manager, and no init system (systemd is replaced by a minimal Go daemon, machined).
  • The entire root filesystem is a read-only SquashFS image mounted in RAM and integrity-verified at boot as part of a signed Unified Kernel Image (UKI) and initramfs validated by UEFI Secure Boot (unlike Bottlerocket and Google COS, which verify disk-backed root partitions block-by-block with dm-verity).
  • Only two persistent partitions are writable on disk - STATE (mounted at /system/state for machine configuration and PKI) and EPHEMERAL (mounted at /var for container images, kubelet state, and etcd data) - both encrypted with LUKS2 + TPM 2.0 as shown in Layer 0. Paths such as /etc/kubernetes live in an ephemeral in-memory tmpfs rebuilt at boot from the signed machine configuration.
  • All node inspection (dmesg, packet captures, process lists, log streaming) and lifecycle actions (upgrades, reboots, etcd snapshots) occur through apid, a mutually authenticated (mTLS) gRPC API on port 50000 governed by RBAC roles (os:admin, os:reader).

If an attacker triggers a kernel vulnerability and escapes a container onto a Talos host, there is no /bin/sh to execve(), no curl or wget binary to pull a second-stage payload, and nowhere on / or /usr to write a persistent binary.

When You Need Flatcar Container Linux

If your bare-metal environment requires legacy storage agents, third-party hardware monitoring binaries, or custom systemd units that cannot run inside privileged DaemonSet containers, Flatcar Container Linux is the right choice:

  • Ships an immutable, read-only /usr partition updated atomically via A/B partition swaps using Nebraska update servers.
  • Configured entirely at first boot via declarative Butane / Ignition JSON - no post-boot Ansible playbooks required.

Hardening the Kubelet Boundary (10250) and Kernel Sysctls

The kubelet is the most privileged daemon on a worker node. It exposes an HTTPS API on port 10250 that allows executing commands in containers (/exec), streaming logs (/containerLogs), and querying metrics. Historically, misconfigured kubelets (allowing anonymous authentication or exposing the unauthenticated read-only port 10255) have been responsible for massive cryptocurrency-mining and cluster-takeover campaigns.

Kubelet Hardening and Host Firewall Boundaries

Production KubeletConfiguration

Whether you deploy via kubeadm or Cluster API (passing this KubeletConfiguration directly), or via Talos Linux (declaring these same fields under machine.kubelet.extraConfig), every production node must enforce the following KubeletConfiguration:

apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
# 1. Never allow unauthenticated requests to 10250
authentication:
  anonymous:
    enabled: false
  webhook:
    enabled: true
    cacheTTL: 2m0s
  x509:
    clientCAFile: /etc/kubernetes/pki/ca.crt

# 2. Delegate all authorization decisions to kube-apiserver via SubjectAccessReview
authorization:
  mode: Webhook
  webhook:
    cacheAuthorizedTTL: 5m0s
    cacheUnauthorizedTTL: 30s

# 3. Completely disable the legacy unauthenticated read-only port (10255)
readOnlyPort: 0

# 4. Enforce automatic client & serving certificate rotation via CSR API
rotateCertificates: true
serverTLSBootstrap: true
# Enforce TLS 1.3. Do NOT set tlsCipherSuites when tlsMinVersion is VersionTLS13:
# Go's crypto/tls hardcodes TLS 1.3 AEAD suites and flag.TLSCipherSuites() rejects
# TLS 1.3 cipher names, causing kubelet startup to fail. (If TLS 1.2 clients are
# required, use VersionTLS12 with ECDHE-GCM/CHACHA20 suites instead.)
tlsMinVersion: VersionTLS13

# 5. Refuse to start if host kernel sysctls do not match hardened defaults
protectKernelDefaults: true

# 6. Apply seccomp RuntimeDefault profile to EVERY pod unless overridden
seccompDefault: true

# 7. Bound pod PID usage to prevent fork-bomb DoS against the host kernel
podPidsLimit: 4096
eventRecordQPS: 50
makeIPTablesUtilChains: true
cgroupDriver: systemd

# 8. Protect kubelet, containerd, and CNI from node memory/CPU starvation
systemReserved:
  cpu: "500m"
  memory: "1Gi"
  ephemeral-storage: "2Gi"
kubeReserved:
  cpu: "500m"
  memory: "1536Mi"
  ephemeral-storage: "2Gi"
evictionHard:
  memory.available: "500Mi"
  nodefs.available: "10%"
  nodefs.inodesFree: "5%"
  imagefs.available: "15%"
imageGCHighThresholdPercent: 80
imageGCLowThresholdPercent: 65

Kubelet Serving Certificate Rotation (serverTLSBootstrap: true)

By default in kubeadm, the kubelet generates a self-signed serving certificate for port 10250. Because that certificate is not signed by the cluster CA, metrics-server either fails TLS verification or forces operators to pass --kubelet-insecure-tls (disabling certificate verification and introducing a MITM vulnerability). Meanwhile, kube-apiserver (when running kubectl exec or kubectl logs) only verifies the kubelet's serving certificate when --kubelet-certificate-authority=/etc/kubernetes/pki/ca.crt is configured - without it, API-server-to-kubelet connections skip serving certificate validation completely.

Setting serverTLSBootstrap: true instructs kubelet to request a serving certificate from kube-apiserver using the kubernetes.io/kubelet-serving signer. Crucial operational step: Kubernetes does not auto-approve kubelet-serving CSRs in kube-controller-manager by default because a compromised node could request a serving cert for another node's IP. Deploy kubelet-csr-approver (or kubelet-serving-cert-approver) to cryptographically validate that the CSR's Subject Alternative Names (IPs and DNS names) match the requesting Node's actual registered status before approving.

Rootless Kubelet (Beta in Kubernetes 1.37)

Traditionally, kubelet and the container runtime (containerd / CRI-O [CNCF Graduated]) run as host UID 0. In Kubernetes 1.37, KubeletInUserNamespace (Rootless Kubelet) reached Beta. Running kubelet and the CRI runtime inside an unprivileged user namespace ensures that even a direct exploit against the kubelet binary or a container runtime shim executes as an unprivileged UID on the underlying host kernel. Evaluate it on non-privileged worker pools that do not require host-level block storage mounts.

Hardening Kernel sysctl Parameters

Because containers share the host kernel, unprivileged pods can exploit permissive kernel interfaces - most notably unprivileged eBPF (bpf() syscall) and kernel pointer leaks in /proc. Enforce these host sysctls in your Talos machine config or /etc/sysctl.d/99-k8s-hardening.conf:

# Talos machine configuration: Hardened kernel sysctls and module lockdown
machine:
  sysctls:
    # Block unprivileged processes/containers from loading eBPF programs (stops major kernel CVEs)
    kernel.unprivileged_bpf_disabled: "1"
    # Harden the BPF JIT compiler against spraying attacks
    net.core.bpf_jit_harden: "2"
    # Hide kernel symbol addresses in /proc/kallsyms from container processes
    kernel.kptr_restrict: "2"
    # Restrict dmesg kernel ring buffer access to root
    kernel.dmesg_restrict: "1"
    # Prevent ptrace process inspection across processes
    kernel.yama.ptrace_scope: "2"
    # Protect against symlink/hardlink TOCTOU privilege escalation in world-writable dirs
    fs.protected_symlinks: "1"
    fs.protected_hardlinks: "1"
    fs.protected_fifos: "2"
    fs.protected_regular: "2"
    # All six sysctls required when protectKernelDefaults: true is set in KubeletConfiguration
    vm.overcommit_memory: "1"
    vm.panic_on_oom: "0"
    kernel.panic: "10"
    kernel.panic_on_oops: "1"
    kernel.keys.root_maxkeys: "1000000"
    kernel.keys.root_maxbytes: "25000000"
  kernel:
    modules: []

Bare-Metal Host Protection: Cilium Host Firewall

On AWS, GCP, or Azure, VPC Security Groups filter traffic hitting the node's network interface before it reaches the OS. On bare metal, traffic arriving on the VLAN hits your node's eth0/bond0 directly. Standard Kubernetes NetworkPolicy resources only filter traffic entering or leaving pods (endpointSelector) - they do nothing to protect host-network daemons like kubelet (10250), etcd (2379-2380), Talos apid (50000), or NodePort services (30000-32767).

Cilium solves this natively in eBPF via its Host Firewall (hostFirewall.enabled: true). When enabled, Cilium attaches eBPF programs directly to the host's native VLAN interfaces (bond0.30, bond0.40, and bond0.50 on workers; plus bond0.20 on control-plane nodes per Layer 1) and enforces CiliumClusterwideNetworkPolicy (CCNP) rules that use a nodeSelector instead of an endpointSelector.

Step 1: Enable Cilium Host Firewall in Helm Values (Audit Rollout)

On a greenfield cluster, enable policyAuditMode: true while validating your initial host policies. On an already-enforcing cluster, do not toggle policyAuditMode: true globally in Helm (that disables pod NetworkPolicy enforcement cluster-wide); instead, scope policy-audit-mode: "true" to a canary node pool via CiliumNodeConfig:

# cilium-values-host-firewall.yaml (greenfield initial audit rollout)
kubeProxyReplacement: true
hostFirewall:
  enabled: true
# Start in audit mode on a greenfield cluster so Hubble logs AUDIT verdicts
# before switching to enforcement (use CiliumNodeConfig per node on live clusters).
policyAuditMode: true
# Worker node VLAN interfaces (per Layer 1, workers do NOT carry VLAN 20).
# Add bond0.20 on control-plane nodes via a control-plane CiliumNodeConfig override.
devices:
  - bond0.30
  - bond0.40
  - bond0.50

Step 2: Author a Worker Host Firewall Policy

Warning: A typo in a nodeSelector CCNP will immediately sever kubelet, BGP, and apid communication, locking you out of every node in the cluster. Always validate host policies in audit mode first, inspect AUDIT verdicts in Hubble, and explicitly allow kube-apiserver, remote-node, health, ToR BGP peers, and storage VLAN traffic before enforcing.

apiVersion: cilium.io/v2
kind: CiliumClusterwideNetworkPolicy
metadata:
  name: host-firewall-worker-nodes
spec:
  description: "Lock down bare-metal worker host ports (10250, 50000, BGP, Hubble, WireGuard, storage)"
  nodeSelector:
    matchExpressions:
      - key: node-role.kubernetes.io/control-plane
        operator: DoesNotExist
  ingress:
    # 1. Always allow control plane, remote nodes (CNI/Hubble), and local health probes
    - fromEntities:
        - kube-apiserver
        - remote-node
        - health
      toPorts:
        - ports:
            - port: "10250"   # Kubelet HTTPS API
              protocol: TCP
            - port: "4240"    # Cilium health check
              protocol: TCP
            - port: "4244"    # Hubble peer / relay
              protocol: TCP
            - port: "51871"   # Cilium WireGuard tunnel
              protocol: UDP
            - port: "8472"    # Cilium VXLAN (if overlay mode used)
              protocol: UDP
    # 2. Allow inbound BGP sessions from Top-of-Rack leaf switches on VLAN 40 (matches Layer 1)
    - fromCIDR:
        - 10.40.0.1/32
        - 10.40.0.2/32
      toPorts:
        - ports:
            - port: "179"     # BGP peering
              protocol: TCP
    # 3. Allow Talos apid (50000) ONLY from the dedicated Zero-Trust Management Proxy CIDR
    # (10.30.0.128/28 stays clear of Layer 1 API VIP 10.30.0.10 and CP nodes 10.30.0.11-.13)
    - fromCIDR:
        - 10.30.0.128/28
      toPorts:
        - ports:
            - port: "50000"
              protocol: TCP
    # 4. Allow Rook-Ceph / host storage traffic on the dedicated Storage VLAN (VLAN 50)
    - fromCIDR:
        - 10.50.0.0/24
      toPorts:
        - ports:
            - port: "3300"    # Ceph Monitor v2
              protocol: TCP
            - port: "6789"    # Ceph Monitor v1
              protocol: TCP
            - port: "6800"    # Ceph OSD / MDS / MGR range
              endPort: 7300
              protocol: TCP
    # 5. Allow ICMP echo and fragmentation-needed within the underlay
    - icmps:
        - fields:
            - type: 8
              family: IPv4
            - type: 3
              family: IPv4

Step 3: Validate in Hubble Before Enforcing

Before applying a host firewall policy in enforcement mode on a live bare-metal cluster, watch Hubble flows for AUDIT verdicts targeting the reserved:host label:

# Watch Hubble for any traffic to the host endpoint that WOULD be dropped by policy
hubble observe --label reserved:host --verdict AUDIT --follow

Only after confirming zero unexpected AUDIT verdicts on 10250, 6443, 2379, 179, 4240, 4244, 50000, and your storage VLAN ports across a full reconciliation window should you switch the policy to full enforcement.


Common Failure Modes & Operational Pitfalls

1. Kubelet Refusing to Start Due to protectKernelDefaults: true

What happens: You set protectKernelDefaults: true in KubeletConfiguration to pass a CIS Benchmark scan (kube-bench), restart kubelet, and it immediately crash-loops with: InvalidKernelConfig: [InvalidKernelConfig: vm.overcommit_memory: Invalid value: 0: must be 1, InvalidKernelConfig: kernel.panic: Invalid value: 0: must be 10].

How to avoid it: When protectKernelDefaults: true is false, kubelet silently mutates host kernel sysctl parameters at startup. When set to true, kubelet refuses to mutate the kernel and aborts if the OS has not already set vm.overcommit_memory=1, vm.panic_on_oom=0, kernel.panic=10, kernel.panic_on_oops=1, kernel.keys.root_maxkeys=1000000, and kernel.keys.root_maxbytes=25000000. Always bake all six parameters into your immutable OS configuration before enabling protectKernelDefaults: true.

2. Breaking kubectl logs and metrics-server with serverTLSBootstrap: true

What happens: You enable serverTLSBootstrap: true in KubeletConfiguration so kubelets stop using untrusted self-signed serving certs. Suddenly kubectl logs, kubectl exec, and Horizontal Pod Autoscalers (metrics-server) fail across the cluster with tls: failed to verify certificate: x509: certificate signed by unknown authority.

How to avoid it: Enabling serverTLSBootstrap: true creates a CertificateSigningRequest (CSR), which remains in Pending status forever until approved. Deploy kubelet-csr-approver (or kubelet-serving-cert-approver) as part of your core bootstrap manifest and ensure kube-apiserver is configured with --kubelet-certificate-authority=/etc/kubernetes/pki/ca.crt.

3. Host Firewall Blocking BGP or VRRP Heartbeats

What happens: You enable Cilium's Host Firewall on bare metal and allow TCP 6443, 10250, and 2379, but forget to allow TCP port 179 (BGP to your Top-of-Rack switches) or IP Protocol 112 (VRRP for keepalived on control-plane nodes). Every BGP session times out after holdTimeSeconds (9s), and the cluster loses all external connectivity.

How to avoid it: Explicitly include your ToR switch peer IPs (10.40.0.1/32, 10.40.0.2/32) on TCP port 179 in your nodeSelector CCNP (and include egress to TCP 179 if you also author host egress policies). On control-plane nodes running keepalived or VRRP, also permit IP Protocol 112 between control-plane peers on VLAN 30.


Summary Checklist

Before moving up to Layer 3 (Control Plane & etcd Hardening), verify your Layer 2 node posture:

  • Immutable Node OS: General-purpose mutable distros replaced with Talos Linux or Flatcar Container Linux on bare metal, and Bottlerocket / COS / Azure Linux on managed clouds.
  • Automated Node Rotation: Maximum node lifetime enforced (<= 21 days via EKS Auto Mode, Karpenter expireAfter + disruption.budgets, or Cluster API rolling replacements).
  • Hardened KubeletConfiguration: anonymous.enabled: false, authorization.mode: Webhook, readOnlyPort: 0, tlsMinVersion: VersionTLS13 (without conflicting tlsCipherSuites), protectKernelDefaults: true, seccompDefault: true, and serverTLSBootstrap: true with kubelet-csr-approver.
  • Kernel Sysctls Locked: kernel.unprivileged_bpf_disabled=1, net.core.bpf_jit_harden=2, kernel.kptr_restrict=2, fs.protected_symlinks=1, and all six protectKernelDefaults sysctls enforced at boot.
  • Host Firewall Active: Cilium Host Firewall (hostFirewall.enabled: true) with nodeSelector CCNPs restricting ingress to 10250, 179, 4240, 4244, 50000, and storage VLAN ports.

Day-1 Verification & Operational Runbook

Run these verification checks after rolling out Layer 2 controls on a cluster:

# 1. Verify kubelet anonymous auth is rejected (must return 401, or drop at the Cilium Host Firewall)
curl -k -s -o /dev/null -w "%{http_code}\n" https://<node-ip>:10250/pods

# 2. Confirm legacy unauthenticated read-only port 10255 is closed
nc -zv -w 3 <node-ip> 10255

# 3. Verify hardened kernel sysctls on Talos nodes (must return 1)
talosctl read /proc/sys/kernel/unprivileged_bpf_disabled -n <node-ip>

# 4. Confirm zero stuck kubelet-serving CSRs after enabling serverTLSBootstrap
kubectl get csr -o custom-columns=NAME:.metadata.name,SIGNER:.spec.signerName,STATUS:.status.conditions[0].type

# 5. Observe host-endpoint audit verdicts before switching a new CCNP to enforcement
hubble observe --label reserved:host --verdict AUDIT --follow

Key Day-2 operational practices:

  • Canary Host Firewall changes per node: Never flip cluster-wide policyAuditMode: true on a live enforcing cluster (which disables pod NetworkPolicies). Validate new nodeSelector CCNPs on a canary node via CiliumNodeConfig and verify zero unexpected AUDIT drops for BGP (179), kubelet (10250), Hubble (4244), apid (50000), and storage (VLAN 50) before rolling out cluster-wide.
  • Patch by node replacement, not in-place updates: Rely on scheduled rotation (expireAfter: 336h in Karpenter or staged A/B image upgrades on Talos/Flatcar) to drain kernel CVEs and eliminate drift. Immutable read-only root images paired with boot-time integrity checks also provide a strong compensating control alongside host file-integrity requirements without maintaining legacy host agents.
  • Monitor kubelet-csr-approver before node scale-ups: Alert on any kubernetes.io/kubelet-serving CSR stuck in Pending for more than 2 minutes so newly scaled nodes never break kubectl logs or metrics-server scrapes.

Series Navigation