-
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,50 @@ | ||
| #!/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 | ||
| if [[ ! -f "$SBOM_DIR/trivy-custom.tmpl" ]]; then | ||
| cat <<'EOL' > "$SBOM_DIR/trivy-custom.tmpl" | ||
| {{- range $ri, $r := . -}} | ||
| {{- range $vi, $v := .Vulnerabilities -}} | ||
| "{{ $v.PkgName }}","{{$v.InstalledVersion }}","{{ $v.VulnerabilityID }}","{{$v.Severity }}","{{$v.Title }}" | ||
| {{- end -}} | ||
| {{- end -}} | ||
| EOL | ||
| fi | ||
|
|
||
| echo "Package","Version Installed","Vulnerability ID","Severity","Title" | ||
|
|
||
| # Loop through each container image and process its SBOM | ||
| docker image ls --format "{{.Repository}}:{{.Tag}}:{{.Image ID}}" | sort | uniq | while read -r image; do | ||
| # Split image ID | ||
| image_id=$(echo "$image" | awk -F: '{print $NF}') | ||
|
|
||
| # 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_id"; 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 \ | ||
|
Member
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. Would it make sense to use cosign to add in-toto attestations during our build creation process, so we can store the signed sbom in the OCI repository in the standard way? It suggests in the docs you can then verify that with trivy to understand if there are CVEs: Unsure if that works with Wazah scanning though.
Member
Author
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. It's been in the infra backlog for a little while. The plan would be to integrate it at build time. There might be a way to pull that straight to Wazuh, but I've not investigated that |
||
| --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.