Container Escape Vulnerabilities and Mitigation Strategies

Container escapes occur when an attacker breaks out of a container’s isolation to access the host system or other containers. Understanding these vulnerabilities and implementing proper mitigations is critical for container security.

Common Escape Vectors

  • Privileged Containers: Running with –privileged flag disables security features
  • Dangerous Capabilities: CAP_SYS_ADMIN, CAP_NET_ADMIN enable escape paths
  • Host Path Mounts: Mounting sensitive host directories
  • Kernel Exploits: Vulnerabilities in the shared kernel
  • Container Runtime Bugs: CVEs in Docker, containerd, runc

Kubernetes Pod Security Standards

# Restricted Pod Security Standard
apiVersion: v1
kind: Namespace
metadata:
  name: secure-apps
  labels:
    pod-security.kubernetes.io/enforce: restricted
    pod-security.kubernetes.io/audit: restricted
    pod-security.kubernetes.io/warn: restricted

Secure Container Configuration

apiVersion: v1
kind: Pod
metadata:
  name: secure-pod
spec:
  securityContext:
    runAsNonRoot: true
    runAsUser: 1000
    fsGroup: 1000
    seccompProfile:
      type: RuntimeDefault
  containers:
  - name: app
    image: myapp:latest
    securityContext:
      allowPrivilegeEscalation: false
      readOnlyRootFilesystem: true
      capabilities:
        drop:
          - ALL
    resources:
      limits:
        memory: "128Mi"
        cpu: "500m"

AppArmor Profile

# /etc/apparmor.d/container-profile
profile container-restricted flags=(attach_disconnected,mediate_deleted) {
  # Deny all file writes except /tmp
  deny /** w,
  /tmp/** rw,
  
  # Deny network raw access
  deny network raw,
  
  # Deny mount operations
  deny mount,
  
  # Deny ptrace
  deny ptrace,
}

Seccomp Profile

{
  "defaultAction": "SCMP_ACT_ERRNO",
  "architectures": ["SCMP_ARCH_X86_64"],
  "syscalls": [
    {
      "names": ["read", "write", "open", "close", "stat", "fstat", "mmap", "mprotect", "munmap", "brk", "exit_group"],
      "action": "SCMP_ACT_ALLOW"
    }
  ]
}

Runtime Detection

# Falco rule for container escape attempts
- rule: Container Escape via Mount
  desc: Detect attempts to mount host filesystem
  condition: >
    spawned_process and container and 
    proc.name = "mount" and 
    proc.args contains "/host"
  output: >
    Container escape attempt via mount 
    (user=%user.name container=%container.name command=%proc.cmdline)
  priority: CRITICAL

Mitigation Checklist

  • Never run privileged containers in production
  • Drop all capabilities and add only required ones
  • Use read-only root filesystem
  • Implement Pod Security Standards
  • Keep container runtime and kernel updated
  • Use gVisor or Kata Containers for high-security workloads

Conclusion

Container escapes represent a serious threat to multi-tenant environments. By implementing defense-in-depth with proper security contexts, AppArmor/Seccomp profiles, and runtime monitoring, organizations can significantly reduce the risk of container breakouts.