Automating Image Security: Integrating Trivy Scanning in Harbor
Learn how to integrate Trivy with Harbor to automate container vulnerability scanning, block critical CVEs, and secure your CI/CD pipeline.
20 Jan 2026, 06:53 UTC

The Risk of the "Blind Push"
In a typical CI/CD pipeline, pushing a container image to a registry is often the final step before deployment. However, pushing an image without knowing its contents is a security blind spot. If a base image contains a critical vulnerability (CVE), you are essentially deploying a known risk into your production environment.
The goal is to move security "left" by integrating vulnerability scanning directly into the registry. By using Harbor with the Trivy adapter, you can ensure that every image is analyzed the moment it hits the registry, preventing vulnerable artifacts from ever reaching your orchestrator.
How Harbor Leverages Trivy
Harbor acts as the management layer, while Trivy serves as the scanning engine. Trivy is a comprehensive scanner that analyzes container images for OS package vulnerabilities and language-specific dependencies. When integrated, Harbor triggers Trivy to perform a static analysis of the image layers without needing to run the container.
This integration provides three primary capabilities:
- Scan on Push: Automatically triggers a vulnerability check as soon as an image is uploaded.
- Scheduled Scanning: Periodically re-scans existing images to catch "day-zero" vulnerabilities that were discovered after the image was first pushed.
- Deployment Blocking: Harbor can be configured to prevent the pulling of images that exceed a specific severity threshold (e.g., blocking any image with "Critical" vulnerabilities).
Configuration and Deployment
To use the built-in Trivy adapter, you must be running Harbor version 2.2 or later. You can verify your version by running the following command on the host where Harbor is deployed:
docker exec harbor-core harbor version
Once verified, the scanner is enabled via the harbor.yml configuration file. Ensure you have administrative permissions on the host machine to modify this file and restart the services.
Example: Enabling the Scanner
In your harbor.yml, locate the scanner section. A standard configuration for Trivy looks like this:
# Example harbor.yml snippet
scanner:
trivy:
# The path to the trivy executable or the image used for scanning
image: aquasec/trivy:latest
After updating the configuration, apply the changes by running the Harbor install script (usually ./install.sh) to restart the containers. This ensures the harbor-trivy container is deployed and linked to the core service.
Verifying the Scan Workflow
- Push a test image to a project:
docker push harbor.example.com/my-project/myapp:v1. - Log into the Harbor UI and navigate to Projects > [Your Project] > Repositories > myapp.
- Click on the
v1tag. Under the Vulnerabilities tab, you should see a list of CVEs, their severity levels, and whether a fix is available. - If the scan does not appear, check the logs on the Harbor host:
tail -f /var/log/harbor/trivy.log. Look for the entry"Trivy scan completed".
Performance Trade-offs and Limitations
Integrating a scanner is not "free" in terms of system resources. There are two primary constraints to consider:
| Constraint | Impact | Mitigation |
|---|---|---|
| Push Latency | Scanning adds CPU and I/O overhead, potentially delaying the "push complete" signal by seconds or minutes. | Disable "Scan on Push" for development projects and rely on scheduled scans. |
| Network Dependency | Trivy must download the latest vulnerability database from the internet to be effective. | In air-gapped environments, you must mirror the Trivy DB to a local source or use a cached version. |
Actionable Closing
To secure your pipeline, start by enabling Trivy in a single non-production project. Once you have a baseline of your image vulnerabilities, implement a Deployment Security policy in the project settings to block images with "Critical" vulnerabilities. This transforms your registry from a passive storage bin into an active security gate.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.