feat(trivy): Enhance Trivy report generation and metrics handling

- Updated `generate_report.sh` to include additional scanners and output paths.
- Enhanced `send_report.py` with new data classes for misconfigurations and vulnerabilities.
- Improved parsing logic for Trivy output, supporting both Kubernetes and image scans.
- Added Prometheus metrics generation for various scan results, including misconfigurations and vulnerabilities.
- Introduced unit tests for parsing Trivy output and generating Prometheus metrics.
- Modified Terraform variables for SMTP port type and added Pushgateway URL variable.
This commit is contained in:
2026-05-22 23:41:26 +02:00
parent 829ab48919
commit 255ba6aec9
25 changed files with 410938 additions and 71 deletions
@@ -1,6 +1,7 @@
locals {
app_version = var.tag
prometheus_folder = "${var.persistent_folder}/prometheus"
pushgateway_folder = "${var.persistent_folder}/pushgateway"
alertmanager_folder = "${var.persistent_folder}/alertmanager"
prometheus_default_config = yamldecode(file("${path.module}/resources/prometheus.yml"))
@@ -0,0 +1,104 @@
resource "kubernetes_deployment" "pushgateway" {
metadata {
name = "pushgateway"
namespace = kubernetes_namespace.prometheus.metadata[0].name
labels = {
app = "pushgateway"
}
}
spec {
replicas = 1
strategy {
type = "Recreate"
}
selector {
match_labels = {
app = "pushgateway"
}
}
template {
metadata {
labels = {
app = "pushgateway"
}
annotations = {
"prometheus.io/scrape" = "true"
"prometheus.io/port" = "9091"
}
}
spec {
automount_service_account_token = false
security_context {
run_as_non_root = true
run_as_user = 65534
run_as_group = 65534
seccomp_profile {
type = "RuntimeDefault"
}
}
container {
name = "pushgateway"
image = "prom/pushgateway:${local.app_version}"
args = ["--persistence.file=/pushgateway/metrics"]
port {
name = "http"
container_port = 9091
}
security_context {
run_as_non_root = true
run_as_user = 65534
run_as_group = 65534
allow_privilege_escalation = false
privileged = false
read_only_root_filesystem = true
capabilities {
drop = ["ALL"]
}
}
volume_mount {
name = "pushgateway-storage-volume"
mount_path = "/pushgateway"
}
}
volume {
name = "pushgateway-storage-volume"
host_path {
path = local.pushgateway_folder
type = "DirectoryOrCreate"
}
}
}
}
}
}
resource "kubernetes_service" "pushgateway" {
metadata {
name = "pushgateway"
namespace = kubernetes_namespace.prometheus.metadata[0].name
}
spec {
selector = {
app = "pushgateway"
}
type = "ClusterIP"
port {
port = 9091
protocol = "TCP"
target_port = "http"
}
}
}
@@ -36,6 +36,10 @@ scrape_configs:
regex: '^/system\.slice/(.+)\.service$'
target_label: systemd_service_name
replacement: "${1}"
- job_name: pushgateway
honor_labels: true
static_configs:
- targets: ["pushgateway.prometheus.svc.cluster.local:9091"]
alerting:
alertmanagers:
- static_configs: