Skip to content

Commit

Permalink
cve: fix Double-count in "All Images" for CVE image scan report (#2856)
Browse files Browse the repository at this point in the history
* WIP: CVE scan double-counting CVEs total

baseline

Signed-off-by: tarilabs <[email protected]>

* fixed to avoid double-counting with demo

Signed-off-by: tarilabs <[email protected]>

* remove demo files

Signed-off-by: tarilabs <[email protected]>

---------

Signed-off-by: tarilabs <[email protected]>
  • Loading branch information
tarilabs authored Aug 28, 2024
1 parent df2c0a6 commit 3c342f2
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions hack/trivy_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ def extract_images(version):
)

# Initialize counters
unique_images = {} # unique set of images across all WGs
total_images = 0
total_low = 0
total_medium = 0
Expand Down Expand Up @@ -309,12 +310,9 @@ def extract_images(version):
high = sum(entry["severity_counts"]["HIGH"] for entry in data)
critical = sum(entry["severity_counts"]["CRITICAL"] for entry in data)

# Update the total counts
total_images += image_count
total_low += low
total_medium += medium
total_high += high
total_critical += critical
# Update unique_images for the total counts later
for d in data:
unique_images[d["image"]] = d

# Create the output for this file
file_data = {
Expand All @@ -328,15 +326,23 @@ def extract_images(version):
# Update merged_data with filename as key
merged_data[filename] = file_data

# Add total counts to merged_data
merged_data["total"] = {
"images": total_images,
"LOW": total_low,
"MEDIUM": total_medium,
"HIGH": total_high,
"CRITICAL": total_critical,
}

# Update the total counts
unique_images = unique_images.values() # keep the set of values
total_images += len(unique_images)
total_low += sum(entry["severity_counts"]["LOW"] for entry in unique_images)
total_medium += sum(entry["severity_counts"]["MEDIUM"] for entry in unique_images)
total_high += sum(entry["severity_counts"]["HIGH"] for entry in unique_images)
total_critical += sum(entry["severity_counts"]["CRITICAL"] for entry in unique_images)

# Add total counts to merged_data
merged_data["total"] = {
"images": total_images,
"LOW": total_low,
"MEDIUM": total_medium,
"HIGH": total_high,
"CRITICAL": total_critical,
}

log("Summary in Json Format:")
log(json.dumps(merged_data, indent=4))
Expand Down

0 comments on commit 3c342f2

Please sign in to comment.