From 114593361228013917cfca68f7a376742dbd50a9 Mon Sep 17 00:00:00 2001 From: Bendeguz Sulyok Date: Thu, 19 Nov 2026 14:51:47 +0000 Subject: [PATCH] initial commit --- README.md | 35 ++++++++++++++++++++++++++ config.json | 7 ++++++ run.sh | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 README.md create mode 100644 config.json create mode 100755 run.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..1c523a7 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# Automated Security Reporting with Trivy + +## Purpose +[Trviy](https://trivy.dev/) is a sucurity reporting tool equipped to find vulnerabilities (CVEs) and misconfigurations (e.g.: visible sensitive information) in container images, repositories and binary artifacts. +In this repo I provide a small and configurable setup for automating the generation of trivy reports. + +## Usage + +Clone the repository! + +### Configuration +Edit the exemplary `config.json` file by adding your own applications for scanning: +``` +[ + { + "id": "hello_world", + "type": "docker_image", + "image": "hello-world:latest" + } +] +``` +- `id` is merely used for naming the produced reports. +- `type` can currently only be "docker\_image" +- `image` is the exact name of the docker image + +### Deploying + +Run the script as follows: +``` +bash ./run.sh +``` +Parameters: +- `config`: path to the config file above introduced (default: `./config.json`) +- `outdir`: the produced reports will be saved in a timestamped folder within this directory (defaul: `./reports`) +- `docker\_socket` (default: `/var/run/docker.sock`) diff --git a/config.json b/config.json new file mode 100644 index 0000000..cda173c --- /dev/null +++ b/config.json @@ -0,0 +1,7 @@ +[ + { + "id": "hello_world", + "type": "docker_image", + "image": "hello-world:latest" + } +] diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..0b6edae --- /dev/null +++ b/run.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash +set -euo pipefail + +scriptdir=$(dirname "$(realpath $0)") + +config_json="$scriptdir/config.json" +output_dir="$scriptdir/reports" +docker_socket="/var/run/docker.sock" + +usage() { + cat >&2 <] [--env ] + -c, --config Path to config JSON file (default: "config.json") + -o, --outdir Output directory (default: "reports") + --docker-socket Docker socket path (default: "/var/run/docker.sock") + -h, --help Show this help message +EOF + exit 1 +} + +while [[ $# -gt 0 ]]; do + case "$1" in + -c|--config) + [[ $# -ge 2 ]] || { echo "Error: $1 requires a value." >&2; usage; } + config_json="$2" + shift 2 + ;; + -o|--outdir) + [[ $# -ge 2 ]] || { echo "Error: $1 requires a value." >&2; usage; } + output_directory="$2" + shift 2 + ;; + -docker-socket) + [[ $# -ge 2 ]] || { echo "Error: $1 requires a value." >&2; usage; } + docker_socket="$2" + shift 2 + ;; + -h|--help) + usage + ;; + *) + echo "Error: Unknown option '$1'" >&2 + usage + ;; + esac +done + +reports_dir="$output_dir/$(date --utc +%Y_%m_%d_%H_%M_%S)" +echo "Saving trivy reports to $reports_dir" + +while IFS= read -r item; do + app_id=$(printf '%s' "$item" | jq -r '.id') + app_type=$(printf '%s' "$item" | jq -r '.type') + app_image=$(printf '%s' "$item" | jq -r '.image') + + echo "Processing $app_id" + image_dir="$reports_dir/$app_id" + mkdir -p "$image_dir" + command_file="$image_dir/command.txt" + execution_log="$image_dir/execution_log.txt" + echo "docker run --rm\\" >> "$command_file" + echo " -v $docker_socket:/var/run/docker.sock:ro \\" >> "$command_file" + echo " -v $image_dir:/output \\" >> "$command_file" + echo " aquasec/trivy:latest image \\" >> "$command_file" + echo " --severity HIGH,CRITICAL \\" >> "$command_file" + echo " --output /output/report.txt \\" >> "$command_file" + echo " $app_image" >> "$command_file" + echo "" >> "$command_file" + + bash "$command_file" > "$execution_log" 2>&1 +done < <(jq -c '.[]' "$config_json")