Integrating Security into Your CI/CD Pipeline
A short guide to adding automated security checks to each stage of your CI/CD pipeline, from pre-commit hooks to runtime, without slowing deployments.
By VVVHQ Team ·
A vulnerability found in production costs more to fix than one found in review: the code has to be traced, patched, retested and redeployed under pressure, and customers may already be exposed. Yet many teams still run security as a gate at the end of the release, where it slows deployments and arrives too late to change the design.
Shift-left security moves automated checks into the CI/CD pipeline, so each change is checked when it is made. This post is the short version, with tool choices per language and two configuration snippets. Our DevSecOps implementation guide covers blocking policies, metrics and rollout in more depth.
Where the checks go
Code → Commit → Build → Test → Deploy → Monitor
↓ ↓ ↓ ↓ ↓ ↓
IDE Pre- SAST DAST Policy Runtime
Scan commit SCA IAST Gates Protection
Secrets, before the commit lands
API keys, passwords and tokens get committed by accident more often than teams admit, and once pushed they live on in Git history. A pre-commit hook stops them on the developer's machine. gitleaks, TruffleHog and git-secrets all work. With the pre-commit framework, gitleaks takes four lines:
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.0 # pin to the current release
hooks:
- id: gitleaks
Run the same scanner again in CI, because hooks can be skipped.
Secrets can also break a deploy quietly on the way out of the pipeline. For one team, a typo in an updated Secrets Manager value broke the YAML parse of the generated Kubernetes Secret, and the service came up without its database variables and without any error. The same deploy script ignored the AWS CLI exit code, so a failed secret fetch would have deployed an empty secrets file instead of failing the pipeline. We fixed the secret, rolled the service, filed the script defect (a failed read must fail the deploy), and proposed moving shared values such as the Redis endpoint into one shared secret, so that each service's secret holds only its own keys. Any step that fetches secrets should fail closed.
Static analysis of the code
SAST reads source code without running it and finds patterns such as SQL injection, cross-site scripting and unsafe deserialization. Good choices per language:
| Language | Tools | |---|---| | JavaScript and TypeScript | eslint-plugin-security, Semgrep | | Python | Bandit, Semgrep | | Go | gosec, Semgrep | | Java | SpotBugs with Find Security Bugs, Semgrep | | Several languages | Semgrep (open-source core, custom rules) |
Run SAST on pull requests to keep the pipeline quick, block merges on critical and high findings, and warn on medium.
Dependencies
Most services contain more third-party code than code their own team wrote, and software composition analysis (SCA) checks it against known vulnerabilities. Snyk, Dependabot, Trivy, npm audit and pip-audit all do this. Trivy as a GitHub Actions step:
- name: Dependency scan
uses: aquasecurity/trivy-action@<commit-sha> # pin to a full commit SHA
with:
scan-type: 'fs'
severity: 'CRITICAL,HIGH'
exit-code: '1'
Pin third-party actions to a commit SHA rather than a branch such as master, so a compromised upstream branch cannot change what runs in your pipeline.
Container images
Every image needs a scan before it reaches production, for vulnerable OS packages in the base image, risky settings such as running as root or exposing extra ports, embedded credentials, and outdated packages. Use small base images such as Alpine or distroless, pin image versions instead of latest, block deployment on critical findings, and rebuild images regularly so base-image patches get in.
Infrastructure as code
Terraform, CloudFormation and Pulumi code defines most of your cloud security settings, and misconfiguration is behind many cloud breaches. Checkov scans Terraform, CloudFormation and Kubernetes manifests; trivy config covers Terraform (it absorbed tfsec); OPA with Rego handles rules specific to your organization. The usual catches are S3 buckets with public access, security groups open to 0.0.0.0/0 on sensitive ports, unencrypted databases and volumes, and missing logging.
Testing the running application
DAST tests a running application from the outside, the way an attacker would. Run it in staging after deployment and before promotion to production. OWASP ZAP is free and fits CI well, Nuclei is a fast template-based scanner, and Burp Suite suits manual testing.
Keeping the checks useful
Security checks that are slow, noisy or unclear get switched off. Keep pull request scans to a few minutes. Make every finding say what is wrong, why it matters and how to fix it. Block only on critical and high, warn on medium, and suppress known false positives. Let developers flag false positives, with security approving the exception. A security-minded developer in each team helps more than another tool.
Track time to remediate, the number of vulnerabilities found in production, the pipeline pass rate after tuning, and how developers rate the experience in a quarterly survey. The trend over a few quarters tells you whether the checks are working.
A first month
In week one, add secret scanning in pre-commit and CI. In week two, add dependency scanning with Trivy or Snyk. In week three, add Semgrep with its default rules. In week four, add container image scanning and IaC checks. Start with the checks that catch the most for the least friction and widen coverage from there.
Ask us to set these checks up in your pipeline, tuned so the team keeps them on.