Security Benchmarks & Hardening
From vibes to a numbered compliance line
Benchmarks (CIS, CSA, NIST) turn 'be safe' into a numbered checklist for cloud accounts and images. Hardening = the practice list; benchmark scanners automate the 'are we still compliant' check on every release.
What you will learn
- Read and apply a provider baseline (CIS Benchmarks)
- Automate benchmark scans in CI and at runtime
- Prioritize findings by severity + exploitability, not raw count
A benchmark is a control checklist (e.g., CIS AWS/Azure/GCP Foundations, CIS Docker/K8s). Scanners (config reviews at CI, host agents, Policy rules) compare you to it; hardening means config/host changes, not just reporting.
What is this?
Standards: CIS Benchmarks (per provider + OS + k8s/docker), CSA CCM, NIST-800-53, STIG. Cloud-native scanners: AWS Security Hub (CIS) + Config packs, Azure Defender + policy, GCP Security Command Center + catalog + CIS workbook site, plus CasC (checkov against IaC). Host level: CIS Benchmark agents (Trivy, osquery), package/digest checks, VSroting. K8s: Pod Security Standards, kyverno/OPA defaults. Prioritization: severity × exposure × exploit path (CVE with public exploit > theoretical). Remediation loop: scan → gating rule for criticals → fix → re-scan; exceptions documented with owner+expiry. Baselines as IaC: hardened AMIs golden-image + scan gate in CI.
Why do you need it?
- Benchmarks convert 'sec opinion' into an auditable, issue-tracker list.
- Scanning in CI blocks new dirty infra from deploying (shift-left).
- Host + cloud scanners catch config drift after the golden image bakes.
- Evidence from canonical frameworks is auditor-ready almost out of the box.
Mental model
A multi-hoor safety inspection checklist bolted to every workshop wall
CIS benchmark + scanner
The wall checklist (benchmark) states rules concretely (padlocks, extinguishers), and the inspector (scanner) walks every week to see compliance, not just intention.
How it works
- Select the right benchmark(s) for your provider + runtime stack.
- Scanner checks config/host/registry vs the benchmark each scan.
- Results map to severity + framework ids; the pipeline fails criticals.
- Fix applies hardening (restrict IDs, set TLS versions, disable legacy) → re-scan green.
- Drift detection: agents/rules recheck on schedule; exceptions expiry-tracked.
Benchmark loop.
Examples
CasC gate in the pipeline
# CI: checkov against the same HCL that will be appliedcheckov -d envs/prod --framework terraform --download-external-modules false --fail-on-checks CKV_AWS_1,CKV_AWS_150 # ex: no public SG, encrypted# host: trivy image --scanners vuln,secret,config ghcr.io/acme/api:v1.2The deploy pipeline refuses a plan that opens public ports or ships a flagged image — shift-left is the benchmark in action.
In production
- Security Hub + CIS pack active across accounts; exceptions via IAM+owner.
- Hardened golden AMIs baked from a CIS-baseline Packer template + rescanned in CI.
- K8s admission default-deny (PSA restricted) as 'the benchmark prevented the incident'.
Best practices
- Pick a benchmark per platform + runtime; don't run five conflicting checklists.
- Automate scans in CI (IaC) + runtime agents (host/container) — two different drifts.
- Prioritize by exposure, not count: a trivial CVE on an internet-facing service > 50 criticals in /3rd-party.
- Set exception expiry: a waived finding is a debt with a due date.
- Re-drill: introduce a benchmark-regression to prove your gate actually blocks it.
Common mistakes
- Scanning and reporting, then doing nothing (scorecard theater).
- Huge finding lists because the scanner config is too broad → ignored signal.
- Golden image hardened, then every deploy drifts because admins tweak after boot.
- Treating CIS as binary-pass; 'mostly compliant' in prod still fails the audit moment.
Debugging tips
- A scanner result that ignores your fix → check model/config drift vs the agent's cached state.
- Critical skipped by gate → verify the failing framework/severity matchers in CI config.
- Image scan clean but host check dirty → the layer/image differs from what runs (digest pin).
- Rule exceptions with no owner → hunt and re-issue; auditor will ask who waived it.
Interview checkpoint
Quick quiz
A critical finding on an internet-exposed service vs 50 low on internal tools — which do you fix first?
Shift-left for IaC means: