Generating HTML Reports with Trivy

Trivy is a powerful tool for scanning container images for vulnerabilities. One of its features allows you to generate reports in HTML format. Here’s how to do it correctly and resolve common errors you might encounter.

Step-by-Step Guide

To generate an HTML report from a Trivy scan, you can use the following command:

trivy image --format template --template "@contrib/html.tpl" -o report.html golang:1.12-alpine

Common Error: Template Not Found

If you encounter an error like this:

FATAL report error: unable to write results: failed to initialize template writer: error retrieving template from path: open contrib/html.tpl: no such file or directory

This indicates that Trivy cannot find the specified template file. The template file html.tpl is not included by default in the Trivy binary, which can lead to this issue.

Solution

To resolve this, you need to manually download the HTML template file from the Trivy GitHub repository. Here’s how:

  1. Go to the Trivy GitHub repository.
  2. Download the raw content of the html.tpl file.
  3. Save it to a directory accessible by your Trivy command, for example, /usr/local/share/trivy/html.tpl.

After saving the template, modify your command to point to the correct path:

trivy image --format template --template "@/usr/local/share/trivy/html.tpl" -o report.html golang:1.12-alpine

Conclusion

By following these steps, you should be able to generate HTML reports from your Trivy scans without encountering template-related errors. Make sure to adjust the path to the template file based on where you saved it.

Tags

  • Trivy
  • Security
  • Vulnerability Scanning

Meta Description

Easily generate HTML reports from Trivy scans and troubleshoot common template errors.