D8.1 Security Concepts για Docker 🛡️
Γιατί Docker Security;
Ένα default Docker container δεν είναι ασφαλές. Τρέχει ως root, έχει πρόσβαση σε kernel capabilities, και μπορεί (αν παραβιαστεί) να επηρεάσει τον host.
📝 Αναλογία με Ansible:
Ansible → SSH ασφάλεια: key auth, no root, no passwords Docker → Container ασφάλεια: no root, no caps, read-only Ίδια φιλοσοφία: Principle of Least Privilege
Attack Surface — Τι κινδυνεύει;
Docker Attack Surface:
│
├── Container escape
│ └── Εκτέλεση κώδικα στον HOST μέσα από container
│
├── Privilege escalation
│ └── root στο container → root στον host
│
├── Secrets exposure
│ └── Passwords σε env vars, image layers, logs
│
├── Network attacks
│ └── Container-to-container lateral movement
│
└── Image vulnerabilities
└── CVEs σε base images, dependencies
Defense in Depth
Layers of Security:
Layer 1: Image Security
├── Minimal base image (distroless, alpine)
├── Non-root user στο Dockerfile
└── Regular scanning (Trivy)
Layer 2: Runtime Security
├── --user=1000:1000 (non-root)
├── --no-new-privileges
├── --read-only (read-only filesystem)
└── --cap-drop=ALL (no capabilities)
Layer 3: Network Security
├── Custom networks (isolation)
├── internal: true (no internet for DBs)
└── Minimal port exposure
Layer 4: Secrets
├── Ansible Vault (όχι plaintext)
├── File mounts (όχι env vars για secrets)
└── no_log: true σε Ansible tasks
Docker Security Checklist
✅ Non-root user (--user ή USER στο Dockerfile)
✅ no-new-privileges
✅ Read-only filesystem (+ tmpfs για /tmp)
✅ Drop ALL capabilities
✅ Secrets ως files (όχι env vars)
✅ Network isolation (internal networks)
✅ Minimal base image
✅ Image scanning πριν deployment
✅ Resource limits (memory, CPU)
✅ Logging (για audit)
Σύνοψη D8.1
Docker Security Philosophy:
│
├── Principle of Least Privilege:
│ ├── Μόνο ό,τι χρειάζεται
│ └── Τίποτα παραπάνω
│
├── Defense in Depth:
│ ├── Image → Runtime → Network → Secrets
│ └── Κάθε layer ανεξάρτητο
│
└── Ansible ρόλος:
└── Εξασφαλίζει consistent security
σε ΟΛΟΥΣ τους hosts (idempotent)