teluzia.Cloud Engineer · Day 138
CHAPTER 20 · COST MANAGEMENT AND SECURITY

Trivy and container/IaC scanning

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

Container scanning is today's starting point. Scan image digest sha256:abc rather than only latest. A report identifies package, installed version and fixed version; rebuilding with the fix requires rescanning the resulting digest, not reusing the old report. You will connect this with iac misconfiguration scanning and remediation and exceptions. The lesson's artifact brings these decisions together: Draft three sample image/configuration findings and a pipeline gate policy distinguishing fixable issues from documented time-limited exceptions.

Think of it this way

A scanner is an inspection of the exact packed suitcase; checking yesterday's suitcase does not establish the contents of today's replacement.

TOPIC 01 / 03Step by step

Container scanning

Trivy inspects image packages against vulnerability information. Pin the scanned image digest and scanner/database versions; a mutable tag can change between scan and deployment. Scan image digest sha256:abc rather than only latest. A report identifies package, installed version and fixed version; rebuilding with the fix requires rescanning the resulting digest, not reusing the old report.

WORKED EXAMPLE
Scan image digest sha256:abc rather than only latest. A report identifies package, installed version and fixed version; rebuilding with the fix requires rescanning the resulting digest, not reusing the old report.

An image digest identifies content; a package inventory lists installed components; a vulnerability identifier links an issue to affected versions. Imagine CI scans one digest but deployment later uses a tag pointing elsewhere. The clean scan has no reliable relationship to the deployed bytes. Carry digest identity from build through scan, registry and release evidence. Distinguish installed vulnerable packages from runtime reachability: the scanner reports the former, while exposure analysis informs the latter. Record database freshness because missing or stale intelligence affects results. Scanning every release improves consistency but can slow builds and produce recurring findings. Cache carefully and keep provenance, while treating the report as one security signal rather than a guarantee that the image contains no dangerous behavior.

Why this matters

A report identifies package, installed version and fixed version; rebuilding with the fix requires rescanning the resulting digest, not reusing the old report.

A common trap

Scanning a mutable image tag proves the later deployed bytes are identical.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Container scanning

Trivy inspects image packages against vulnerability information. Pin the scanned image digest and scanner/database versions; a mutable tag can change between scan and deployment. Scan image digest sha256:abc rather than only latest. A report identifies package, installed version and fixed version; rebuilding with the fix requires rescanning the resulting digest, not reusing the old report.

WORKED EXAMPLE
Scan image digest sha256:abc rather than only latest. A report identifies package, installed version and fixed version; rebuilding with the fix requires rescanning the resulting digest, not reusing the old report.

An image digest identifies content; a package inventory lists installed components; a vulnerability identifier links an issue to affected versions. Imagine CI scans one digest but deployment later uses a tag pointing elsewhere. The clean scan has no reliable relationship to the deployed bytes. Carry digest identity from build through scan, registry and release evidence. Distinguish installed vulnerable packages from runtime reachability: the scanner reports the former, while exposure analysis informs the latter. Record database freshness because missing or stale intelligence affects results. Scanning every release improves consistency but can slow builds and produce recurring findings. Cache carefully and keep provenance, while treating the report as one security signal rather than a guarantee that the image contains no dangerous behavior.

Why this matters

A report identifies package, installed version and fixed version; rebuilding with the fix requires rescanning the resulting digest, not reusing the old report.

A common trap

Scanning a mutable image tag proves the later deployed bytes are identical.

IaC misconfiguration scanning

Configuration scanning checks infrastructure declarations for risky settings. It complements cloud inspection because runtime changes and policies may differ from the file under review. A declaration allowing ingress 0.0.0.0/0 on port 22 should trigger review. A safer declared rule does not prove someone has not widened access manually after deployment.

WORKED EXAMPLE
A declaration allowing ingress 0.0.0.0/0 on port 22 should trigger review. A safer declared rule does not prove someone has not widened access manually after deployment.

A misconfiguration rule tests a declared setting; an IaC file describes intended infrastructure; drift is a difference between that intention and actual resources. Imagine a template restricts storage access but a manual console edit makes the deployed resource public. File scanning still passes because it has not observed the runtime change. Combine declaration review with actual configuration inspection where authorized. Understand the rule's scope and identify whether it checks network exposure, encryption or permission structure. A scanner cannot infer every business requirement; public access can be intentional but still needs a data-sensitivity review. Automated checks make common mistakes visible early, yet exceptions must remain tied to explicit requirements and actual deployment evidence rather than a global suppression that hides unrelated resources.

Why this matters

A safer declared rule does not prove someone has not widened access manually after deployment.

A common trap

Scanning IaC files proves the runtime cloud has no manual changes.

Remediation and exceptions

Fix available versions, review compatibility and rerun the scan. An exception needs justification, an owner and expiry; severity alone cannot determine exploitability in your workload. If a fix exists, test the updated dependency and rerun the scan. A no-fix finding can have an expiring exception with exposure evidence, while critical reachable code may block release immediately.

WORKED EXAMPLE
If a fix exists, test the updated dependency and rerun the scan. A no-fix finding can have an expiring exception with exposure evidence, while critical reachable code may block release immediately.

A remediation changes the affected component; an exception records a reason not to fix immediately; expiry forces a later review. Imagine an update removes a vulnerability but breaks a required application feature. Test compatibility, consider a safer version or exposure reduction and record the residual risk instead of silently abandoning the fix. Gate on documented criteria such as severity, fix availability and reachable production exposure. An exception should identify the exact package/image or resource, an accountable owner and the event or date that ends it. Broad ignore files are easy to add but can outlive their rationale. Re-scan the new artifact and preserve the before/after evidence so release reviewers can see both the risk decision and whether the intended fix actually landed.

Why this matters

A no-fix finding can have an expiring exception with exposure evidence, while critical reachable code may block release immediately.

A common trap

An exception needs no expiry after someone accepts the risk once.

KEEP THESE WITH YOU

Today’s takeaways

Container scanning: Trivy inspects image packages against vulnerability information.

IaC misconfiguration scanning: Configuration scanning checks infrastructure declarations for risky settings.

Remediation and exceptions: Fix available versions, review compatibility and rerun the scan.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed