Secure Pipeline — Security-First CI/CD with DefectDojo & SonarQube

Case Study
SecurityCI/CDDevSecOpsGitHub ActionsTerraformAWSSonarQubeDefectDojo

Security-first CI/CD pipeline that integrates Gitleaks, Bandit, Trivy, Syft, and SonarQube into GitHub Actions, with automated result aggregation in DefectDojo. Infrastructure provisioned via Terraform on AWS EC2.

Overview

A security-first CI/CD pipeline that runs eight stages of automated security scanning on every push, aggregates all findings in DefectDojo, and integrates with SonarQube for code quality analysis. The entire infrastructure is provisioned via Terraform on AWS EC2 — free-tier eligible.

Pipeline Stages

StageToolWhat It Finds
Stage 1GitleaksHardcoded secrets, API keys, passwords
Stage 2BanditPython security bugs (eval, injection, unsafe calls)
Stage 3Trivy FSVulnerable dependencies, misconfigurations
Stage 4Docker BuildContainer image build
Stage 5Trivy ImageOS-level CVEs in container layers
Stage 6Syft SBOMCycloneDX software bill of materials
Stage 7SonarQubeCode quality bugs, security hotspots
Stage 8DefectDojoAggregates all findings in one dashboard

Architecture

Push code → GitHub Actions CI → Gitleaks + Bandit + Trivy + Syft + SonarQube
                                     ↓
                               EC2 (DefectDojo :8080, SonarQube :9000)

Infrastructure

A single AWS EC2 instance (t2.micro, free-tier) hosts both DefectDojo and SonarQube via Docker Compose, provisioned entirely through Terraform. The CI pipeline connects to this instance using repository secrets.

  • Terraform — Provisions EC2, security groups, and SSH access
  • Docker Compose — Runs DefectDojo + SonarQube + PostgreSQL
  • GitHub Actions — Triggers on push, runs all scanners, uploads results
  • Dependabot — Automatic dependency update PRs

Key Features

  • SAST + SCA + Secrets: Covers static analysis, software composition analysis, and secret detection in a single pipeline
  • SBOM Generation: Syft produces a CycloneDX bill of materials for supply chain transparency
  • Centralized Dashboard: DefectDojo aggregates findings from all tools into one view
  • SonarQube Integration: Bandit results are imported into SonarQube security tab alongside quality metrics
  • Free-Tier: Entire infrastructure runs within AWS Free Tier (~$10/month)

Tools Breakdown

Bandit

Python security linter that scans source code for common vulnerabilities: SQL injection, unsafe eval/exec, hardcoded passwords, and insecure file permissions. Results go to both DefectDojo and SonarQube.

Gitleaks

Scans git history and working tree for hardcoded secrets before they reach the repository. Configured via .gitleaks.toml with custom allowlists and regex patterns.

Trivy

Three-in-one scanner: filesystem scanning for dependency vulnerabilities (requirements.txt), secret scanning for exposed keys, and container image scanning for OS-level CVEs.

DefectDojo

The central aggregation point. Instead of checking five separate reports, all findings from every scanner are uploaded to DefectDojo's single dashboard for triage and tracking.