-
Notifications
You must be signed in to change notification settings - Fork 2
/
trivy.yml
60 lines (59 loc) · 1.99 KB
/
trivy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
spec:
inputs:
stage:
description: 'The stage to run Trivy scan'
type: string
default: 'scan'
image_name:
description: 'The image name to scan'
type: string
default: '$CI_REGISTRY_IMAGE'
image_tag:
description: 'The image tag to scan'
type: string
default: '$CI_COMMIT_SHORT_SHA'
---
trivy:
image:
name: docker.io/aquasec/trivy:latest
entrypoint: [""]
stage: $[[ inputs.stage ]]
variables:
# Exclude built-in rubygems
TRIVY_OPTIONS: --skip-dirs /usr/local/lib/ruby/gems
# No need to clone the repo, we exclusively work on artifacts. See
# https://docs.gitlab.com/ee/ci/runners/README.html#git-strategy
GIT_STRATEGY: none
TRIVY_USERNAME: "$CI_REGISTRY_USER"
TRIVY_PASSWORD: "$CI_REGISTRY_PASSWORD"
TRIVY_AUTH_URL: "$CI_REGISTRY"
FULL_IMAGE_NAME: "$[[ inputs.image_name | expand_vars ]]:$[[ inputs.image_tag | expand_vars ]]"
TRIVY_NO_PROGRESS: "true"
TRIVY_CACHE_DIR: ".trivycache/"
cache:
key: trivy-shared
paths:
- .trivycache/
needs:
- docker
script:
- trivy --version
# cache cleanup is needed when scanning images with the same tags, it does not remove the database
- time trivy clean --scan-cache
# update vulnerabilities db
- time trivy image --download-db-only
# Builds report and puts it in the default workdir $CI_PROJECT_DIR, so `artifacts:` can take it from there
- time trivy image --exit-code 0 --format template --template "@/contrib/gitlab.tpl"
--output "$CI_PROJECT_DIR/gl-container-scanning-report.json" "$FULL_IMAGE_NAME"
--timeout 15m
# Prints full report
- time trivy image --exit-code 0 "$FULL_IMAGE_NAME"
# Fail on critical vulnerabilities
- time trivy image --exit-code 1 --skip-java-db-update $TRIVY_OPTIONS --severity CRITICAL "$FULL_IMAGE_NAME"
interruptible: true
artifacts:
when:
reports:
container_scanning: gl-container-scanning-report.json
rules:
- if: '$CI_COMMIT_TAG'