@@ -120,8 +120,42 @@ jobs:
120
120
IMAGE_REGISTRY : " ghcr.io/${{ github.repository }}/workbench-images"
121
121
CONTAINER_BUILD_CACHE_ARGS : " --cache-from ${{ env.CACHE }} --cache-to ${{ env.CACHE }}"
122
122
123
- - name : " schedule: run Trivy vulnerability scanner"
124
- if : " ${{ fromJson(inputs.github).event_name == 'schedule' }}"
123
+ # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
124
+ - name : " pull_request: make ${{ inputs.target }}"
125
+ run : |
126
+ # start a black hole container registry as make target always does a push
127
+ mkdir -p $HOME/.config/containers/registries.conf.d/
128
+ cp ci/cached-builds/insecure_localhost_registry.conf $HOME/.config/containers/registries.conf.d/insecure_localhost_registry.conf
129
+ go run ci/cached-builds/dev_null_container_registry.go &
130
+ # build and push the image
131
+ make ${{ inputs.target }}
132
+ if : " ${{ fromJson(inputs.github).event_name == 'pull_request' }}"
133
+ env :
134
+ IMAGE_TAG : " ${{ github.sha }}"
135
+ IMAGE_REGISTRY : " localhost:5000/workbench-images"
136
+ CONTAINER_BUILD_CACHE_ARGS : " --cache-from ${{ env.CACHE }}"
137
+
138
+ - name : " pull_request|schedule: resolve image name if Trivy scan should run"
139
+ id : resolve-image
140
+ if : ${{ fromJson(inputs.github).event_name == 'pull_request' || fromJson(inputs.github).event_name == 'schedule' }}
141
+ env :
142
+ EVENT_NAME : ${{ fromJson(inputs.github).event_name }}
143
+ HAS_TRIVY_LABEL : ${{ contains(fromJson(inputs.github).event.pull_request.labels.*.name, 'trivy-scan') }}
144
+ run : |
145
+ if [[ "$EVENT_NAME" == "pull_request" && "$HAS_TRIVY_LABEL" == "true" ]]; then
146
+ IMAGE_NAME="localhost:5000/workbench-images:${{ inputs.target }}-${{ github.sha }}"
147
+ echo "image=$IMAGE_NAME" >> $GITHUB_OUTPUT
148
+ elif [[ "$EVENT_NAME" == "schedule" ]]; then
149
+ IMAGE_NAME="ghcr.io/${{ github.repository }}/workbench-images:${{ inputs.target }}-${{ github.ref_name }}_${{ github.sha }}"
150
+ echo "image=$IMAGE_NAME" >> $GITHUB_OUTPUT
151
+ fi
152
+
153
+ if [[ -z "$IMAGE_NAME" ]]; then
154
+ echo "Trivy scan won't run"
155
+ fi
156
+
157
+ - name : Run Trivy vulnerability scanner
158
+ if : ${{ steps.resolve-image.outputs.image }}
125
159
run : |
126
160
TRIVY_VERSION=0.53.0
127
161
REPORT_FOLDER=${{ github.workspace }}/report
@@ -131,9 +165,15 @@ jobs:
131
165
mkdir -p $REPORT_FOLDER
132
166
cp ci/$REPORT_TEMPLATE $REPORT_FOLDER
133
167
134
- IMAGE_NAME=ghcr.io/ ${{ github.repository }}/workbench-images:${{ inputs.target }}-${{ github.ref_name }}_${{ github.sha }}
168
+ IMAGE_NAME=${{ steps.resolve-image.outputs.image }}
135
169
echo "Scanning $IMAGE_NAME"
136
170
171
+ SEVERITY_OPTION=""
172
+ # Report only higher vulnerabilities if not a pull request
173
+ if [ "${{ fromJson(inputs.github).event_name }}" != "pull_request" ]; then
174
+ SEVERITY_OPTION="--severity CRITICAL,HIGH"
175
+ fi
176
+
137
177
# have trivy access podman socket,
138
178
# https://github.com/aquasecurity/trivy/issues/580#issuecomment-666423279
139
179
podman run --rm \
@@ -143,28 +183,13 @@ jobs:
143
183
image \
144
184
--image-src podman \
145
185
--podman-host /var/run/podman/podman.sock \
146
- --scanners vuln,secret \
186
+ --scanners vuln --ignore-unfixed \
147
187
--exit-code 0 --timeout 30m \
148
- --severity CRITICAL,HIGH \
188
+ $SEVERITY_OPTION \
149
189
--format template --template "@/report/$REPORT_TEMPLATE" -o /report/$REPORT_FILE \
150
190
$IMAGE_NAME
151
191
152
192
cat $REPORT_FOLDER/$REPORT_FILE >> $GITHUB_STEP_SUMMARY
153
193
154
- # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
155
- - name : " pull_request: make ${{ inputs.target }}"
156
- run : |
157
- # start a black hole container registry as make target always does a push
158
- mkdir -p $HOME/.config/containers/registries.conf.d/
159
- cp ci/cached-builds/insecure_localhost_registry.conf $HOME/.config/containers/registries.conf.d/insecure_localhost_registry.conf
160
- go run ci/cached-builds/dev_null_container_registry.go &
161
- # build and push the image
162
- make ${{ inputs.target }}
163
- if : " ${{ fromJson(inputs.github).event_name == 'pull_request' }}"
164
- env :
165
- IMAGE_TAG : " ${{ github.sha }}"
166
- IMAGE_REGISTRY : " localhost:5000/workbench-images"
167
- CONTAINER_BUILD_CACHE_ARGS : " --cache-from ${{ env.CACHE }}"
168
-
169
194
- run : df -h
170
195
if : " ${{ !cancelled() }}"
0 commit comments