commit
1145933612
@ -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`)
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "hello_world",
|
||||||
|
"type": "docker_image",
|
||||||
|
"image": "hello-world:latest"
|
||||||
|
}
|
||||||
|
]
|
||||||
@ -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 <<EOF
|
||||||
|
Usage: $0 [--file <path>] [--env <name>]
|
||||||
|
-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")
|
||||||
Loading…
Reference in new issue