Tutorial: Container image scans with Aqua Trivy
Scan a container image using Aqua Trivy
This tutorial shows you how to scan your container images using Aqua Trivy, a popular open-source scanning tool.
In this tutorial, you'll set up a simple orchestration workflow with two steps:
A Background step that runs Docker-in-Docker as a service. This is required for any orchestrated or dataload scan of a container image.
An Aqua-Trivy step that runs the scan and ingests the results into STO.
Set up your pipeline
Do the following:
Select Security Testing Orchestration (left menu, top) > Pipelines > Create a Pipeline. Enter a name and click Start.
In the new pipeline, select Add stage > Security.
Set up your stage as follows:
Enter a Stage Name.
Disable Clone Codebase. You don't need a code repository for this tutorial.
In the Pipeline Editor, go to Infrastructure and select Cloud, Linux, and AMD64 for the infrastructure, OS, and architecture.
You can also use a Kubernetes or Docker build infrastructure, but these require additional work to set up. For more information, go to Supported Infrastructures documentation.
Add a Docker-in-Docker background step
Add the Aqua-Trivy scan step
Add an Aqua Trivy step to your pipeline after the DinD background step and configure it as follows:
Scan Mode = Orchestration
Target name — Click the Value Selector button on the right side of the input field and select Runtime Input.
Target variant — Select Runtime Input.
Container image Type = Docker v2
Container image Domain = docker.io
Container image name — Select Runtime Input.
Container image tag — Select Runtime Input.
Fail on Severity = Critical
Add an Aqua Trivy step to your pipeline after the DinD background step and configure it as follows:
type:AquaTrivyname:A name for the step.identifier:A unique step ID.spec :mode :orchestrationIn orchestrated mode, the step runs the scan and ingests the results in one step.config: defaulttarget :name : <+input>type : containervariant : <+input>You will specify the target name and variant when you run the pipeline. When scanning a repository, you will generally use the repository name and branch for these fields.advanced :log :level : infofail_on_severity: critical
privileged: true
Here's an example:
Run the pipeline and check your results
In the Pipeline Studio, select Run (top right).
When prompted, enter your runtime inputs.
Under Target, enter the target name and variant.
Under Image, enter the [image name] and [tag] you want to use. In most cases, you want to use the repository for the target and the branch for the variant.
If you're scanning the codebase for the first time, enter the root branch of your repo. This is usually the
mainormasterbranch.If you're scanning the example image mentioned above, enter
snyklabs/gooffor the target and image name, andlatestfor the target variant and image tag.Run the pipeline and then wait for the execution to finish.
If you used the example image, you'll see that the pipeline failed for an entirely expected reason: you configured the Trivy step to fail the pipeline if the scan detected any critical vulnerabilities. The final log entry for the Semgrep step reads:
Exited with message: fail_on_severity is set to critical and that threshold was reached.Select Vulnerabilities tab and examine any issues detected by your scan.
Specify the baseline
Select Test Targets (left menu).
Select the baseline you want for your target.
YAML pipeline example
Here's an example of the pipeline you created in this tutorial. If you copy this example, replace the placeholder values with appropriate values for your project, organization, and connectors.
Last updated
Was this helpful?