What is Container Security?
Container Security encompasses all practices, tools, and processes for securing containerized applications from build time through deployment to runtime. Containers share the host system's kernel, which introduces new security challenges compared to traditional virtual machines. Effective container security requires a multi-layered approach covering image scanning, runtime protection, network isolation, secrets management, and compliance enforcement.
Why is Container Security Critical?
Containers have transformed how we develop and deploy applications, but they have also introduced new security risks:
- Shared kernel: All containers on a host share the same OS kernel - a kernel exploit can compromise the entire host
- Image vulnerabilities: 80%+ of Docker images contain known CVE vulnerabilities
- Misconfigurations: Privileged containers, mounted Docker socket, exposed APIs
- Supply chain risks: Untrusted base images, malicious layers, backdoored dependencies
- Runtime threats: Container breakout, lateral movement, crypto mining
- Secrets exposure: Hardcoded credentials, env variables, mounted secrets
- Network attacks: Pod-to-pod lateral movement without network policies
Notable Container Security Incidents
- Tesla Kubernetes cryptojacking (2018): Unprotected Kubernetes dashboard used for mining
- Docker Hub malicious images: 17 malicious images with 5M+ pulls contained cryptominers
- RunC vulnerability (CVE-2019-5736): Container breakout enabling root access on the host
- Kinsing malware: Exploits misconfigured Kubernetes for cryptomining and botnet operations
Container Security Layers
Defense in Depth Approach
1. Build Time Security
Security during the image build process
- Base image selection (minimal, trusted sources)
- Dockerfile best practices (non-root user, no secrets)
- Image scanning for CVEs (Trivy, Snyk, Clair)
- Multi-stage builds for a smaller attack surface
- Image signing and verification (Cosign, Notary)
2. Registry Security
Securing the container registry
- Private registries with authentication
- Image vulnerability scanning in the registry
- Access control (RBAC, IAM)
- Image retention policies
- Webhook notifications for new vulnerabilities
3. Orchestration Security (Kubernetes)
Securing the Kubernetes cluster
- Pod Security Standards (Restricted, Baseline)
- Network Policies (CNI-based isolation)
- RBAC for users and service accounts
- Admission Controllers (OPA, Kyverno)
- Secrets management (Vault, External Secrets)
4. Runtime Security
Monitoring and protection of running containers
- Runtime behavior monitoring (Falco, Tetragon)
- Anomaly detection
- Process/file/network monitoring
- Intrusion prevention
- Audit logging
5. Host Security
Securing the underlying infrastructure
- Minimal host OS (COS, Bottlerocket)
- Kernel hardening (AppArmor, SELinux)
- Host patching and updates
- CIS Benchmarks compliance
- Node isolation
Docker Security Best Practices
Secure Dockerfile
Docker Compose Security
Image Scanning Tools
Trivy
The most popular open-source vulnerability scanner for container images, filesystems, and git repos.
- Detects CVEs in OS packages and application dependencies
- Supports Docker, containerd, Kubernetes
- Fast (seconds) with offline mode
- IaC scanning (Terraform, CloudFormation)
- Secret detection
- SBOM generation
Clair
Static analysis tool for vulnerabilities in container images by CoreOS.
- Layer-by-layer analysis
- Multiple vulnerability databases
- API-first design
- Integration with Quay registry
Snyk Container
Developer-first container security with fix recommendations.
- Base image recommendations
- Prioritized fix guidance
- CI/CD integration
- Kubernetes deployment scanning
AWS ECR Scanning
Native image scanning in Amazon ECR registries.
- Basic (Clair-based) scanning
- Enhanced (Inspector-based)
- Continuous scan on push
- EventBridge notifications
Practical Example: Trivy in CI/CD
Kubernetes Security
Pod Security Standards
Kubernetes defines three levels of pod security policies:
Network Policies
Runtime Security
Falco
Runtime security tool using eBPF for syscall monitoring and anomaly detection.
- Detects abnormal behavior (shell spawn, file access)
- Custom rules (Falco rules syntax)
- Kubernetes-aware
- Real-time alerting
- Integration with SIEM
Tetragon
eBPF-based security observability and runtime enforcement by Cilium.
- Process execution monitoring
- File access tracking
- Network connections
- Syscall filtering
- Policy enforcement
Falco Rules Example
Container Security Best Practices - Summary
Build Time
- Use minimal base images (alpine, distroless, scratch)
- Specific version tags (not latest)
- Multi-stage builds for smaller images
- Scan images before pushing to registry (Trivy, Snyk)
- Non-root user
- No secrets in images or Dockerfile
- Sign images (Cosign, Notary)
Kubernetes Deployment
- Pod Security Standards (Restricted for production)
- Network Policies (default deny all)
- Resource limits (CPU, memory)
- RBAC (least privilege)
- Secrets from external store (Vault, AWS Secrets Manager)
- Admission controllers (OPA, Kyverno)
- Service mesh for mTLS (Istio, Linkerd)
Runtime
- Runtime monitoring (Falco, Tetragon)
- Anomaly detection and alerting
- Audit logging
- Incident response playbooks
- Regular security audits
What NOT to Do
- Use the latest tag in production
- Run containers as root
- Mount Docker socket into a container
- Privileged containers without justification
- Hardcoded secrets in images
- No network policies
- Disable security features for "faster debugging"
- Ignore scan results