Skip to main content

Trivy Operator

Trivy Operator is an open-source security scanner that leverages Trivy to continuously scan your Kubernetes cluster for security issues.

Using Port's Kubernetes Exporter, you can keep track of all Trivy resources across your different clusters and export all the security issues to Port. You will use built in metadata from your kubernetes resources and CRDs to create entities in Port and keep track of their state.


Get to know the basics of our Kubernetes exporter here!


In this use-case, you will use a custom bash script which will assist you in the process of installing Port's K8s exporter.

The script will install the helm chart to the Kubernetes cluster which is currently in kubectl context. To view the context name of the cluster the exporter will be installed on, run:

kubectl config current-context

Setting up blueprints & resource mapping

The following section will guide you through the process of setting up your blueprints and resource mapping using the installation script. You can read more about the installation script here.

Creating blueprints

The installation script provides a convenient way to create your blueprints. Using the CUSTOM_BP_PATH environment variable, you can fetch a pre-defined blueprints.json to create your blueprints. For this use-case, you will use this file to define your blueprints. Do this by running:

export CUSTOM_BP_PATH=""

This blueprints.json file defines the following blueprints:

  • Cluster
  • Namespace
  • Workload
  • Trivy Vulnerabilities
  • Workload is an abstraction of Kubernetes objects which create and manage pods. By creating this blueprint, you can avoid creating a dedicated blueprint per Workload type, all of which will likely look pretty similar. Here is the list of kubernetes objects Workload will represent:

    • Deployment
    • StatefulSet
    • DaemonSet
  • Trivy Vulnerabilities is one of the most important Trivy resources, giving developers the capability to find and view the risks that relate to different resources in their Kubernetes cluster.

Below is the Trivy blueprint schema used in the exporter:

Trivy vulnerability blueprint (click to expand)
"title":"Trivy Vulnerabilities",
"title":"Critical Count",
"title":"High Count",
"title":"Low Count",
"title":"Medium Count",
"title":"Scanner Version",
"title":"Created At",

Exporting custom resource mapping

Using the CONFIG_YAML_URL parameter, you can define a custom resource mapping to use when installing the exporter.

In this use-case you will be using the this configuration file. To achieve this, run:


Below is the mapping for the Trivy resource:

Trivy vulnerability mapping (click to expand)
- kind:
- identifier: + "-" + .metadata.namespace + "-" + env.CLUSTER_NAME
icon: '"Trivy"'
blueprint: '"trivyVulnerabilities"'
criticalCount: .report.summary.criticalCount
highCount: .report.summary.highCount
lowCount: .report.summary.lowCount
mediumCount: .report.summary.mediumCount
category: .report.checks[0].category
message: .report.checks[0].messages
severity: .report.checks[0].severity
scannerVersion: .report.scanner.version
createdAt: .metadata.creationTimestamp
namespace: .metadata.namespace + "-" + env.CLUSTER_NAME

Alternative integration using script

While the Trivy Kubernetes exporter described above is the recommended installation method, you may prefer to use a webhook and a script to ingest your Trivy scan results to Port.