-
Notifications
You must be signed in to change notification settings - Fork 23
Add container image scanning script #1903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: stackhpc/2025.1
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
features: | ||
- | | ||
Added ``wazuh-scan-images.sh``, a script to scan container images for | ||
vulnerabilities. In a future release, this script can be integrated into | ||
Wazuh for continuous scanning. |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,44 @@ | ||||||||||||||||||||||||||||||||||||||||
#!/bin/bash | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
# SBOM directory path | ||||||||||||||||||||||||||||||||||||||||
SBOM_DIR="/opt/kayobe/stackhpc/sboms" | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
# Ensure the SBOM directory exists | ||||||||||||||||||||||||||||||||||||||||
mkdir -p "$SBOM_DIR" | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
# Ensure the custom output template exists | ||||||||||||||||||||||||||||||||||||||||
cat <<EOL > "$SBOM_DIR/trivy-custom.tmpl" | ||||||||||||||||||||||||||||||||||||||||
"Package","Version Installed","Vulnerability ID","Severity","Title" | ||||||||||||||||||||||||||||||||||||||||
{{- range \$ri, \$r := . }} | ||||||||||||||||||||||||||||||||||||||||
{{- range \$vi, \$v := .Vulnerabilities }} | ||||||||||||||||||||||||||||||||||||||||
"{{ $v.PkgName }}","{{$v.InstalledVersion }}","{{ $v.VulnerabilityID }}","{{$v.Severity }}","{{$v.Title }}" | ||||||||||||||||||||||||||||||||||||||||
{{- end}} | ||||||||||||||||||||||||||||||||||||||||
{{- end }} | ||||||||||||||||||||||||||||||||||||||||
EOL | ||||||||||||||||||||||||||||||||||||||||
Comment on lines
+9
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current template generation has several issues:
I suggest replacing this block to create a header-less template only if it doesn't exist. Using
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
# Loop through each container image and process its SBOM | ||||||||||||||||||||||||||||||||||||||||
docker image ls --format "{{.Repository}}:{{.Tag}}" | sort | uniq | while read -r image; do | ||||||||||||||||||||||||||||||||||||||||
# Generate SBOM filename | ||||||||||||||||||||||||||||||||||||||||
sbom_file="$SBOM_DIR/$(echo "$image" | tr '/:' '_').sbom" | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
# Generate SBOM if missing | ||||||||||||||||||||||||||||||||||||||||
if [[ ! -f "$sbom_file" ]]; then | ||||||||||||||||||||||||||||||||||||||||
echo "Generating SBOM for $image" | ||||||||||||||||||||||||||||||||||||||||
if ! trivy image --quiet --format spdx-json --output "$sbom_file" "$image"; then | ||||||||||||||||||||||||||||||||||||||||
echo "Failed to generate SBOM for $image. Skipping." | ||||||||||||||||||||||||||||||||||||||||
continue | ||||||||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
echo "Scanning SBOM: $sbom_file" | ||||||||||||||||||||||||||||||||||||||||
# Scan SBOM and prepend image info to each output line | ||||||||||||||||||||||||||||||||||||||||
trivy sbom \ | ||||||||||||||||||||||||||||||||||||||||
--scanners vuln \ | ||||||||||||||||||||||||||||||||||||||||
--severity CRITICAL,HIGH \ | ||||||||||||||||||||||||||||||||||||||||
--ignore-unfixed \ | ||||||||||||||||||||||||||||||||||||||||
--quiet \ | ||||||||||||||||||||||||||||||||||||||||
--format template \ | ||||||||||||||||||||||||||||||||||||||||
--template "@$SBOM_DIR/trivy-custom.tmpl" \ | ||||||||||||||||||||||||||||||||||||||||
"$sbom_file" | \ | ||||||||||||||||||||||||||||||||||||||||
awk -v img="$image" '{print "Trivy:\"" img "\"," $0}' | ||||||||||||||||||||||||||||||||||||||||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SBOM directory path is hardcoded. This reduces the script's flexibility. It's better to allow this to be configured via an environment variable, with the current path as a default.