You can identify and address the security vulnerabilities earlier in the software development life-cycle if you integrate a scanner in the continuous integration (CI) pipelines. There are multiple open-source and commercial tools out there that can scan the applications and containers. When comparing these tools, we consider the following aspects:
Easier integration with the pipelines through plugins, scripts, or API calls.
Faster, ideally synchronous execution. It should not hold up the build pipeline.
Ability to easily ignore false positives, unfixable, and realized vulnerabilities.
Audit report access from the pipeline and roll-up at the organizational level.
Ability to run tests from developer machines easily
CI pipeline integration is often just one part of an enterprise security toolchain. Tools like AquaSecurity, Prisma, Snyk, and others provide additional features such as periodic re-scanning, run-time monitoring, alerting, and a centralized dashboard for the security teams. In this blog post, however, we will look into Trivy. Trivy is an open-source scanner from the AquaSecurity team that can scan container images or filesystem paths for vulnerable operating system packages or application dependencies.
Let’s review our scanner selection criteria with Trivy.
Getting Started
Let’s download trivy CLI and test it on our local machine:
There are several binaries available for *-nix based systems. If you can’t find the right binary, you have an option to use the aquasec/trivy container instead. First, let’s take a quick look at the CLI.
When you run a scan, trivy will automatically download the vulnerabilities database and cache it for 12 hours. The database can also be downloaded separately if required.
Let’s take trivy for a spin and see it in action.
node:11-alpine seems to have several security vulnerabilities, including a few CRITICAL and HIGH. However, all of them are identified in the underlined Alpine 3.9.4 operating system since we have not deployed any custom applications inside the container. Trivy can differentiate between OS and application dependency base vulnerabilities.
By default, Trivy generates a tabular output on the CLI, but it supports templating, and you can generate reports in multiple formats including HTML file type. Let’s create an HTML report for the last run.
Jenkins Integration
Let’s add a scanning feature in our Jenkinsfile:
The script downloads and runs the scanner on a nodejs application path. It runs the scan twice, the second time from the previous cache, and fails the build if it discovers are any CRITICAL vulnerabilities. Finally, the report to the pipeline using HTML Publisher plugin.
You can manage false positives through .trivyignore file. So you can check in your .trivyignore file and the scan step in Jenkins pipeline will pick it up automatically.
Trivy is a fast, lightweight, and user-friendly scanner that can easily integrate in any environment.