Test container security by scanning the image during build for known package and base-image flaws, checking the Dockerfile for unsafe settings, and validating the runtime with admission controls, least-privilege Linux capabilities, read-only filesystems, and seccomp or AppArmor profiles. Include secret scanning and runtime monitoring for unexpected network calls, process spawning, and privilege escalation attempts.
How to test container security from build to runtime
Container security testing works best as a continuous chain, not as a single gate. Build-time checks should catch vulnerable base images, unsafe Dockerfile settings, and embedded secrets before an image is published. Runtime checks then confirm the container is actually confined, observable, and behaving as expected when it starts, talks on the network, and tries to use kernel or filesystem privileges.
That build-to-run split matters because an image can look clean at build time and still become dangerous once it is deployed with excessive privileges, a permissive admission policy, or a weak runtime profile. The practical test is whether the same workload remains safe after it is admitted, started, and exercised under realistic conditions.
For build-stage validation, focus on image composition and configuration. Scan the image for known package and base-image flaws, inspect the Dockerfile for risky patterns such as root execution, broad file permissions, uncontrolled package installation, and secret handling mistakes, and verify that signed or trusted base images are enforced where your process requires them.
Runtime testing should prove that the container is constrained, not just that it launched successfully. That means checking admission controls, verifying least-privilege Linux capabilities, confirming read-only filesystems where possible, and testing seccomp or AppArmor profiles with commands and behaviours that should be denied. A useful test is to attempt actions the workload should not need, then confirm they are blocked without breaking normal function.
Secret scanning and runtime monitoring fill the gap between static analysis and live behaviour. Scan images and manifests for secrets before deployment, then watch for unexpected process spawning, unusual outbound connections, access to sensitive paths, and privilege escalation attempts once the container is running. If a container can reach a dependency it should not call, or can spawn shells or package managers at runtime, the configuration is probably too loose.
Where build-time checks usually miss the real exposure
Build-time testing gives you a reproducible baseline, but it does not prove the container will behave safely in a cluster or on a host. Image scanners can miss abuse that only appears after startup, while Dockerfile review can overlook inherited risk from the base image, implicit privileges, or a deployment manifest that reintroduces dangerous access. That is why build findings should be treated as necessary evidence, not as proof of runtime safety.
Another common gap is assuming that a clean scan means the image is trustworthy. A container can still include leaked credentials, inherited tooling, or packages that become dangerous only when combined with mounted volumes, network reachability, or a writable root filesystem. Runtime validation is the place to confirm whether those conditions are actually present.
What runtime controls should prove, not just claim
Runtime tests should answer a small set of practical questions: can the container write where it should not, can it escalate privilege, can it spawn unexpected processes, and can it reach destinations outside its intended network path? If any of those are true, the deployment is too permissive even if the image itself is current.
Admission controls are especially important because they prevent unsafe manifests from reaching the cluster in the first place. For container workloads, the security test is not only whether policy exists, but whether the policy actually blocks privileged containers, dangerous capability sets, and non-compliant runtime settings in the path you use for deployment.
What to do when patching or hardening cannot wait
If a vulnerable image or unsafe runtime setting cannot be fixed immediately, test compensating controls as if you were trying to break the workload. Reduce privileges, isolate the container, remove unnecessary mounts, limit egress, and verify that monitoring can detect abnormal child processes or network destinations. A temporary exception is only acceptable if you can show that the blast radius is still controlled.
When secrets are involved, treat exposure as a separate problem from code quality. A secret in an image or manifest is not made safe by a clean vulnerability scan, so testing should include whether that material can be discovered, reused, or abused after deployment. If you cannot answer that confidently, rotation and revocation need to be part of the response plan.
Risk and Threat Considerations
Containers fail most often through overpermission, hidden secrets, and runtime assumptions that are never tested under pressure. The main risk is not just exploitation of a vulnerable package, but a successful pivot from a constrained workload into broader host, network, or credential access.
Failure mechanism: An attacker or tester finds that the image is packaged safely enough, but the deployed container can still spawn shells, use excess Linux capabilities, write to unexpected locations, or reach secrets and internal services because runtime policy is weaker than build-time review.
Impact: That gap can turn a routine application container into a path for lateral movement, secret theft, data exposure, or host compromise, especially when the same image is reused across environments with different admission and runtime settings.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
NIST SP 800-53 Rev 5, OWASP ASVS and CIS Controls v8 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| NIST SP 800-53 Rev 5 | SI-2 — Flaw Remediation | Container build scanning and patch hygiene depend on finding known flaws quickly. |
| SC-7 — Boundary Protection | Runtime network restrictions and admission boundaries are central to container containment. | |
| CM-7 — Least Functionality | Least-privilege capabilities, read-only filesystems, and minimal runtime settings reflect least functionality. | |
| Recommendation — Scan images and dependencies continuously, and remediate confirmed flaws before deployment. Enforce egress and ingress boundaries for container workloads. Remove unnecessary functions, permissions, and runtime capabilities from containers. | ||
| OWASP ASVS | V13 — Configuration | Dockerfile and deployment hardening tests are configuration verification problems. |
| Recommendation — Verify secure configuration settings before release and at deployment time. | ||
| CIS Controls v8 | CIS-4 — Secure Configuration of Enterprise Assets and Software | Container hardening, admission settings, and runtime baselines are secure configuration issues. |
| Recommendation — Harden container baselines and verify them against approved configurations. | ||
Practitioner Guidance
What to verify: Test one workload through the full path, from image build to live deployment, and confirm that the same controls remain effective after admission. A build scan is not enough unless the runtime policy, filesystem mode, capability set, and monitoring all line up with it.
Common mistake: Teams often validate only the image and then assume the orchestrator will “take care of” confinement. In practice, the weakest layer usually decides the outcome, so a secure image with a permissive runtime is still a risk.
Practitioner takeaway: The goal is to prove that the container cannot meaningfully expand its own authority after deployment, because that is where most real container failures become security incidents.
Related resources from NHI Mgmt Group
- How should organisations govern container security across build and runtime?
- How can security teams detect and contain a malicious Python dependency before it spreads across build and runtime systems?
- How should security teams contain an upstream software supply chain breach across build and runtime environments?
- How should security teams implement application security across build, deploy, and runtime phases?
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 25, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org