This project is a Bash script (scan_with_options.sh
) designed to automate the process of scanning container images defined in a Helm chart for vulnerabilities. It uses either Anchore Grype or Aqua Trivy for vulnerability scanning and outputs results in a CSV file with the following fields:
image:tag
component/library
vulnerability
severity
The script retrieves a specified Helm chart, extracts the container images it deploys, scans these images for vulnerabilities of severity Medium or higher, and saves the results in a CSV file named with the scan date.
- Support for Two Scanners: Choose between Grype or Trivy for scanning container images.
- Customizable Helm Chart Retrieval: Specify Helm repository URL, chart name, and chart version.
- CSV Output: Outputs vulnerability scan results in a clear, structured format.
- Cleanup: Automatically removes temporary resources after the process (unless any error occurs, in that case script keeps the temporary files for troubleshooting purposes).
- Docker (for running vulnerability scanners)
- Helm (for retrieving and templating Helm charts)
- jq (for processing JSON output from scanners)
Run the script as follows:
./scan_with_options.sh --repourl <url> --chart <chart_name> --chartversion <version> --scanner <scan_tool>
--repourl
: The URL of the Helm chart repository (e.g.,https://charts.bitnami.com/bitnami
).--chart
: The name of the Helm chart (e.g.,wordpress
).--chartversion
: The version of the Helm chart (e.g.,10.0.0
).--scanner
: The scanning tool to use (grype
ortrivy
).
./scan_with_options.sh --repourl=https://charts.bitnami.com/bitnami --chart=wordpress --chartversion=10.0.0 --scanner=grype
- The user has access to a Helm repository that contains the desired chart.
- All container images used in the Helm chart can be scanned directly without requiring special authentication.
- The script focuses on vulnerabilities of severity Medium or higher to prioritize actionable issues.
- Cleanup of temporary files and directories is handled automatically to avoid clutter.
This project involved AI assistance in the following areas:
- Code Suggestions: The Bash script structure, argument parsing, and the logic for handling scanners were partially AI-generated. Adjustments included:
- Adding error handling for missing dependencies.
- Fine-tuning
jq
queries for Grype and Trivy JSON output. - Ensuring compatibility with Helm templates.
- Debugging: The AI suggested fixes for parsing Helm chart images and handling cases where multiple images were defined in a chart.
These suggestions were manually tested and refined to align with the project's requirements.
AI failed to create jq queries properly and for this I believe it does not know latest output format. I had to adjust queries to match with outputs.
Also while scanning the image names, regex written by ai was not properly grabbing the image names, I had to adjust the query.
Given more time, the following improvements could be made:
- Enhanced Error Handling: Add more descriptive error messages and edge-case handling, such as invalid chart versions, missing Docker images, failed output.
- Parallel Scanning: Improve performance by scanning multiple images in parallel.
- Dynamic Severity Threshold: Allow users to define their own severity threshold for filtering vulnerabilities.
- Integration Tests: Add automated tests to validate the script’s functionality in various scenarios.
- Logging: Include a logging mechanism to track script activity for troubleshooting.
- I created bash script using my existing snippets. No comment, no failsafe check.
- I provided exact prompt in the assignemt to ChatGPT with my code and reviewed the output. I believe even if I just provide the assignment, ChatGPT will output usable code.
- I run the code against a couple public helm charts for sanity check. I've found a couple errors and tried to fix as much as possible within givin time.
- After finishing the code, I created a step by step instructions with high level technical not detailed infromation. I provided the next prompt and my notes including instructions and imporovement suggestions to create README file.
- As like the code, I reviewed the README file as well.
This project is open source and available under the BSD License.