Trivy Security & Compliance
Trivy is a comprehensive and versatile security scanner deeply integrated into the Kreate ecosystem. This integration enables developers to embed security checks directly into the build process, facilitating a "Shift Left" approach to identify vulnerabilities and compliance issues as early as possible.
In Kreate, the Trivy integration focuses on three core areas:
License Compliance: Automatically verify that dependencies comply with your legal requirements and organizational policies.
Vulnerability Scanning (CVEs): Identify known security flaws in your third-party libraries.
Secret Scanning: Detect hardcoded secrets such as API keys, passwords, and tokens within your source code and configuration files.
Configuration is centralized within the trivy { } block inside kreate { project { } }.
Why Use Trivy in Kreate?
Manual verification of licenses and vulnerabilities is time-consuming and prone to human error. By automating these checks with Trivy, you benefit from:
Early Detection: Catch issues on the developer's machine before code is even committed to the repository.
Automated Compliance: Ensure that no software with incompatible licenses (e.g., AGPL in proprietary projects) is shipped.
Infrastructure Protection: Prevent credential theft by scanning for secrets in configuration files and source code.
Prerequisites
To use the Trivy integration, the Trivy CLI must be installed on the executing system (developer machine or CI runner).
Install via Homebrew:
Add the repository and install:
Add the repository and install:
Manual Installation (Official):
Download the
trivy_x.xx.x_windows-64bit.zipfile from the GitHub Releases page.Unzip the file and copy to any folder.
Generic installation script (ideal for CI):
Dependency Locking
For License Compliance and Vulnerability Scanning (CVEs), Kreate relies on Gradle lockfiles. These files provide a precise snapshot of all transitive dependencies, which is required for Trivy to perform an accurate analysis.
1. Enable Dependency Locking
You must manually enable dependency locking in your project. This is typically done in your build.gradle.kts:
2. Generate Lockfiles
After enabling locking or when changing dependencies, you must generate or update the lockfiles using the following command:
Quick Start
All Trivy scans are disabled by default. To use the module, it must be globally enabled in the trivy block:
Once enabled, Kreate automatically registers the following Gradle tasks for your project:
Task Name | Description |
|---|---|
| Lifecycle aggregator that runs all enabled Trivy scans. |
| Scans lockfiles for known security vulnerabilities (CVEs). |
| Verifies dependencies for license compliance. |
| Searches source code for hardcoded secrets. |
Running Scans
Kreate provides multiple ways to run Trivy scans, ranging from running all checks at once to executing specific, targeted scans.
Run All Enabled Scans
The most common way to run scans is through the standard Gradle check lifecycle task. Kreate registers a central trivyScan task that aggregates all individual scanners and attaches it to the check task.
To run all security checks:
Run Individual Scans
If you want to perform only a specific type of scan, you can call the corresponding task directly. This is useful for faster feedback loops during development.
License Compliance:
Vulnerability (CVE) Scanning:
Secret Detection:
Further Reading
License Scanning: Monitoring and enforcing license policies.
Vulnerability Scanning: Details on searching for CVEs in dependencies.
Secret Scanning: Protecting your project from leaked credentials.
Configuration Reference: A complete list of all available DSL parameters.