Trivy component
This component executes Trivy vulnerability and misconfiguration scans against container images or filesystem paths and produces machine-readable reports.
Every container image scan also applies the bundled CRITICAL entitlement
policy. Images containing files below /etc/pki/entitlement are rejected so
Red Hat subscription certificates and keys cannot be distributed in image
layers. This policy remains active when the scanners input omits secret.
Set the string input secret-config to other Trivy secret configuration
contents to apply a project-specific policy instead.
By default, vulnerabilities without an available fix are excluded. Set the
ignore-unfixed input to false to include them.
Set CI_TRIVIY_SERVER_URL to a Trivy server URL, including the http:// or
https:// scheme, to run vulnerability and license scanning in client/server
mode. The component passes the URL to every image or filesystem scan with
Trivy's --server option.
Scans do not run for the renovate/gitlab-pipelines branch, including
merge request pipelines for that branch. This branch is generated by the
gitlab-pipelines package rule in the shared Renovate configuration. The
rules input continues to control all other pipeline contexts.
Download the SBOM
Download release/sbom/gl-sbom-<name>.cdx.json from the scan job artifacts
for the original Trivy CycloneDX inventory. GitLab ingests a separate report
for each scanned image or filesystem input file. To inspect those reports,
open the job archive’s release/sbom/gitlab-<job-id>/ directory. A package used by two
dependency manifests appears in both reports. If the scan cannot attribute a
filesystem package to an input file, the job reports an error rather than
assigning the package to an unrelated file.
Variables
| Name | required | Hints |
|---|---|---|
| TRIVY_TIMEOUT | no | Global variable to set a custom scan timeout for long running scans |
| CI_TRIVIY_SERVER_URL | no | Trivy server URL used for client/server scans |
Usage
Scan the filesystem
- Create a new pipeline file
include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/trivy@stable
inputs:
name: project
path: .
Scan a container image
- Create a new pipeline file
include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/trivy@stable
inputs:
name: image
image: registry.gitlab.com/xrow-public/ci-tools/test-insecure-java-app:latest
ignore-unfixed: false
Track new CVE findings with temporary ignores
Add the label component to create the type::security label. Store a GitLab
project token with permission to create issues and push the scan branch in the
masked GITLAB_TOKEN CI/CD variable. Enable the workflow on the trivy
component, or set workflow-security-enabled: true on the workflow component
for all Trivy jobs in the pipeline:
include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/label@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/workflow@stable
inputs:
workflow-security-enabled: true
workflow-security-ignore-expiration: 2d
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/trivy@stable
inputs:
name: project
path: .
scanning-allow-failure: false
On a branch pipeline, a failing scan includes both fixed and
unfixed CVE findings. For each new finding at or above
scanning-severity, the job
creates a fix: CVE-… issue with type::security, then commits an entry in
.trivyignore.yaml with an expiration date and pushes with ci.skip. The
current scan job still fails; with scanning-allow-failure: false, so does
its pipeline. The next pipeline succeeds for these findings until the ignore
expires. Existing entries are never automatically renewed.
Set CI_WORKFLOW_SECURITY_ENABLED to true or false in CI/CD variables to
override either component input. If it is unset, either component input can
enable the workflow. The Trivy input workflow-security-ignore-expiration
accepts a positive number of days or weeks, such as 2d or 1w. The Trivy
input takes precedence when both components set a non-default expiration.
Trivy records expiration as a UTC date, so it may last until the end of that
day. With no GITLAB_TOKEN, the scan fails without changing issues or ignore
files. Detached merge request pipelines can create tracking issues, but
cannot commit or push temporary ignores. Protected branches require a token
that is allowed to push there.
Registry authentication
For private job images and OCI client credentials, follow the central registry authentication guide.
Report templates
The tools image uses the GitLab, HTML and code-quality templates directly from
the signature-verified Trivy RPM in /usr/local/share/trivy/templates. There is
no template copy, generator or separately downloaded template set.
The Containerfile applies the outstanding upstream JSON URL-encoding correction in place to the GitLab vulnerability template. Its exact-context guard refuses an unexpected template rather than silently applying an obsolete patch. Report filtering, vulnerability findings and scan policy are unchanged.
To update the templates, update TRIVY_VERSION in container/tools/Containerfile
and rebuild the tools image. Review the upstream template before removing or
adjusting the local patch. The existing report suite renders through the template
installed at its default path in that image.
Inputs
| Name | Description | Default | Type |
| --- | --- | --- | --- |
| dependencies | The dependencies that this job depends on. | [] | array |
| ignore-unfixed | Exclude vulnerabilities that do not have a fix available. | true | boolean |
| image | Url to the image. | string | |
| name | Name for the pipeline jobs and the container. | $CI_PROJECT_NAME | string |
| needs | The jobs that this job depends on. | [] | array |
| package-types | Package types to scan | ["os","library"] | array |
| path | Path to the sources. | . | string |
| rules | The jobs that this job depends on. | [{"if":"$CI_PIPELINE_SOURCE == \"schedule\"","when":"never"},{"if":"$CI_PIPELINE_SOURCE == \"merge_request_event\"","when":"on_success"},{"when":"on_success"}] | array |
| scanners | Scanners to use. none, vuln, license, secret, misconfig | ["vuln","secret","license","misconfig"] | array |
| scanning-allow-failure | Should the pipeline fail if scanning the built container image fails? | true | boolean |
| scanning-severity | What level of severity should cause scanning of the built container to fail? | CRITICAL | string |
| scanning-timeout | How long should the scanning process be allowed to run before timing out? Use format e.g. 5m0s | string | |
| secret-config | Trivy secret scanner configuration used for image scans. | rules: - id: redhat-entitlement-material category: subscription title: Red Hat entitlement material must not be shipped in container images severity: CRITICAL path: '(^|/)etc/pki/entitlement/.+' regex: '(?s).+' | string |
| stage | The pipeline stage that the jobs belongs to. | build | string |
| tags | The runners that this job depends on. | [] | array |
| workflow-security-enabled | Create tracking issues and temporary CVE ignores when a branch scan fails. | false | boolean |
| workflow-security-ignore-expiration | Lifetime of generated CVE ignores, as days or weeks (for example, 2d). | 2d | string |