How to Integrate Security Into Your CI/CD Pipeline: A DevSecOps Implementation Guide

A stage-by-stage guide to integrating security into your CI/CD pipeline without slowing deployments, with tool choices, build policies and a 30-day rollout.

By VVV Ops ·

A pipeline that ships to production in ten minutes, paired with a penetration test once a quarter, leaves a long window. A SQL injection merged on Monday can be live for months before the test finds it.

Running security checks inside the CI/CD pipeline, usually called shift-left security or DevSecOps, closes most of that window. The checks run on every change, and the developer sees the result while the change is still open. Set up badly, the same checks slow every build, flood developers with false positives and teach the team to work around CI. This guide covers the stages, the tools for each and the policies that keep the checks useful.

The pipeline at a glance

Each stage is an automated check with a clear rule for what blocks the build and what only warns:

  ┌─────────┐   ┌───────┐   ┌──────┐   ┌──────┐   ┌─────────┐   ┌──────┐   ┌─────┐
  │ Pre-    │   │  PR   │   │ SAST │   │ SCA  │   │ Secrets │   │ IaC  │   │ DAST│
  │ commit  │──▶│ Review│──▶│  +   │──▶│ Deps │──▶│  Scan   │──▶│ Scan │──▶│ Post│
  │ hooks   │   │  Bot  │   │ Lint │   │      │   │         │   │      │   │Deploy│
  └─────────┘   └───────┘   └──────┘   └──────┘   └─────────┘   └──────┘   └─────┘
       │            │          │          │           │            │         │
       ▼            ▼          ▼          ▼           ▼            ▼         ▼
    Seconds      Minutes    Minutes    Seconds     Seconds      Seconds   Minutes+
                (async)    (block)    (block)     (block)     (block)    (warn)

The order and the blocking rules decide whether engineers accept the pipeline or route around it.

The seven stages

1. Pre-commit hooks for secrets

The aim is to stop credentials before they reach the Git server. A pre-commit hook that scans for secrets is cheap to install and stops the most common leak, a key pasted into a config file, on the developer's machine.

Tools: the pre-commit framework with gitleaks (fast, regex plus entropy), detect-secrets (entropy-based, mature) or TruffleHog (can check whether a found credential is live).

Block the commit. The hook runs locally, so a developer with a genuine false positive can add it to the allowlist. Run it in audit mode for one sprint first, clear the existing findings, then switch it to blocking.

2. Findings in the pull request

Findings should appear as comments in the pull request, on the line that caused them, with a short explanation and a suggested fix. That works far better than a dashboard nobody opens.

Tools: GitHub Advanced Security if you are already on GitHub Enterprise, Semgrep for custom rules with few false positives, or Snyk, Checkmarx and SonarQube on other platforms.

Warn at this stage and do not block yet. The goal is to earn the team's trust. Once the findings are reliable, move the most important rules into the blocking SAST stage.

3. SAST: static analysis of the code

SAST tools read the source code for vulnerable patterns: SQL injection, cross-site scripting, unsafe deserialization, hardcoded secrets, misused cryptography. Run them on every push.

For most SaaS codebases, our order of preference:

  1. Semgrep. Fast, open-source core, good custom rules. Our first choice for most teams.
  2. CodeQL. Free for public repositories, strong on data-flow analysis, and slower.
  3. SonarQube. Combines code quality and security.
  4. Checkmarx, Veracode or Fortify. Expensive and slow; we use them when a customer or auditor requires one.

Block on high and critical findings, warn on medium, and log low and informational ones. Expect the first month to be noisy and tune the rules as you go. Semgrep usually finishes in a few minutes; CodeQL can take much longer on a large codebase, so run it in a separate cached workflow outside the main pull request check.

4. SCA: vulnerable dependencies

A typical service built on npm, PyPI, RubyGems or Maven contains far more third-party code than code its own team wrote. SCA tools compare the dependency tree with public vulnerability databases such as the CVE list and the GitHub Advisory Database.

Tools: GitHub Dependabot (free and built in, a good start), Snyk (paid, good developer experience), Trivy (free, also scans container images) or OWASP Dependency-Check.

Block on critical CVEs with a known exploit and warn on the rest. Include transitive dependencies, because serious vulnerabilities often sit several levels down. Do not block on a CVE that has no fixed version yet: the developer cannot do anything about it, and blocking only encourages bypasses. Track those separately.

5. Secrets scanning on the server

Pre-commit hooks miss some secrets. Not everyone has the hooks installed, --no-verify skips them, and old branches get merged. A server-side scan catches what got through.

Tools: GitHub secret scanning (free on public repositories, part of GitHub Secret Protection for private ones), gitleaks in CI, or TruffleHog.

Block the merge. A detected secret is rotated straight away; removing it from the commit is not enough, because it stays in Git history and in every clone.

6. IaC scanning before apply

A public S3 bucket or a security group open to the internet is the kind of mistake that ends up in breach reports. Scan Terraform, CloudFormation, Kubernetes manifests and Helm charts the same way you scan application code.

Tools: Checkov for broad coverage, trivy config (which now includes the former tfsec checks) for Terraform, kube-score or Polaris for Kubernetes manifests, and Open Policy Agent with Conftest for your own organization's rules.

Block on violations that are clearly wrong, such as public buckets, open security groups or missing encryption, and allow documented exceptions. Run the same checks against the terraform plan output as well, which also shows changes made outside the code.

7. DAST against the running application

DAST tools send hostile HTTP requests to a deployed application: malformed input, injection payloads, authentication tests. They find problems SAST cannot see, such as runtime configuration, broken authorization and session handling.

Tools: OWASP ZAP (free, easy to automate, good baseline scans), Burp Suite Enterprise (commercial, deeper) or StackHawk (built for CI/CD).

Run it against a dedicated staging environment after each deploy, in parallel with other post-deploy steps. Warn, do not block, and have a person triage critical findings before they become urgent tickets.

Setting build policies the team will accept

When DevSecOps fails, it is usually because the checks are so noisy that engineers bypass them, not because there are too few of them.

  1. Start every new scanner in warn mode for a sprint. Tune the rules, suppress false positives and set thresholds from what you see.
  2. Block only on findings you are confident about and that matter: critical CVEs with known exploits, confirmed secrets, injection in code that handles user input.
  3. Give every scanner an exception process. A team lead can waive a finding with a written reason, and the waiver expires after 90 days.
  4. Fix or remove any tool that produces more false positives than real findings.
  5. Watch pipeline duration at the 95th percentile. If a new check adds several minutes, parallelize it, cache it or move it out of the blocking path.

Metrics worth tracking

  • Time to remediate critical vulnerabilities, from detection to deployed fix.
  • Escape rate: how many vulnerabilities reach production compared with how many CI catches.
  • False positive rate per scanner, measured as waived or dismissed findings over all findings.
  • Pipeline time added by security checks.
  • Open waivers and their age.

Totals such as "vulnerabilities scanned" say little about risk and are not worth reporting.

A 30-day rollout

| Week | Work | |---|---| | 1 | Pre-commit secret hooks. Dependabot or Snyk for dependencies. gitleaks in CI in warn mode. | | 2 | Semgrep and Checkov or trivy config in warn mode. A weekly triage meeting for the first month. | | 3 | Tune rules from real findings. Switch secrets scanning and the most reliable SAST rules to blocking. | | 4 | ZAP baseline scan after deploy, in warn mode. Review the first month's metrics and write the policy down. |

After a month the pipeline has owners, findings people trust and little friction. Keep tuning from there.

Mistakes we see often

  • Starting with an enterprise SAST suite. Semgrep and Dependabot are free and fast, and they show whether the process works.
  • Blocking on everything, which gets the pipeline bypassed.
  • Putting DAST in the pull request check, where it is too slow.
  • Treating waivers as permanent. Each one needs an expiry date and a review.
  • Leaving it to the security team alone. Security sets the policy; engineers build and maintain the pipeline.
  • Skipping pre-commit hooks, the cheapest control on this list.

For a regulated medical-device platform we built CI/CD for more than 25 repositories, with SAST and SBOM generation in the pipelines. If you want the same kind of setup in your own CI, tuned so the team keeps it switched on, tell us about your stack and how often you release. The OWASP DevSecOps Guideline, NIST's SSDF and SLSA are good references for the policy side.

Tags: integrate security into ci/cd pipeline, devsecops implementation, shift-left security, sast dast integration, ci/cd security scanning, secure software development lifecycle