Deploying DefectDojo on Docker: Centralized Vulnerability Management and Automated Report Aggregation

Security tutorial - IT technology blog
Security tutorial - IT technology blog

Context & Why: The Pain of Fragmented Vulnerability Reports

Most CI/CD pipelines run an alphabet soup of security tools. Trivy or Grype inspects container images. Semgrep checks source code. OWASP ZAP probes running APIs, while npm audit flags vulnerable libraries. Generating these scans is easy. Making sense of their output across thirty repositories is an operational nightmare.

Without a central hub, engineers drown in raw SARIF artifacts, 20 MB JSON dumps, and disjointed PDF summaries scattered across build logs. A few recurring bottlenecks always pop up when scaling pipeline security:

  • Duplicate Findings: The same vulnerable base image dependency gets flagged across 50 builds a day, inflating vulnerability counts and obscuring new risks.
  • Zero Central Visibility: Engineering leads cannot see overall system posture without manually stitching together reports from five different dashboards.
  • Triage Fatigue: False positive suppressions and risk acceptances end up buried in Jira tickets or stale spreadsheets instead of staying linked to the codebase.

DefectDojo cuts through this chaos. This open-source management platform ingests results from more than 150 scanners, normalizes the data, and deduplicates identical issues across branches. It also tracks the full remediation lifecycle from initial commit to production patch. Running it on Docker Compose delivers a reliable production stack complete with Celery task queues, Redis caching, and PostgreSQL.

Installation: Deploying DefectDojo via Docker Compose

Under the hood, DefectDojo decouples responsibilities across several services: an Nginx proxy, a Django uWSGI web app, Celery workers for background parsing, Celery Beat for scheduled routines, Redis for brokering tasks, and PostgreSQL for storage. The official Docker Compose setup wires these components together out of the box.

1. Host Prerequisites

You need a standard Linux host (such as Ubuntu 22.04 LTS or Rocky Linux 9) with Docker Engine and the Compose plugin installed. Parsing massive scanner outputs demands decent memory. Allocate at least 4 GB of RAM for lightweight hobby stacks, but bump that to 8 GB and 4 vCPUs if your teams regularly upload 50+ MB SARIF files.

# Verify Docker and Compose installations
docker --version
docker compose version

2. Clone the Repository and Prepare Environment Variables

Fetch the repository directly from GitHub. Check out an official release tag instead of running unpinned code from main:

git clone https://github.com/DefectDojo/django-DefectDojo.git
cd django-DefectDojo

# Checkout a stable release tag
git checkout 2.38.1

Next, initialize your environment configuration. The repository provides sample profiles inside docker/environments/. Always replace default passwords and secrets before launching containers in shared infrastructure.

For credentials, use strong entropy. The browser-based generator at toolcraft.app/en/tools/security/password-generator creates secure server passwords client-side without transmitting plain text over the network. Generate 32-character alphanumeric strings for POSTGRES_PASSWORD, DD_DATABASE_PASSWORD, and DD_SECRET_KEY.

# Copy the default PostgreSQL + Redis profile
cp docker/environments/postgres-redis.env .env

# Configure custom secrets and host settings
nano .env

Confirm these key parameters inside your .env file:

DD_SECRET_KEY=c3f91a82d4e740b28e6c71a39f02b1584e021a9c84e14f9da761b34e56cd8912
POSTGRES_PASSWORD=f78a2e19b3cd4691a02e5891d4e32a67
DD_DATABASE_PASSWORD=f78a2e19b3cd4691a02e5891d4e32a67
DD_URL_PREFIX=
DD_ADMIN_USER=admin
[email protected]

3. Build and Start the Containers

Bring up the services in detached mode:

# Pull images and start containers in the background
docker compose -f docker-compose.yml up -d

During the first startup, an initializer container runs database migrations, creates schema tables, and populates baseline permission sets. This step typically takes 2 to 4 minutes depending on your storage I/O throughput.

4. Retrieve the Initial Admin Password

If you did not define a static admin password in your environment file, DefectDojo generates a temporary one. Grab it directly from the initializer container log:

docker compose logs initializer | grep "Admin password:"

Open your browser and navigate to http://<your-server-ip>:8080. Log in using admin and your generated secret. Head straight to the user profile icon in the top-right corner to reset the password and enable two-factor authentication (2FA).

Configuration: Structuring Assets and Integrating Scanners

Avoid dumping raw scans into DefectDojo immediately. Take five minutes to map your infrastructure into its logical structure first.

1. Define the Core Hierarchy

DefectDojo groups vulnerabilities into three distinct tiers:

  1. Product Type: Broad organizational buckets, such as "Customer APIs", "Internal Tooling", or "Edge Firmware".
  2. Product: The target system or service (for instance, "Billing Engine").
  3. Engagement: The operational testing window, like "Sprint 34 CI Pipeline" or "Annual External Pentest".

Create a Product Type and Product via the web console under Products > Add Product, or automate this creation step through the REST API.

2. Automate Report Ingestion via API

Manual file uploads through the UI defeat the purpose of automation. DefectDojo exposes an extensive v2 REST API for pipeline integration. Generate a personal token under User Profile > API v2 Key.

Here is an example Bash script suitable for GitHub Actions, GitLab CI, or Jenkins. It runs Trivy against a local Docker image, exports a JSON report, and uploads it to an existing engagement:

#!/usr/bin/env bash
set -euo pipefail

DEFECTDOJO_URL="http://defectdojo.internal:8080"
API_TOKEN="9a8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b"
ENGAGEMENT_ID=3
IMAGE_TAG="billing-service:2.4.1"
REPORT_FILE="trivy-report.json"

# 1. Run Trivy vulnerability scan and write JSON output
trivy image --format json --output "${REPORT_FILE}" "${IMAGE_TAG}"

# 2. Push results directly into DefectDojo
curl -X POST "${DEFECTDOJO_URL}/api/v2/import-scan/" \
  -H "Authorization: Token ${API_TOKEN}" \
  -H "accept: application/json" \
  -F "engagement=${ENGAGEMENT_ID}" \
  -F "scan_type=Trivy Scan" \
  -F "file=@${REPORT_FILE}" \
  -F "active=true" \
  -F "verified=true" \
  -F "close_old_findings=true" \
  -F "deduplication_on_engagement=true"

The close_old_findings=true flag is crucial. When a developer upgrades a vulnerable package, the next pipeline run marks previous CVE alerts as mitigated automatically. No manual ticket scrubbing required.

3. Tuning Deduplication Settings

Deduplication prevents alert fatigue. Head over to Configuration > System Settings and scroll to the Deduplication section. You can match incoming reports against existing records using:

  • Vulnerability ID (CVE/CWE): Ideal for SCA and container tools like Trivy, Grype, and Snyk.
  • File Path and Line Number: Best for static analysis tools like Semgrep or SonarQube.
  • Endpoint URL and HTTP Method: Well-suited for DAST scanners like OWASP ZAP.

Enabling Deduplicate findings keeps dashboards legible. Instead of spawning 30 identical tickets for Log4j across thirty builds, DefectDojo links each recurrence to the original finding.

Verification & Monitoring: Validating Ingestion and System Health

Once your pipelines start posting data, verify that background ingestion queues keep pace with incoming builds.

1. Check Container Health and Service States

Verify that your services run cleanly:

docker compose ps

Confirm all six core containers report an Up or healthy status:

  • nginx-1: Reverse proxy listening on port 8080 and terminating requests.
  • uwsgi-1: Core Django backend serving API calls and web pages.
  • celery-worker-1: Asynchronous background worker parsing file uploads.
  • celery-beat-1: Periodic task scheduler for alerts and cleanup routines.
  • redis-1: In-memory queue handling task dispatching.
  • postgres-1: Relational database holding asset and vulnerability state.

2. Monitoring Celery Queue Ingestion

When an uploaded report takes more than 10 seconds to appear in the UI, Celery is likely churning through a backlog. Stream worker logs to catch ingestion bottlenecks or schema parsing failures:

# Tail worker activity live
docker compose logs -f celery-worker

A successful import logs an event like this:

[INFO/ForkPoolWorker-2] Task dojo.tasks.async_import_scan[89e4c1...] succeeded in 1.42s: Imported 18 findings.

3. Verifying Ingested Findings in the UI

Open Findings > All Findings in the web dashboard. Perform three sanity checks:

  • Confirm severity breakdowns (Critical, High, Medium, Low) align with your scanner output.
  • Look for the small Duplicate tag on recurring issues.
  • Inspect resolved vulnerabilities to ensure their status switched from Active to Inactive.

4. Routine Maintenance and Database Backups

DefectDojo stores your team’s historical risk decisions and compliance records. Guard that data with scheduled PostgreSQL dumps. Run a manual snapshot to confirm connectivity:

# Verify database export
docker compose exec -T postgres pg_dump -U defectdojo defectdojo > /var/backups/defectdojo_$(date +%F).sql

Add a host cron job (such as 0 2 * * *) to dump, compress with gzip, and ship snapshots to remote S3-compatible object storage. Watch host disk utilization closely. Large SARIF files and continuous pipeline logs can consume 10 to 20 GB of storage within a few months if left unpruned.

Share: