MONEY MITRA NETWORK ACADEMY
Docker Container Defense
Image Security & Registry Protection
Secure your container image supply chain from build to deployment. Learn vulnerability scanning, image signing, registry access controls, and supply chain integrity validation to prevent unauthorized image deployment.
$ docker scan myapp:latest
Scanning image for vulnerabilities...
Found 12 vulnerabilities (3 critical)
→ Requires remediation before deployment
Image Security Fundamentals
Base Image Risks
Base images form the foundation of your container security posture:
- ⚠ Bloated images: Large base images with unnecessary packages expand vulnerability surface
- ⚠ Unpatched packages: Outdated OS packages and dependencies with known CVEs
- ⚠ Untrusted registries: Third-party or unofficial base images may contain malware
- ⚠ No SCA: Unknown dependencies and transitive vulnerabilities go undetected
FROM ubuntu:20.04
⚠ 250+ packages included
⚠ Contains 47 vulnerabilities
Vulnerability Scanning Concept
Scanning identifies known vulnerabilities before deployment:
- ✓ CVE Databases: Cross-reference image packages against NVD, GitHub Security Advisory, and vendor databases
- ✓ Layer Analysis: Scan each layer for vulnerabilities and exposed credentials
- ✓ Severity Scoring: CVSS scoring helps prioritize remediation efforts (Critical → Low)
- ✓ Continuous Scanning: Ongoing monitoring for new CVEs in running images
Critical: 2 CVEs | High: 5 | Medium: 12
Action: Update base packages
Severity: Block deployment
Common Vulnerability Categories
📚 Dependencies
Third-party libraries with known CVEs (log4j, etc.)
🔧 OS Packages
Unpatched kernel and system package vulnerabilities
🔐 Secrets
API keys, passwords, credentials accidentally baked into images
⚙️ Misconfigs
Insecure settings, weak permissions, exposed ports
Secure Image Lifecycle
Build-Time Security Awareness
Secure image construction from Dockerfile to registry:
Use Minimal Base Images
Alpine, Distroless, or scratch images contain only essential components, reducing attack surface and vulnerability count
Multi-Stage Builds
Separate build artifacts from runtime environment; exclude build tools and source code from final image
Run Non-Root
Create unprivileged user for application; prevents privilege escalation if container is compromised
Exclude Secrets
Never commit credentials, API keys, or sensitive data into images; use environment variables or secret management
Regular Updates
Rebuild images frequently to incorporate OS and dependency patches; establish update cadence
# Secure Dockerfile pattern
FROM alpine:3.18 AS builder
# Build application
FROM alpine:3.18
USER nobody
COPY --from=builder /app /app
✓ Minimal, non-root, multi-stage
Dependency Risk Management
Managing third-party dependencies and supply chain risks:
-
📦
Software Composition Analysis (SCA)
Identify all components, versions, and licenses; detect vulnerable dependencies and outdated packages
-
🔍
Transitive Dependencies
Track indirect dependencies; vulnerabilities in secondary packages can be equally critical
-
🔗
Lock Files & Pinning
Use dependency lock files to ensure reproducible builds and prevent unexpected package updates
-
📄
SBOM Generation
Generate Software Bill of Materials (CycloneDX/SPDX) for complete component visibility and compliance
Registry Protection
Access Control Concepts
Prevent unauthorized image access with strong registry controls:
- ✓ Strong Authentication: Use strong credentials, token-based auth, OAuth, or OIDC instead of simple passwords
- ✓ RBAC: Role-based access control restricts push/pull to authorized users and CI/CD systems
- ✓ Repository Isolation: Separate public/private repos; restrict access at team/project level
- ✓ Credential Rotation: Regular credential updates prevent long-lived secrets from being leaked
$ docker login --username user --password-stdin
✓ Use PAT instead of password
✓ Rotate credentials quarterly
Preventing Unauthorized Operations
Defend registry against push/pull attacks and tampering:
- 🔒 Image Signing: Digitally sign images with Cosign or Notary; verify signatures before pull
- 🔒 Registry Audit Logs: Log all push/pull operations; detect and investigate suspicious activity
- 🔒 Push/Pull Policies: Restrict operations based on image type, digest, or tag; prevent tag override
- 🔒 Image Immutability: Lock image tags to prevent overwriting; use SHA256 digests instead
⚠ Risky: docker pull app:latest
✓ Safe: docker pull app@sha256:abc123...
✓ Verify signature before use
Registry Security Best Practices
🌐 Network Security
Use HTTPS/TLS; deploy registry behind firewall; restrict network access to authorized users/CI systems
📊 Image Scanning
Enforce vulnerability scanning on push; block images with critical/high CVEs from deployment
🔄 Compliance
Maintain audit trails; meet compliance requirements (HIPAA, PCI-DSS); regular security assessments
Supply Chain Awareness
Image Integrity Validation
Ensure images haven't been modified or tampered with during transit:
- 🔗 Content Hash: Use SHA256 digests to verify exact image content; immutable reference independent of tags
- 🔗 TLS/HTTPS: Verify registry certificate; prevent man-in-the-middle attacks on image downloads
- 🔗 Image Manifest: Check manifest signatures and provenance; trace image origin and build metadata
- 🔗 Checksum Verification: Compare downloaded image checksum against registry; detect corruption or tampering
Signing & Verification Mindset
Digital signatures prove image authenticity and origin:
- 🔐 Cosign: Modern container image signing tool; supports keyless signing with OIDC
- 🔐 Notary/DCT: Docker Content Trust; sign images at build; verify before pull
- 🔐 Key Management: Secure private keys; rotate signing keys regularly; store in HSM if possible
- 🔐 Policy Enforcement: Require signature verification in admission controllers; reject unsigned images at runtime
$ cosign sign image:tag
✓ Image signed with private key
$ cosign verify image:tag
✓ Signature valid - trusted source
Supply Chain Attack Vectors
🎯 Compromised Base Image
Attacker publishes malicious base image; developers unknowingly inherit backdoor
📦 Dependency Injection
Popular package hijacked or replaced with malware; spreads via build pipelines
🏗️ Build Pipeline Compromise
CI/CD system compromised; attacker modifies images before push to registry
🏴 Registry Takeover
Weak credentials or API vulnerability; attacker gains registry access and pushes malicious images
External Learning References
Explore official Docker, DevSecOps, and container security resources for deeper understanding:
Docker Image Scanning
Docker Scout and vulnerability scanning in Docker Desktop
Docker Content Trust
Image signing and verification with Docker Content Trust
Cosign - Container Signing
Modern container image signing and verification tool
Trivy - Image Scanning
Open-source vulnerability scanner for containers
DevSecOps Best Practices
OWASP DevSecOps project and security integration