Most breaches do not start with a zero-day. They start with a leaked API key in a commit, a dependency with a known CVE, or a container image full of unpatched packages. DevSecOps means catching those problems automatically, inside the delivery workflow, before they reach production. This guide turns an ordinary CI setup into a DevSecOps pipeline with four practical scanning layers: secrets, code, dependencies and images, and infrastructure as code.
The Four Scanning Layers
- Secret scanning searches commits for passwords, tokens, and private keys.
- SAST (static application security testing) analyzes your source code for dangerous patterns.
- Dependency and image scanning compares libraries and OS packages against vulnerability databases.
- IaC scanning checks Terraform, Kubernetes manifests, and Dockerfiles for misconfigurations such as public storage buckets or privileged containers.
The golden rule of a DevSecOps pipeline: fail the build on critical, fixable findings, warn on the rest, and give developers the exact file and line to fix. A scanner that blocks everything gets disabled within a week.
Layer 1: Secret Scanning with Gitleaks
Gitleaks scans Git history and working trees for secrets. Run it locally first to see what is already hiding in your repository:
docker run --rm -v "$(pwd)":/repo ghcr.io/gitleaks/gitleaks:latest detect --source /repo -v
In GitHub Actions, the official action runs on every push and pull request:
- name: Run Gitleaks
uses: gitleaks/gitleaks-action@v2
If Gitleaks finds a real credential, rotating it matters more than deleting the commit: once pushed, assume the secret is compromised. Pair scanning with pre-commit hooks so secrets are blocked before they ever enter history, which is the cheapest point in the whole DevSecOps pipeline to stop them.
Layer 2: SAST with Semgrep
Semgrep scans source code using pattern rules for many languages, catching issues such as SQL injection, unsafe deserialization, and weak cryptography:
pip install semgrep
semgrep scan --config auto .
The auto config pulls community rules matched to your languages and frameworks. In CI, run semgrep ci so results upload to Semgrep Cloud (optional) and the exit code reflects policy violations. Start with the default ruleset, review the noise level for two weeks, then promote the high-confidence rules to blocking.

Layer 3: Dependency and Container Scanning with Trivy
Trivy is a single binary that scans almost everything: lockfiles, container images, filesystems, and repositories. Try it against an image right now:
trivy image nginx:1.25
trivy fs .
The first command lists CVEs in the image’s OS packages and libraries; the second scans your project directory, including dependency lockfiles. In a pipeline, make critical vulnerabilities break the build while ignoring issues with no fix available yet:
- name: Scan image with Trivy
uses: aquasecurity/trivy-action@master
with:
image-ref: "myapp:${{ github.sha }}"
format: "table"
severity: "CRITICAL,HIGH"
ignore-unfixed: true
exit-code: "1"
If you build images with Docker, scan the exact image you are about to deploy, not a tag that might differ. Our Docker on Ubuntu 24.04 guide shows the build side of that workflow.
Layer 4: IaC Scanning with Checkov
Checkov reviews Terraform, CloudFormation, Kubernetes YAML, and Dockerfiles against hundreds of built-in policies:
pip install checkov
checkov -d . --framework terraform
Typical findings include unencrypted storage, security groups open to 0.0.0.0/0, and missing resource tags. Suppress a finding only with an inline justification comment, so exceptions stay visible in code review. Together with the other layers, this completes the DevSecOps pipeline from commit to deployed infrastructure.
Putting It Together: Pipeline Order and Policy
- Run secret scanning and SAST first; they are fast and catch cheap mistakes early.
- Build the application and its container image.
- Scan dependencies and the built image with Trivy.
- Scan IaC in the same repository before any plan or apply step.
- Publish reports as pipeline artifacts so failures are debuggable, and track trends: total criticals should trend to zero.
Troubleshooting Common Problems
The pipeline suddenly fails after a scanner update
New CVEs are published daily, so a green build can turn red without any code change. That is the system working. Triage the finding, patch or accept the risk with a dated exception, and never respond by removing the scanner.
Too many false positives
Tune per-repository: ignore files for test fixtures, baseline files for SAST, and severity thresholds per layer. Document every suppression with a reason and an expiry date.
Scans make CI too slow
Cache the vulnerability database, scan base images on a schedule instead of per commit, and parallelize the layers. A DevSecOps pipeline that developers bypass is worse than a slightly slower one they trust.
Rolling Out Scanning Without Slowing Teams Down
The social side decides whether a DevSecOps program survives. Introduce one scanner at a time in report-only mode, publish the results where developers already work (pull request comments beat dashboards nobody opens), and fix the backlog together before turning on blocking. Package the checks as a reusable workflow or shared CI template owned by the platform team, so fifty repositories improve by changing one file instead of fifty. Track two metrics publicly: percentage of pipelines with scanning enabled, and mean time to remediate critical findings. Celebrate teams that drive their numbers down. For supply-chain depth, add SBOM generation with Syft and image signing with Cosign once the basics stick; both build naturally on the Trivy step you already run. Security that arrives as helpful automation gets adopted. Security that arrives as a surprise gate gets routed around.
Conclusion
A DevSecOps pipeline is not a product you buy; it is four habits wired into CI: scan secrets with Gitleaks, scan code with Semgrep, scan dependencies and images with Trivy, and scan infrastructure code with Checkov, failing builds only on critical, fixable findings. Start with one layer this week, tune it until the team trusts it, then add the next. For scanner configuration details and advanced usage, the Trivy official documentation is an excellent reference, and combining these checks with the monitoring stack from our Prometheus and Grafana guide gives you security visibility before and after deployment.