Container architecture and security fundamentals

Containerization Fundamentals

Security-focused overview of Docker and Kubernetes architecture, covering isolation mechanisms, security boundaries, and common misconfigurations from an offensive security perspective.

Mar 31, 2026
Updated Dec 11, 2025
2 min read

Introduction

Containers have become the standard deployment model for modern applications, but they introduce security considerations that differ from traditional virtual machines. Understanding container architecture is essential for both offensive security testing and defensive hardening.

This guide covers the security-relevant aspects of Docker and Kubernetes architecture, highlighting isolation boundaries and common misconfigurations.

Security Perspective

Containers share the host kernel, creating a fundamentally different threat model than VMs. A kernel vulnerability affects all containers on the host.

Docker Architecture

How Containers Work

Docker containers use Linux kernel features to provide process isolation:

  • Namespaces - Isolate process trees, network stacks, users, and filesystems
  • Cgroups - Limit CPU, memory, and I/O resources
  • Union Filesystems - Layer images for efficient storage
  • Capabilities - Fine-grained privilege control
# View container namespaces
lsns -p $(docker inspect --format '{{.State.Pid}}' container_name)

# View cgroup limits
cat /sys/fs/cgroup/memory/docker/<container_id>/memory.limit_in_bytes

Docker Components

ComponentFunctionSecurity Relevance
Docker DaemonManages containersRuns as root, API access = host compromise
Docker CLIClient interfaceCredentials stored in ~/.docker/config.json
containerdContainer runtimeLower-level container management
runcOCI runtimeExecutes containers, subject to CVEs
Docker RegistryImage storageSupply chain attacks, credential exposure

Security Boundaries

Docker isolation is not equivalent to VM isolation:

┌─────────────────────────────────────────────┐
│                  Host OS                     │
│  ┌──────────────────────────────────────┐   │
│  │           Linux Kernel                │   │
│  │  (Shared by all containers)          │   │
│  └──────────────────────────────────────┘   │
│                                             │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐  │
│  │Container1│  │Container2│  │Container3│  │
│  │ Namespace│  │ Namespace│  │ Namespace│  │
│  └──────────┘  └──────────┘  └──────────┘  │
└─────────────────────────────────────────────┘

Key implications:

  • Kernel exploits affect all containers on the host
  • Container escape = host compromise
  • Root in container != root on host (unless misconfigured)

Docker Socket Exposure

The Docker socket (/var/run/docker.sock) is a critical attack target:

# If mounted in container, full host compromise is possible
docker run -v /var/run/docker.sock:/var/run/docker.sock alpine

# From inside container with socket access
docker run -v /:/host -it alpine chroot /host

High Risk

Never expose the Docker socket to containers unless absolutely necessary. Socket access equals root on the host.

Kubernetes Architecture

Control Plane Components

ComponentFunctionSecurity Relevance
kube-apiserverAPI endpointPrimary attack target, RBAC enforcement
etcdCluster state storeContains secrets, requires encryption
kube-schedulerPod placementInfluences where workloads run
kube-controller-managerCluster controllersService account token management
cloud-controller-managerCloud provider integrationCloud credential access

Worker Node Components

ComponentFunctionSecurity Relevance
kubeletPod managementNode-level API, often unauthenticated
kube-proxyNetwork proxyService routing, network policies
Container RuntimeRuns containerscontainerd, CRI-O, Docker

Kubernetes Security Model

┌─────────────────────────────────────────────────────────┐
│                    Kubernetes Cluster                    │
│  ┌────────────────────────────────────────────────────┐ │
│  │                   Control Plane                     │ │
│  │  ┌─────────┐  ┌────┐  ┌───────────┐  ┌──────────┐ │ │
│  │  │API Server│  │etcd│  │Scheduler  │  │Controller│ │ │
│  │  └─────────┘  └────┘  └───────────┘  └──────────┘ │ │
│  └────────────────────────────────────────────────────┘ │
│                                                          │
│  ┌────────────────────┐  ┌────────────────────────────┐ │
│  │     Worker Node    │  │       Worker Node          │ │
│  │  ┌──────────────┐  │  │  ┌──────────────────────┐  │ │
│  │  │   Pod        │  │  │  │        Pod           │  │ │
│  │  │ ┌──────────┐ │  │  │  │ ┌────────┐ ┌──────┐ │  │ │
│  │  │ │Container │ │  │  │  │ │Cont. A │ │Cont B│ │  │ │
│  │  │ └──────────┘ │  │  │  │ └────────┘ └──────┘ │  │ │
│  │  └──────────────┘  │  │  └──────────────────────┘  │ │
│  │  ┌───────┐ ┌─────┐ │  │  ┌───────┐ ┌─────┐        │ │
│  │  │kubelet│ │proxy│ │  │  │kubelet│ │proxy│        │ │
│  │  └───────┘ └─────┘ │  │  └───────┘ └─────┘        │ │
│  └────────────────────┘  └────────────────────────────┘ │
└─────────────────────────────────────────────────────────┘

Authentication and Authorization

Authentication methods:

  • X.509 client certificates
  • Service account tokens
  • OpenID Connect (OIDC)
  • Webhook token authentication

Authorization models:

  • RBAC - Role-Based Access Control (recommended)
  • ABAC - Attribute-Based Access Control (deprecated)
  • Node - kubelet authorization
  • Webhook - External authorization
# Example RBAC - Least privilege for deployment reader
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: deployment-reader
  namespace: production
rules:
- apiGroups: ["apps"]
  resources: ["deployments"]
  verbs: ["get", "list"]

Common Misconfigurations

Docker Misconfigurations

IssueRiskDetection
--privileged flagContainer escapedocker inspect
Docker socket mountedHost compromiseCheck container mounts
Running as rootPrivilege escalationdocker inspect --format '{{.Config.User}}'
Host network modeNetwork pivotingdocker inspect --format '{{.HostConfig.NetworkMode}}'
Sensitive mountsData exposureCheck /proc/mounts in container
# Find privileged containers
docker ps -q | xargs docker inspect --format '{{.Name}} {{.HostConfig.Privileged}}'

# Find containers with socket mounted
docker ps -q | xargs docker inspect --format '{{.Name}} {{range .Mounts}}{{.Source}}{{end}}' | grep docker.sock

Kubernetes Misconfigurations

IssueRiskDetection
Anonymous authentication enabledUnauthenticated API accesskubectl auth can-i --list --as=system:anonymous
Overly permissive RBACPrivilege escalationAudit ClusterRoleBindings
Privileged podsContainer escapeCheck SecurityContext
Default service accountsToken abusePods without explicit SA
etcd unencryptedSecret exposureCheck etcd configuration
Kubelet API exposedNode compromisePort 10250/10255 scan
# Check for privileged pods
kubectl get pods -A -o json | jq '.items[] | select(.spec.containers[].securityContext.privileged==true) | .metadata.name'

# Check anonymous access
kubectl auth can-i --list --as=system:anonymous

# Find pods with hostPath mounts
kubectl get pods -A -o json | jq '.items[] | select(.spec.volumes[]?.hostPath != null) | {name: .metadata.name, namespace: .metadata.namespace}'

Attack Surface

Container Escape Vectors

  1. Privileged containers - Full device access, kernel module loading
  2. Dangerous capabilities - CAP_SYS_ADMIN, CAP_SYS_PTRACE
  3. Docker socket exposure - Create privileged container
  4. Kernel vulnerabilities - Dirty COW, OverlayFS CVEs
  5. runc vulnerabilities - CVE-2019-5736
  6. Host path mounts - Write to host filesystem

Kubernetes Attack Paths

  1. Compromised pod → Service account token → API access
  2. Misconfigured RBAC → Create privileged pod → Node compromise
  3. etcd access → Extract secrets → Lateral movement
  4. Kubelet API → Pod execution → Container compromise
  5. Cloud metadata → IAM credentials → Cloud compromise
# From compromised pod - check service account permissions
cat /var/run/secrets/kubernetes.io/serviceaccount/token | cut -d. -f2 | base64 -d
kubectl auth can-i --list

# Access cloud metadata (if not blocked)
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/

Security Tools

Vulnerability Scanning

ToolPurpose
TrivyImage vulnerability scanning
GrypeContainer image scanner
KubescapeKubernetes security scanning
kube-benchCIS benchmark compliance
FalcoRuntime security monitoring
# Scan image for vulnerabilities
trivy image nginx:latest

# Kubernetes security assessment
kubescape scan framework nsa

# CIS benchmark check
kube-bench run --targets=node

Offensive Tools

ToolPurpose
CDKContainer/Kubernetes penetration toolkit
PeiratesKubernetes penetration testing
kubectl-who-canRBAC enumeration
kube-hunterKubernetes vulnerability scanner
# CDK - Container escape detection
./cdk evaluate

# Peirates - Kubernetes attack automation
./peirates

# Find who can create pods
kubectl-who-can create pods -A

Quick Reference: Security Checklist

Docker

  • Never run containers with --privileged
  • Don't mount Docker socket in containers
  • Run containers as non-root user
  • Use read-only root filesystems
  • Drop all capabilities, add only required
  • Scan images for vulnerabilities
  • Don't store secrets in images

Kubernetes

  • Enable RBAC with least privilege
  • Use Pod Security Standards (restricted)
  • Encrypt etcd at rest
  • Enable audit logging
  • Use Network Policies
  • Don't use default service accounts
  • Block cloud metadata access
  • Disable anonymous authentication

References

MITRE ATT&CK Techniques

Common Weakness Enumeration

Official Documentation

Last updated on