Docker image security is a release workflow, not a single scan. This checklist shows how to move from trusted source code and base images to scanned, signed, policy-controlled images in production, with practical checks for registries, Kubernetes clusters, and remediation.
Overview
A container image bundles application code, operating-system packages, language dependencies, configuration defaults, and metadata. That convenience also creates a supply-chain boundary: a vulnerable package, leaked secret, untrusted base image, or tampered artifact can travel through CI/CD and reach production.
A reliable Docker image security workflow separates the problem into several controls:
- Build from trusted inputs. Use approved base images, pin important dependencies, and keep the Dockerfile understandable.
- Inspect the contents. Scan operating-system packages, application dependencies, configuration, and secrets.
- Describe the artifact. Generate a software bill of materials (SBOM) so teams can identify what is inside an image.
- Prove its origin. Sign the image and preserve build metadata where your tooling supports it.
- Control distribution. Restrict registry access, prefer immutable references, and separate build, staging, and production permissions.
- Enforce deployment rules. Require approved registries, signatures, scan results, and non-root settings where appropriate.
- Respond consistently. Define severity-based remediation targets and a process for exceptions.
Scanning does not make an image safe by itself. A finding must be interpreted in context, assigned to an owner, fixed or accepted with a documented reason, and checked again after the image is rebuilt. The same workflow should apply whether images run on a managed Kubernetes service, a self-managed cluster, or a simpler container platform.
Checklist by scenario
1. Before writing or changing a Dockerfile
- Choose a base image from a registry and publisher your team has reviewed.
- Use a minimal runtime image when it remains compatible with debugging and operations. Do not remove required tooling blindly.
- Pin the base image by a digest when reproducibility and change control are important. A human-readable tag can remain in documentation, but a digest identifies a specific artifact.
- Use multi-stage builds so compilers, package managers, tests, and source files do not enter the runtime image unnecessarily.
- Run the application as a non-root user unless there is a documented operational reason not to.
- Keep secrets out of Dockerfiles, build arguments, image labels, source archives, and environment defaults. Build arguments can be exposed through build history and should not be treated as secret storage.
- Review package installation commands for unsafe downloads, unverified archives, and unnecessary privileges.
- Record ownership for the Dockerfile, base image, dependency files, and release pipeline.
A simple multi-stage pattern might look like this:
FROM approved-builder:version AS build
WORKDIR /src
COPY package*.json ./
RUN install-dependencies
COPY . .
RUN build-application
FROM approved-runtime:version
USER 10001
COPY --from=build /src/dist /app
ENTRYPOINT ["/app/service"]
The exact commands depend on the language and builder. The security objective is to make the final stage contain only what the service needs to run.
2. During development and pull requests
- Run a fast dependency and secret scan before an image is built or published.
- Scan the built image as part of pull-request or branch validation. This catches packages introduced by the build process, not just files visible in the repository.
- Fail automatically on credentials, private keys, and other high-confidence secret findings.
- Review critical and high-severity findings before merging. Define whether a finding blocks the change, requires an exception, or can be tracked for later remediation.
- Test the image as the same user and with the same entrypoint used in deployment.
- Generate an SBOM and retain it with the build record or registry artifact.
Use a scanner in two modes: a quick developer-friendly check for feedback and a fuller CI check for the release candidate. This reduces friction without treating the shorter check as the final security decision.
3. At the CI/CD release boundary
- Build from a clean, controlled runner rather than reusing an untrusted workspace.
- Authenticate to the registry with short-lived or narrowly scoped credentials. Avoid embedding registry passwords in workflow files.
- Scan the exact image digest that will be pushed or deployed.
- Generate an SBOM for that digest, not merely for the source repository.
- Attach provenance or build metadata when your build system supports it and your team can verify it.
- Sign the image after the required checks pass. Keep signing keys in an appropriate protected key system or use a keyless approach that matches your identity and audit requirements.
- Promote the verified artifact between environments instead of rebuilding different images for staging and production.
For a digest-based workflow, the sequence is generally: build, scan, generate the SBOM, publish or identify the immutable digest, sign that digest, verify the signature, and then promote it. The exact command syntax varies by registry and signing implementation, so validate commands against the versions deployed in your environment.
4. In the container registry
- Require authentication and assign separate read, write, delete, and administration permissions.
- Give CI only the permissions it needs for the repositories it builds.
- Protect production repositories from arbitrary pushes and tag deletion.
- Prefer immutable digests in deployment configuration. Treat mutable tags such as
latestas convenience labels, not release identities. - Enable registry audit logs and review unusual pushes, deletions, permission changes, and access from unexpected identities.
- Define retention rules that preserve production artifacts, signatures, SBOMs, and investigation evidence for the period your team requires.
- Use repository namespaces to distinguish approved, experimental, and third-party images.
5. Before deploying to Kubernetes
- Allow images only from approved registries and repositories.
- Require a digest or an approved signed image for sensitive workloads.
- Reject images with prohibited severity findings unless an authorized exception exists.
- Set a security context appropriate to the application, including non-root execution, a read-only root filesystem, dropped Linux capabilities, and a restricted privilege model where compatible.
- Use admission policy to make these requirements consistent across namespaces.
- Check that service accounts, image-pull secrets, and workload identities have only the required access.
An admission policy conceptually expresses rules such as:
deny if image.registry not in approved_registries
deny if image is not signed by approved_identity
deny if image reference has no digest
deny if workload requests privileged execution
warn or deny if vulnerability threshold is exceeded
The syntax depends on the policy engine and Kubernetes distribution. Start in audit or warning mode where possible, measure violations, then enforce rules after teams have a documented migration path.
6. After a vulnerability is reported
- Identify affected image digests, tags, services, clusters, and environments.
- Confirm whether the finding is present in the deployed image rather than only in a source branch or unused layer.
- Check exploitability, runtime exposure, package reachability, and compensating controls before assigning priority.
- Update the base image or dependency, rebuild, rescan, regenerate the SBOM, and sign the replacement.
- Redeploy by digest and retire the affected artifact where operationally safe.
- Document accepted risk with an owner, reason, expiration date, and follow-up condition.
Tool comparison
Tools overlap, and product capabilities change. Select based on the systems you already operate, the formats you need, identity integration, policy support, and how findings reach developers.
| Control | Common tool categories | What to evaluate |
|---|---|---|
| Image and dependency scanning | Registry-native scanners, CI scanners, open-source vulnerability scanners | OS and language coverage, severity logic, ignore rules, pull-request integration, export formats |
| Secret detection | Repository scanners, CI secret scanners, pre-commit checks | Credential patterns, false-positive handling, history scanning, revocation guidance |
| SBOM generation | Image inspectors, build plugins, SBOM generators | Supported formats, layer accuracy, attachment to image digests, downstream ingestion |
| Image signing | Signing and verification tools, registry-native signing, keyless identity systems | Key protection, identity policy, registry compatibility, offline verification, auditability |
| Deployment enforcement | Kubernetes admission controllers and policy engines | Audit mode, exception workflows, digest and signature checks, policy testing, operational visibility |
What to double-check
- Scanner scope: Confirm that the scan covers both operating-system packages and application dependencies. A clean result from one category does not imply a clean result from the other.
- Image identity: Match scan results, SBOMs, signatures, deployment records, and incident reports to the same digest.
- Suppression rules: Every ignored finding should have a reason, owner, review date, and narrow scope. Avoid global ignore patterns that hide future findings.
- Base-image updates: Establish who watches for updates and how often supported images are rebuilt, even when application code has not changed.
- Runtime settings: An image may be well scanned but still run with excessive privileges, host access, or a powerful service account.
- Key and identity separation: Do not let the same credential build, sign, publish, and deploy without additional controls. Separation limits the impact of a compromised pipeline.
- Exception handling: Make exceptions visible to security, platform, and service owners. An exception should not silently become the default policy.
- Operational recovery: Ensure teams can roll back to a known-good signed digest and can identify which workloads use a vulnerable artifact.
Common mistakes
- Relying on tags alone. Tags can be moved or reused. Use digests for release identity and verify them during deployment.
- Scanning only the Dockerfile. The final image can contain transitive packages and generated files that are not obvious from the Dockerfile.
- Treating every finding as equally urgent. Use severity as an input, then consider exposure, reachability, exploitability, and business context.
- Signing too early. Sign the release candidate after required scans and checks, not an intermediate image that will later change.
- Keeping secrets in deleted layers. Removing a secret in a later layer may leave it recoverable from image history. Rotate exposed credentials and rebuild from a clean history.
- Building separately for each environment. Rebuilding can produce different dependencies. Promote the tested artifact whenever the deployment model permits.
- Enforcing policy without an adoption path. Begin with inventory and audit results, then address the highest-risk violations before switching to blocking mode.
When to revisit
Use this workflow before every production image release and whenever a base image, package lockfile, build runner, registry, signing method, or Kubernetes policy changes. Revisit it immediately after a vulnerability disclosure that affects your images, a suspected credential exposure, a registry permission change, or a supply-chain incident.
During quarterly or seasonal planning cycles, review the complete inventory of deployed image digests, stale tags, signing identities, registry permissions, exception records, and remediation performance. Test whether a responder can answer three questions quickly: which workloads use an affected digest, who approved that artifact, and how can a known-good replacement be deployed?
As a final release gate, confirm:
- The image uses approved inputs and contains no unresolved secret findings.
- Vulnerability findings have been fixed, accepted, or assigned according to your remediation policy.
- An SBOM is available for the exact image digest.
- The digest is signed and verification succeeds using the production trust policy.
- The registry permissions and deployment identity are appropriately limited.
- Kubernetes admission checks will accept the image for the intended namespace and workload.
- The team can identify, roll back, and replace the artifact if a new issue appears.
Keep the checklist with the release process, not in a separate document that engineers rarely consult. Container image security works best when the evidence and decisions travel with each artifact from build to deployment.