DevSecOps ensures the security by doing Vulnerability scanning on the container images. There are several tools available for image scanning.
Trivy
is a Simple and Comprehensive Vulnerability Scanner for Containers, Suitable for CI.
The more information on Trivy is available in https://github.com/aquasecurity/trivy
In this article, we will see, how to implement trivy in Jenkins
and Tekton
pipelines.
DevSecOps, DevOps, Aquasec, Trivy, jenkins, tekton.
The CICD process contains several steps. There could be a step called Build Image
that will build a image and Push the image to the image registry.
Need to split the step into 3 steps.
Build Image
Trivy Scan
Push Image
Here is the modified pipeline.
The build image will build the image.
Trivy scan will scan the image that was generated in the above step and print the Vulnerability count as Low, Medium, High and Critical.
Based on the configured exit criteria (0 Critical) the next step would in the pipeline will continue or stop.
Here is the sample logs of the pipeline execution.
After the scan is completed, it Pushes the image to the Image Registry.
The pipeline scripts are defined in the jenkinsfile
. lets us see the changes to be done in the jenkins file.
Here is the declaration about the Trivy image in the containers
section under podTemplate
in the jenkinsfile
-
Name
trivy
will be used in the script to refer the trivy container. -
The image tag of the
trivy
. -
A configmap contains
username
details to connect to IBM Cloud Container registry. -
A secrte contains
password
to connect to IBM Cloud Container registry.
Here are the steps to Build Image.
-
Temp image name is framed.
-
Image is build using
buildah
. Here temp image name is used. -
Login into IBM Cloud Container Registry using
buildah
. -
Temp image is pushed to IBM Cloud Container Registry using
buildah
.
Here are the steps for trivy Scanning
-
Refers the temp image name created in the previous step.
-
Registry URL and user details to login into IBM Cloud Container Registry by trivy.
-
Trivy scanning the temp image found in the IBM Cloud Container Registry.
Here are the steps for Push Image.
-
Refers the temp image name created in the previous step.
-
Login into IBM Cloud Container Registry using
buildah
. -
Pull the temp image using
buildah
. -
Tag the image to the actual image name.
-
Push the actual image to IBM Cloud Container Registry using
buildah
. -
Remove the temp image from IBM Cloud Container Registry using
buildah
.
The CICD process contains several steps. There could be a step called Build
that will build a image and Push the image to the image registry.
Need to split the step into 3 steps.
build
image-scan
push
Here is the modified pipeline.
The pipeline scripts are defined as Task in the yaml file. lets us see the changes done in the task file.
Here is the declaration about the Trivy image in the Task
-
Image details of the
buildah
. -
The variable name of the
buildah
. -
Image details of the
trivy
. -
The variable name of the
trivy
.
Here are the steps for Build Image.
-
Temp image name is framed.
-
Image is build using
buildah
. Here temp image name is used. -
Login into IBM Cloud Container Registry using
buildah
. -
Temp image is pushed to IBM Cloud Container Registry using
buildah
. -
Username details to Login into IBM Cloud Container Registry.
-
Password details to Login into IBM Cloud Container Registry.
-
Image details reference
buildah
from input param. -
Name of the step
Here are the steps for Scanning
-
Refers the temp image name created in the previous step.
-
Trivy scanning the temp image found in the IBM Cloud Container Registry
-
Username details to Login into IBM Cloud Container Registry.
-
Password details to Login into IBM Cloud Container Registry.
-
Image details of the
trivy
from input param. -
Name of the step.
-
Registry URL and user details to login into IBM Cloud Container Registry by trivy.
Here are the steps for Pushing Image.
-
Refers the image url passed as a parameter.
-
Refers the temp image name created in the previous step.
-
Login into IBM Cloud Container Registry using
buildah
. -
Pull the temp image using
buildah
. -
Tag the image to the actual image name.
-
Push the actual image to IBM Cloud Container Registry using
buildah
. -
Remove the temp image from IBM Cloud Container Registry using
buildah
. -
Image details of the
buildah
from input param. -
Name of the step.