Retrofitting Security vs Building It In

Container hardening usually starts after the image already exists: scan for CVEs, strip unnecessary packages, enforce non-root execution, layer on SELinux or AppArmor, rebuild when maintainers publish patches. That approach reduces attack surface and improves configuration hygiene, and it is worth doing. What it cannot do is change the security properties that were fixed when the binaries were compiled. Memory protections such as FORTIFY_SOURCE, stack clash defences, control-flow integrity, position-independent executables, and feature inclusion are all decisions embedded in the artifact at build time, and no scanner or runtime control can retrofit them into a pre-compiled binary. Distribution maintainers pick compilation flags for broad compatibility, so images inherit those defaults regardless of the deploying organisation's threat model.

Building components from verified source shifts those decisions into the operator's hands. Compilation happens in hermetic environments with hardened toolchains, defensive protections get applied uniformly across every package, optional features get excluded before the binary exists, and each artifact carries a signed provenance record tying it back to source commit, toolchain version, and build parameters. That model changes the operational shape too: instead of waiting for upstream maintainers to publish rebuilt packages, monitoring pipelines pull patches directly from source and recompile with the same hardened configuration, so remediation runs on the build system's cadence rather than the distribution's. SLSA and similar supply chain frameworks reward this because identical inputs produce identical outputs, which makes tamper detection and independent verification possible. The choice is architectural. Retrofit hardening keeps container security as a reactive operational loop, and source-based compilation makes it a deterministic property of the build.