Skip to Content
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 Nov 22, 2026
9 min read

Introduction

Most applications now ship as containers, and a container is not a virtual machine. You need to know where the isolation actually sits to attack it or to harden it.

This note walks through the parts of Docker and Kubernetes that matter for security: where the isolation boundaries are and which misconfigurations break them.

Security perspective

Containers share the host kernel, so the threat model is different from a VM. One kernel vulnerability affects every container on the host.

Docker architecture

How containers work

Docker builds process isolation out of Linux kernel features:

FeatureWhat it does
NamespacesGive the container its own process tree, network stack, users and mount table
CgroupsCap CPU, memory and I/O
Union filesystemsStack image layers so containers share read-only base layers
CapabilitiesSplit root's privileges into individual grants
# 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 weaker than VM isolation. Every container talks to the same kernel:

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

What follows from that:

  • A kernel exploit hits every container on the host
  • A container escape is a host compromise
  • Root in the container is not root on the host, unless the configuration makes it so

Docker socket exposure

Look for the Docker socket (/var/run/docker.sock) first. Anyone who can talk to it controls the daemon:

# 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

Don't mount the Docker socket into a container unless there is no other way. Socket access is 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, sometimes left 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

The API server authenticates requests with:

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

It then authorizes them with one or more of these modes:

ModeNotes
RBACRole-based access control, the one to use
ABACAttribute-based access control, legacy
NodeAuthorizes kubelet requests
WebhookHands the decision to an external service
# 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

VectorWhat it gives you
Privileged containerFull device access and kernel module loading
Dangerous capabilitiesCAP_SYS_ADMIN or CAP_SYS_PTRACE open several escapes
Docker socketStart a new privileged container with the host filesystem mounted
Kernel vulnerabilitiesDirty COW, OverlayFS CVEs
runc vulnerabilitiesCVE-2019-5736 overwrites the host runc binary
Host path mountsDirect writes to the host filesystem

Kubernetes attack paths

  1. Compromised pod → service account token → API access
  2. Misconfigured RBAC → create a privileged pod → node compromise
  3. etcd access → extract secrets → lateral movement
  4. Kubelet API → exec into pods → 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

Hardening 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

CWE entries

Official documentation

On this page