@@ -103,19 +103,14 @@ trivy_tmp_dir="$(mktemp -d -p "$PROJECT_ROOT")"
103103
104104trap ' rm -rf "$tmp_dir" "$trivy_tmp_dir"' EXIT
105105
106- PREFIXES=(" example" " enterprise" )
107-
106+ # Scan both example and enterprise images
108107for image in " ${IMAGES[@]} " ; do
109- for prefix in " ${PREFIXES[@]} " ; do
110- image_ref=" codercom/${prefix} -${image} :${TAG} "
111- image_name=" ${prefix} -${image} -${TAG} "
112- output=" ${tmp_dir} /${prefix} -${image} -${TAG} .sarif"
113-
114- if ! docker image inspect " $image_ref " > /dev/null 2>&1 ; then
115- echo " Image '$image_ref ' does not exist locally; skipping" >&2
116- continue
117- fi
108+ # Process example images (primary)
109+ example_image_ref=" codercom/example-${image} :${TAG} "
110+ example_image_name=" example-${image} -${TAG} "
111+ example_output=" ${tmp_dir} /example-${image} -${TAG} .sarif"
118112
113+ if docker image inspect " $example_image_ref " > /dev/null 2>&1 ; then
119114 old_tmpdir=" ${TMPDIR:- } "
120115 export TMPDIR=" $trivy_tmp_dir "
121116
@@ -124,41 +119,87 @@ for image in "${IMAGES[@]}"; do
124119 run_trace $DRY_RUN trivy image \
125120 --severity CRITICAL,HIGH \
126121 --format sarif \
127- --output " $output " \
122+ --output " $example_output " \
128123 --timeout 15m0s \
129- " $image_ref " 2>&1 | indent
124+ " $example_image_ref " 2>&1 | indent
130125
131126 if [ " $old_tmpdir " = " " ]; then
132127 unset TMPDIR
133128 else
134129 export TMPDIR=" $old_tmpdir "
135130 fi
136131
137- if [ $DRY_RUN = true ]; then
138- continue
132+ if [ $DRY_RUN = false ] && [ -f " $example_output " ]; then
133+ # Do substitutions to add extra details to every message. Without these
134+ # substitutions, most messages won't have any information about which image
135+ # the vulnerability was found in.
136+ jq \
137+ " .runs[].tool.driver.name |= \" Trivy ${example_image_name} \" " \
138+ " $example_output " > " $example_output .tmp"
139+ mv " $example_output .tmp" " $example_output "
140+ jq \
141+ " .runs[].results[].locations[].physicalLocation.artifactLocation.uri |= \" ${example_image_name} /\" + ." \
142+ " $example_output " > " $example_output .tmp"
143+ mv " $example_output .tmp" " $example_output "
144+ jq \
145+ " .runs[].results[].locations[].message.text |= \" ${example_image_name} : \" + ." \
146+ " $example_output " > " $example_output .tmp"
147+ mv " $example_output .tmp" " $example_output "
148+ elif [ $DRY_RUN = false ]; then
149+ echo " No SARIF output found for image '$example_image_ref ' at '$example_output '" >&2
150+ exit 1
139151 fi
152+ else
153+ echo " Image '$example_image_ref ' does not exist locally; skipping" >&2
154+ fi
140155
141- if [ ! -f " $output " ]; then
142- echo " No SARIF output found for image '$image_ref ' at '$output '" >&2
143- exit 1
156+ # Process enterprise images (alias)
157+ enterprise_image_ref=" codercom/enterprise-${image} :${TAG} "
158+ enterprise_image_name=" enterprise-${image} -${TAG} "
159+ enterprise_output=" ${tmp_dir} /enterprise-${image} -${TAG} .sarif"
160+
161+ if docker image inspect " $enterprise_image_ref " > /dev/null 2>&1 ; then
162+ old_tmpdir=" ${TMPDIR:- } "
163+ export TMPDIR=" $trivy_tmp_dir "
164+
165+ # The timeout is set to 15 minutes because in Java images it can take a while
166+ # to scan JAR files for vulnerabilities.
167+ run_trace $DRY_RUN trivy image \
168+ --severity CRITICAL,HIGH \
169+ --format sarif \
170+ --output " $enterprise_output " \
171+ --timeout 15m0s \
172+ " $enterprise_image_ref " 2>&1 | indent
173+
174+ if [ " $old_tmpdir " = " " ]; then
175+ unset TMPDIR
176+ else
177+ export TMPDIR=" $old_tmpdir "
144178 fi
145179
146- # Do substitutions to add extra details to every message. Without these
147- # substitutions, most messages won't have any information about which image
148- # the vulnerability was found in.
149- jq \
150- " .runs[].tool.driver.name |= \" Trivy ${image_name} \" " \
151- " $output " > " $output .tmp"
152- mv " $output .tmp" " $output "
153- jq \
154- " .runs[].results[].locations[].physicalLocation.artifactLocation.uri |= \" ${image_name} /\" + ." \
155- " $output " > " $output .tmp"
156- mv " $output .tmp" " $output "
157- jq \
158- " .runs[].results[].locations[].message.text |= \" ${image_name} : \" + ." \
159- " $output " > " $output .tmp"
160- mv " $output .tmp" " $output "
161- done
180+ if [ $DRY_RUN = false ] && [ -f " $enterprise_output " ]; then
181+ # Do substitutions to add extra details to every message. Without these
182+ # substitutions, most messages won't have any information about which image
183+ # the vulnerability was found in.
184+ jq \
185+ " .runs[].tool.driver.name |= \" Trivy ${enterprise_image_name} \" " \
186+ " $enterprise_output " > " $enterprise_output .tmp"
187+ mv " $enterprise_output .tmp" " $enterprise_output "
188+ jq \
189+ " .runs[].results[].locations[].physicalLocation.artifactLocation.uri |= \" ${enterprise_image_name} /\" + ." \
190+ " $enterprise_output " > " $enterprise_output .tmp"
191+ mv " $enterprise_output .tmp" " $enterprise_output "
192+ jq \
193+ " .runs[].results[].locations[].message.text |= \" ${enterprise_image_name} : \" + ." \
194+ " $enterprise_output " > " $enterprise_output .tmp"
195+ mv " $enterprise_output .tmp" " $enterprise_output "
196+ elif [ $DRY_RUN = false ]; then
197+ echo " No SARIF output found for image '$enterprise_image_ref ' at '$enterprise_output '" >&2
198+ exit 1
199+ fi
200+ else
201+ echo " Image '$enterprise_image_ref ' does not exist locally; skipping" >&2
202+ fi
162203done
163204
164205# Merge all SARIF files into one.
0 commit comments