43
43
type : boolean
44
44
required : false
45
45
default : true
46
- scan-upload :
47
- description : Upload scanned images that have vulnerabilities?
46
+ scan-push :
47
+ description : Push scanned images that have vulnerabilities?
48
48
type : boolean
49
49
required : false
50
50
default : true
@@ -135,11 +135,6 @@ jobs:
135
135
run : |
136
136
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sudo sh -s -- -b /usr/local/bin v0.44.0
137
137
138
- - name : Install jq
139
- run : |
140
- curl --output /usr/local/bin/jq -sfL https://github.com/jqlang/jq/releases/download/jq-1.6/jq-linux64
141
- chmod +x /usr/local/bin/jq
142
-
143
138
- name : Setup networking
144
139
run : |
145
140
if ! ip l show breth1 >/dev/null 2>&1; then
@@ -186,7 +181,7 @@ jobs:
186
181
env :
187
182
KAYOBE_VAULT_PASSWORD : ${{ secrets.KAYOBE_VAULT_PASSWORD }}
188
183
189
- - name : Build and push kolla overcloud images
184
+ - name : Build kolla overcloud images
190
185
run : |
191
186
args="${{ github.event.inputs.regexes }}"
192
187
args="$args -e kolla_base_distro=${{ matrix.distro }}"
@@ -198,7 +193,7 @@ jobs:
198
193
KAYOBE_VAULT_PASSWORD : ${{ secrets.KAYOBE_VAULT_PASSWORD }}
199
194
if : github.event.inputs.overcloud == 'true'
200
195
201
- - name : Build and push kolla seed images
196
+ - name : Build kolla seed images
202
197
run : |
203
198
args="kolla_base_distro=${{ matrix.distro }}"
204
199
args="$args -e kolla_tag=${{ needs.generate-tag.outputs.kolla_tag }}"
@@ -222,40 +217,57 @@ jobs:
222
217
223
218
- name : Generate list of images to scan/push
224
219
run : |
220
+ # Clean up any stale data
221
+ rm -rf ${{ matrix.distro }}-docker-images.txt
222
+
225
223
# Make a file of imagename:tag
226
224
grep --invert-match --no-filename ^REPOSITORY ${{ matrix.distro }}-container-images |\
227
225
sed 's/ \+/:/g' |\
228
- cut -f 1,2 -d: > docker-images.txt
226
+ cut -f 1,2 -d: > ${{ matrix.distro }}- docker-images.txt
229
227
230
228
- name : Scan built container images
231
229
run : |
232
230
set -euo pipefail
233
- mkdir -p image-scan-output
234
231
232
+ # Clean any stale data
233
+ rm -rf ${{ matrix.distro }}-image-scan-output
235
234
rm -f images-to-push.txt
236
235
236
+ # Make a fresh output directory
237
+ mkdir -p ${{ matrix.distro }}-image-scan-output
238
+
237
239
# If Trivy detects no vulnerabilities, add the image name to images-to-push.txt.
238
240
# If there are vulnerabilities detected, generate a CSV summary and do not add to
239
241
# images-to-push.txt.
240
242
while read -r image; do
241
243
filename=$(basename $image | sed 's/:/\./g')
242
244
if $(trivy image \
245
+ --quiet \
243
246
--exit-code 1 \
244
247
--scanners vuln \
245
248
--format json \
246
249
--severity HIGH,CRITICAL \
247
- --output image-scan-output/${filename}.json \
250
+ --output ${{ matrix.distro }}- image-scan-output/${filename}.json \
248
251
--ignore-unfixed \
249
252
$image); then
250
- echo "${image}" >> images-to-push.txt
251
- rm image-scan-output/${filename}.json
253
+ # Clean up the output file for any images with no vulnerabilities
254
+ rm -f ${{ matrix.distro }}-image-scan-output/${filename}.json
255
+
256
+ # Add the image to the list to push
257
+ echo "${image}" >> ${{ matrix.distro }}-images-to-push.txt
252
258
else
253
- if [${{github.event.input.scan-upload}} == 'true' ]; then
254
- echo "${image}" >> images-to-push.txt
259
+ # Still add the image to the list to push if we're ignoring fails
260
+ if [ "${{github.event.inputs.scan-push}}" == "true" ]; then
261
+ echo "${image}" >> ${{ matrix.distro }}-images-to-push.txt
255
262
fi
256
263
257
- echo '"PkgName","PkgPath","PkgID","VulnerabilityID","FixedVersion","PrimaryURL","Severity"' > image-scan-output/${filename}.csv
258
- jq -r '.Results[].Vulnerabilities
264
+ # Write a header for the summary CSV
265
+ echo '"PkgName","PkgPath","PkgID","VulnerabilityID","FixedVersion","PrimaryURL","Severity"' > ${{ matrix.distro }}-image-scan-output/${filename}.summary.csv
266
+
267
+ # Write the summary CSV data
268
+ jq -r '.Results[]
269
+ | select(.Vulnerabilities)
270
+ | .Vulnerabilities
259
271
# Ignore packages with "kernel" in the PkgName
260
272
| map(select(.PkgName | test("kernel") | not ))
261
273
| group_by(.VulnerabilityID)
@@ -271,37 +283,40 @@ jobs:
271
283
]
272
284
)
273
285
| .[]
274
- | @csv' image-scan-output/${filename}.json >> image-scan-output/${filename}.summary.csv
286
+ | @csv' ${{ matrix.distro }}- image-scan-output/${filename}.json >> ${{ matrix.distro }}- image-scan-output/${filename}.summary.csv
275
287
fi
276
- done < docker-images.txt
277
- mv images-to-push.txt docker-images.txt
288
+ done < ${{ matrix.distro }}-docker-images.txt
289
+
290
+ # Rename the file of vulnerability scanned images so that it can
291
+ # be consumed by the docker push step
292
+ mv ${{ matrix.distro }}-images-to-push.txt ${{ matrix.distro }}-docker-images.txt
278
293
shell : bash
279
294
if : github.event.inputs.scan == 'true'
280
295
281
296
- name : Upload Trivy scan artefacts
282
297
uses : actions/upload-artifact@v3
283
298
with :
284
- name : " trivy-scan-output"
285
- path : |
286
- 'image-scan-output/*.json'
287
- 'image-scan-output/*.summary.csv'
299
+ name : ${{ matrix.distro }}-image-scan-output
300
+ path : ${{ matrix.distro }}-image-scan-output
288
301
retention-days : 7
289
- if : github.event.inputs.scan == 'true'
302
+ if : always()
290
303
291
304
- name : Push images
292
305
run : |
293
306
source venvs/kayobe/bin/activate &&
294
307
source src/kayobe-config/kayobe-env --environment ci-builder &&
295
- kayobe playbook run ${KAYOBE_CONFIG_PATH}/ansible/docker-registry-login.yml
308
+ kayobe playbook run --become ${KAYOBE_CONFIG_PATH}/ansible/docker-registry-login.yml
296
309
297
310
while read -r image; do
298
311
# Retries!
299
312
for i in {1..10}; do
300
- docker push ${image} && break || sleep 5
313
+ sudo docker push ${image} && break || sleep 2
301
314
done
302
- done < docker-images.txt
315
+ done < ${{ matrix.distro }}- docker-images.txt
303
316
shell : bash
304
- if : ${{ inputs.push }}
317
+ env :
318
+ KAYOBE_VAULT_PASSWORD : ${{ secrets.KAYOBE_VAULT_PASSWORD }}
319
+ if : github.event.inputs.push == 'true'
305
320
306
321
- name : Prune local Kolla container images over 1 week old
307
322
run : |
0 commit comments