Safeguard
Security Guides•

Where should a security scan run in container-based CI?

In container-based CI, run scans as their own job on a fresh runner, with the build artifact as input. Here is why and how to place each type of scan.

Safeguard Security Team
4 min read

Run scans as separate jobs on fresh runners, fed by the build output, rather than as extra steps inside the build container. A separate job gets only the access a scan needs, fails independently, and can be required by policy. Keep source level scans early and image scans after the image is built.

The three placements

  1. Inside the build container. Simple, but the scanner shares the filesystem, credentials and tools of the build. A compromised build step can alter scanner config or output.
  2. A separate job in the same pipeline. The scan starts on its own runner, pulls the artifact or image by digest, and reports pass or fail. This is the usual fit.
  3. A sidecar or external service. Useful for long running monitoring, such as rescanning a registry, but not a replacement for a gate on the change.

Which scan goes where

Scan typeInputBest placement
Dependency scan and SBOMLockfiles and manifestsEarly job, runs in parallel with the build
Static code analysisSourceEarly job on the pull request
Container image scanBuilt image by digestAfter the build, before promotion
API or web scan against a running appA deployed test instanceLater job in an isolated environment
Registry rescanImages already publishedScheduled, outside the pipeline

Why separate jobs help in an ephemeral setup

Each job starts clean, so a scan cannot be skewed by leftovers from the build. The scan job also needs fewer secrets, usually none beyond read access to the artifact. And a required job can be enforced by branch rules, which an in-build step cannot.

One caution: scanners rely on vulnerability data. A fresh runner starts with whatever database the image or cache holds, so a stale one can report clean results for known issues. Stale vulnerability data in CI scan caches and ephemeral runners explains how to refresh it.

Steps to set this up

  1. Have the build job publish the image or artifact and output its digest.
  2. Start the scan job with that digest as input, never a moving label.
  3. Give the job read only access to the artifact and no deploy credentials.
  4. Fail the job on the policy you have agreed, and require it before merge or promotion.
  5. Store the report with the build record so it can be retrieved later.
  6. Schedule a separate rescan of published images, since new advisories appear after the build.

What a gate should decide

Blocking on every finding stalls delivery, so pick thresholds on severity, whether a fix exists and whether the vulnerable code is reachable. Revisit them after a month of real results.

Try it yourself

Click through it at your own pace, or open it full screen.

Click through a scan and look at what the report ties each finding to, since that is the data a gate would act on.

Safeguard supports container image scanning, reachability analysis and policy gates in CI, and you can try a free scan at gold.safeguard.sh/scan.

Quick check

Is one combined scan step simpler and good enough?

For a small team it can be a start. As soon as the pipeline holds deploy credentials, separate the scan so it cannot be influenced by the build.

Do I still need a registry scan if I scan in CI?

Yes. CI scans a moment in time. A registry rescan catches advisories published later.

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.