Skip to content

Commit 6c05ee3

Browse files
authored
Try fixing the trivy command execution (#16)
Using artifact uload and download to transport container images for scans and start trivy as root
1 parent 70383e6 commit 6c05ee3

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

.github/workflows/container-vulnerability-scan.yaml

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@ name: Container vulnerability scan
22
on:
33
workflow_call:
44
inputs:
5-
image:
5+
image_name:
66
type: string
77
description: Container image name and tag to scan
88
required: true
9+
image_artifact_name:
10+
type: string
11+
description: Container image artifact name to identify the container image file from artifacts
12+
required: false
13+
image_artifact_filename:
14+
type: string
15+
description: Container image file that needs to be downloaded from artifacts
16+
required: false
917
login_dockerhub:
1018
type: boolean
1119
description: "Login to DockerHub, requires the secrets DOCKERHUB_USERNAME and DOCKERHUB_PASSWORD (default: false)"
@@ -41,6 +49,31 @@ jobs:
4149
- name: Pull aquasec/trivy
4250
run: |
4351
docker pull aquasec/trivy:${{ inputs.trivy_tag }}
52+
- name: Download container image from artifacts if uploaded
53+
if: ${{ inputs.image_artifact_name }} && ${{ inputs.image_artifact_filename }}
54+
uses: actions/download-artifact@v2
55+
with:
56+
name: ${{ inputs.image_artifact_name }}
57+
path: /tmp
58+
- name: Load container image file if one is shipped via artifacts
59+
if: ${{ inputs.image_artifact_name }} && ${{ inputs.image_artifact_filename }}
60+
run: |
61+
docker load --input /tmp/${{ inputs.image_artifact_filename }}
62+
RC=$?
63+
if [ ${RC} -gt 0 ]; then
64+
exit ${RC}
65+
fi
66+
- name: Pull container image that should be scanned if no container image is shipped via artifacts
67+
if: ! ${{ inputs.image_artifact_name }} && ! ${{ inputs.image_artifact_filename }}
68+
run: |
69+
docker pull ${{ inputs.image_name }}
70+
RC=$?
71+
if [ ${RC} -gt 0 ]; then
72+
exit ${RC}
73+
fi
74+
- name: List available container images in local repository
75+
run: |
76+
docker image ls -a
4477
- name: Vulnerability scan
4578
run: |
46-
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock aquasec/trivy:${{ inputs.trivy_tag }} -q image ${{ inputs.image }} | tee -a ${GITHUB_STEP_SUMMARY}
79+
docker run -u 0 --rm -v /var/run/docker.sock:/var/run/docker.sock aquasec/trivy:${{ inputs.trivy_tag }} -q image ${{ inputs.image_name }} >> ${GITHUB_STEP_SUMMARY} 2>&1

0 commit comments

Comments
 (0)