Deploying KubeArmor on Kubernetes: Enforce eBPF and LSM Runtime Security

Security tutorial - IT technology blog
Security tutorial - IT technology blog

The 2:14 AM Pager Call: When Static Scans Fail

It was 2:14 AM on a Sunday when PagerDuty woke me up. An alert flagged a critical anomaly in our production cluster: CPU utilization on an internal payment worker had pegged at 98%. Worse, the pod was flooding outbound traffic to an unknown host in Eastern Europe over port 3333.

I grabbed my laptop, opened a bastion session, and inspected the node. An attacker had chained a remote code execution vulnerability in an unpatched JSON parser to spawn a shell. Within three minutes, they fetched an xmrig crypto-miner into /tmp and ran it directly under the pod’s default service account.

Our CI/CD pipeline was not the problem here. Trivy and Grype scan every container image on merge, and our base images had zero high or critical CVEs at build time. But static scanning only catches known flaws in stored artifacts.

The moment a container goes live, static analysis is blind. Standard Kubernetes security context configurations still leave room for arbitrary binary execution and directory traversal. Network policies can restrict egress traffic, but they cannot stop a rogue process from dumping API secrets or executing payloads on disk. We needed inline runtime enforcement that chokes malicious system calls before they touch user space.

Core Concepts: How eBPF and LSM Block Threats in the Kernel

Most runtime monitors operate in user space. They tail audit logs, poll /proc, or hook processes using ptrace. That approach has two fatal flaws: evasion windows and brutal performance overhead—often taxing node CPU by 15% to 30%. KubeArmor solves this by anchoring enforcement directly inside the Linux kernel.

Understanding KubeArmor

KubeArmor is a CNCF-sandboxed runtime security engine. Unlike passive detection agents that only trigger alerts after files change, KubeArmor enforces restrictions inline. It protects workloads across three distinct boundaries:

  • Process Execution: Locks down binaries. You can permit Nginx to spawn worker processes while barring access to /bin/sh, /bin/bash, curl, or arbitrary staging scripts.
  • File System Access: Restricts read and write operations on critical assets, including service account tokens, private keys, and application configurations like /etc/nginx/conf.d/.
  • Network Capabilities: Denies untrusted processes from creating raw sockets or initiating unauthorized TCP/UDP connections.

LSM Enforcement vs. eBPF Visibility

To understand KubeArmor, you have to separate telemetry from enforcement. KubeArmor pairs extended Berkeley Packet Filter (eBPF) with Linux Security Modules (LSMs), such as AppArmor, SELinux, and BPF-LSM.

eBPF handles the telemetry pipeline with minimal overhead—typically under 1.5% CPU utilization. When a container triggers a system call like execve or openat, eBPF probes gather rich container context: pod labels, namespaces, and process trees. But eBPF tracing probes alone cannot block system calls on standard production kernels.

That blocking power comes from the LSM layer. If a call violates your policy, the LSM hook intercepts it and returns an immediate -EPERM (Operation not permitted) error. The kernel drops the operation instantly.

Hands-On Practice: Deploying KubeArmor and Locking Down Pods

Here is how to roll out KubeArmor on an active Kubernetes cluster (v1.26+) and configure inline protection for a production-style workload.

Step 1: Verify Kernel LSM Capabilities

First, verify which security modules are active across your worker pool. Kernel version 5.4 or later is recommended; kernels running 5.15+ LTS support BPF-LSM out of the box. Install the official karmor CLI tool:

# Install the karmor CLI tool to /usr/local/bin
curl -sfL https://raw.githubusercontent.com/kubearmor/kubeArmor/main/getting-started/karmor/install.sh | sudo sh -s -- -b /usr/local/bin

# Inspect security module readiness on each node
karmor probe

Review the output table. You should see AppArmor, SELinux, or BPF-LSM flagged as supported. Ubuntu 22.04 and Debian 12 nodes default to AppArmor, while RHEL and Rocky Linux nodes leverage SELinux.

Step 2: Install KubeArmor via DaemonSet

Deploy the KubeArmor operator, daemonsets, and custom resource definitions across your cluster:

# Deploy the controller and node daemonset
karmor install

# Confirm that pods are healthy across all nodes
kubectl get pods -n kubearmor -o wide

You should see one kubearmor-xxx pod running on each worker, alongside the kubearmor-controller deployment in charge of policy synchronization.

Step 3: Deploy an Unhardened Target Workload

Create an isolated namespace and deploy a basic Nginx service to test default cluster boundaries:

# Provision a test namespace
kubectl create namespace demo-secure

# Spin up an unhardened Nginx pod
kubectl create deployment nginx-target --image=nginx:1.25-alpine -n demo-secure
kubectl wait --for=condition=ready pod -l app=nginx-target -n demo-secure --timeout=60s

Test the default execution privileges inside this running pod:

# Run an interactive shell check inside the container
TARGET_POD=$(kubectl get pod -l app=nginx-target -n demo-secure -o jsonpath='{.items[0].metadata.name}')
kubectl exec -it -n demo-secure $TARGET_POD -- /bin/sh -c "whoami; ls -la /etc/nginx"

The command returns root alongside the directory listing. If an attacker breaches the web application, they can inspect virtual host configurations, write reverse shells, or download rootkits without friction.

Step 4: Craft and Apply an Inline Blocking Policy

Next, write a targeted KubeArmorPolicy custom resource. We will lock down two specific attack paths:

  1. Block all execution attempts for system shells (/bin/sh, /bin/ash, /bin/bash).
  2. Prohibit read and write access to /etc/nginx/conf.d/, keeping proxy rules and certificates tamper-proof.

Save this configuration as harden-nginx-policy.yaml:

apiVersion: security.kubearmor.com/v1
kind: KubeArmorPolicy
metadata:
  name: block-shell-and-config-tampering
  namespace: demo-secure
spec:
  selector:
    matchLabels:
      app: nginx-target
  process:
    matchPaths:
      - path: /bin/sh
      - path: /bin/ash
      - path: /bin/bash
    action: Block
  file:
    matchDirectories:
      - dir: /etc/nginx/conf.d/
        recursive: true
    action: Block

Apply the manifest and confirm that KubeArmor loaded the rules:

kubectl apply -f harden-nginx-policy.yaml
kubectl get kubearmorpolicies -n demo-secure

Step 5: Verify Kernel Enforcement in Real Time

With the policy loaded, run the exact same shell command you used in Step 3:

kubectl exec -it -n demo-secure $TARGET_POD -- /bin/sh

Instead of a prompt, the container runtime immediately returns an error:

OCI runtime exec failed: exec failed: container_linux.go: exec: "/bin/sh": permission denied: unknown

The binary /bin/sh sits right where it always was on the filesystem with executable flags intact. But the kernel intercepted the execve call, evaluated it against the LSM profile, and killed execution before the first instruction ran.

To inspect the telemetry payload, stream the KubeArmor audit pipeline in another terminal window:

karmor log --namespace demo-secure --json

The JSON stream provides structured forensics: timestamp, host PID, container ID, parent process hierarchy, policy name, and the exact blocked operation.

Hardening Lessons from the Field

CI/CD vulnerability scanners remain essential, but they cannot defend against runtime exploitation. Zero-day flaws, supply chain compromises, and configuration oversights will always slip into production. By anchoring protection in eBPF and LSMs through KubeArmor, security moves from passive detection to active defense. Even when an exploit lands, the attacker finds themselves trapped in a sandbox where shells cannot spawn and critical configs cannot be touched.

Share: