Skip to content

Commit 0032c92

Browse files
author
Vitaly Korolev
committed
Revert last invalid commit
This reverts commit 025fef8.
1 parent 025fef8 commit 0032c92

File tree

2 files changed

+10
-59
lines changed

2 files changed

+10
-59
lines changed

Jenkinsfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ void imageScan() {
149149
sh '''rm -f dep-image-scan.txt'''
150150

151151
// trigger BlackDuck scan
152-
def imageList = readFile(file: 'helm_image.list').trim()
152+
def rawImageList = readFile(file: 'helm_image.list').trim()
153+
def imageList = rawImageList.endsWith(',') ? rawImageList[0..-2] : rawImageList
153154
build job: 'securityscans/Blackduck/KubeNinjas/kubernetes-helm', wait: false, parameters: [ string(name: 'branch', value: "${env.BRANCH_NAME}"), string(name: 'CONTAINER_IMAGES', value: "${imageList}") ]
154155
}
155156

makefile

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -229,65 +229,15 @@ upgrade-test: prepare
229229
#***************************************************************************
230230
## Find and scan dependent Docker images for security vulnerabilities
231231
## Options:
232-
## * [saveOutput] optional. Save the output to a text file. Example: saveOutput=true
232+
## * [saveOutput] optional. Save the output to a xml file. Example: saveOutput=true
233233
.PHONY: image-scan
234234
image-scan:
235+
235236
@rm -f helm_image.list dep-image-scan.txt
236-
@$(if $(saveOutput), > dep-image-scan.txt)
237237
@echo "=====Scan dependent Docker images in charts/values.yaml" $(if $(saveOutput), | tee -a dep-image-scan.txt,)
238-
set -e; \
239-
scanned_images_tracker_file="$$(mktemp)"; \
240-
scan_image() { \
241-
img="$$1"; \
242-
src_file="$$2"; \
243-
if [ -z "$$img" ]; then \
244-
echo "Warning: Empty image name provided from $$src_file. Skipping." $(if $(saveOutput), | tee -a dep-image-scan.txt,); \
245-
return; \
246-
fi; \
247-
if grep -Fxq "$$img" "$$scanned_images_tracker_file"; then \
248-
echo "= $$img (from $$src_file) - Already Processed" $(if $(saveOutput), | tee -a dep-image-scan.txt,); \
249-
return; \
250-
fi; \
251-
echo "= Scanning $$img (from $$src_file)" $(if $(saveOutput), | tee -a dep-image-scan.txt,); \
252-
if ! docker pull "$$img"; then \
253-
echo "Error: Failed to pull Docker image $$img. Skipping scan." $(if $(saveOutput), | tee -a dep-image-scan.txt,); \
254-
echo "$$img" >> "$$scanned_images_tracker_file"; \
255-
return; \
256-
fi; \
257-
echo "$$img" >> "$$scanned_images_tracker_file"; \
258-
printf "%s," "$${img}" >> helm_image.list ; \
259-
grype_json_output=$$(docker run --rm -v /var/run/docker.sock:/var/run/docker.sock anchore/grype:latest --output json "$$img" 2>/dev/null); \
260-
if [ -z "$$grype_json_output" ]; then \
261-
echo "Warning: Grype produced no output for $$img. Command might have failed or image not found/supported by grype." $(if $(saveOutput), | tee -a dep-image-scan.txt,); \
262-
echo $(if $(saveOutput), | tee -a dep-image-scan.txt,); \
263-
return; \
264-
fi; \
265-
if ! echo "$$grype_json_output" | jq -e '.descriptor.name' > /dev/null; then \
266-
echo "Warning: Grype output for $$img is not valid JSON or image metadata is missing. Output was:" $(if $(saveOutput), | tee -a dep-image-scan.txt,); \
267-
echo "$$grype_json_output" $(if $(saveOutput), | tee -a dep-image-scan.txt,); \
268-
echo $(if $(saveOutput), | tee -a dep-image-scan.txt,); \
269-
return; \
270-
fi; \
271-
summary=$$(echo "$$grype_json_output" | jq -r '([.matches[]?.vulnerability.severity] // []) as $$all_severities | reduce ["Critical","High","Medium","Low","Negligible","Unknown"][] as $$sev ( {Critical:0,High:0,Medium:0,Low:0,Negligible:0,Unknown:0} ; .[$$sev] = ([$$all_severities[] | select(. == $$sev)] | length) ) | "Critical=\(.Critical) High=\(.High) Medium=\(.Medium) Low=\(.Low) Negligible=\(.Negligible) Unknown=\(.Unknown)"'); \
272-
echo "Summary: $$summary" $(if $(saveOutput), | tee -a dep-image-scan.txt,); \
273-
if echo "$$grype_json_output" | jq -e '.matches == null or (.matches | length == 0)' > /dev/null; then \
274-
echo "No vulnerabilities found to tabulate for $$img." $(if $(saveOutput), | tee -a dep-image-scan.txt,); \
275-
else \
276-
scan_out_body=$$(echo "$$grype_json_output" | jq -r 'def sevorder: {Critical:0, High:1, Medium:2, Low:3, Negligible:4, Unknown:5}; [.matches[]? | {pkg: .artifact.name, ver: .artifact.version, cve: .vulnerability.id, sev: .vulnerability.severity}] | map(. + {sort_key: sevorder[.sev // "Unknown"]}) | sort_by(.sort_key) | .[] | [.pkg // "N/A", .ver // "N/A", .cve // "N/A", .sev // "N/A"] | @tsv'); \
277-
if [ -n "$$scan_out_body" ]; then \
278-
(echo "Package\tVersion\tCVE\tSeverity"; echo "$$scan_out_body") | column -t -s $$'\t' $(if $(saveOutput), | tee -a dep-image-scan.txt,); \
279-
else \
280-
echo "No vulnerability details to display for $$img (though summary reported counts)." $(if $(saveOutput), | tee -a dep-image-scan.txt,); \
281-
fi; \
282-
fi; \
283-
echo $(if $(saveOutput), | tee -a dep-image-scan.txt,); \
284-
}; \
285-
util_image=$$(grep -A2 'utilContainer:' charts/values.yaml | grep 'image:' | sed 's/.*image:[[:space:]]*//g' | sed 's/"//g' | xargs); \
286-
scan_image "$$util_image" "charts/values.yaml"; \
287-
haproxy_image=$$(grep -A 3 '^haproxy:' charts/values.yaml | grep -A 1 '^\s*image:' | grep '^\s*repository:' | sed 's/.*repository:[[:space:]]*//g' | sed 's/"//g' | sed 's/#.*//g' | xargs); \
288-
haproxy_tag=$$(grep -A 4 '^haproxy:' charts/values.yaml | grep -A 2 '^\s*image:' | grep '^\s*tag:' | sed 's/.*tag:[[:space:]]*//g' | sed 's/"//g' | sed 's/{{.*}}/latest/' | sed 's/#.*//g' | xargs); \
289-
scan_image "$$haproxy_image:$$haproxy_tag" "charts/values.yaml";
290-
@# Remove trailing comma from helm_image.list if present
291-
@if [ -f helm_image.list ]; then \
292-
sed -i '' -e 's/,\s*$$//' helm_image.list; \
293-
fi
238+
@for depImage in $(shell grep -E "^\s*\bimage:\s+(.*)" charts/values.yaml | sed 's/image: //g' | sed 's/"//g'); do\
239+
echo -n "$${depImage}," >> helm_image.list ; \
240+
echo "= $${depImage}:" $(if $(saveOutput), | tee -a dep-image-scan.txt,) ; \
241+
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock anchore/grype:latest --output json $${depImage} | jq -r '[(.matches[] | [.artifact.name, .artifact.version, .vulnerability.id, .vulnerability.severity])] | .[] | @tsv' | sort -k4 | column -t $(if $(saveOutput), | tee -a dep-image-scan.txt,);\
242+
echo $(if $(saveOutput), | tee -a dep-image-scan.txt,) ;\
243+
done

0 commit comments

Comments
 (0)