diff --git a/docker-compose.yml b/docker-compose.yml index ce071d3f..5fb028d6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,6 +5,7 @@ services: # image: docker-bench-security # use build path to Dockerfile if docker-compose should build the image + image: docker-bench-security build: . cap_add: @@ -19,3 +20,11 @@ services: - /var/run/docker.sock:/var/run/docker.sock:ro - /usr/lib/systemd:/usr/lib/systemd:ro - /etc:/etc:ro + - ./log:/log + + report: + image: nginx:alpine + ports: + - "8099:80" + volumes: + - ./log:/usr/share/nginx/html:ro diff --git a/generate_report.py b/generate_report.py new file mode 100644 index 00000000..5dc61ced --- /dev/null +++ b/generate_report.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 +import json, sys, pathlib + +log_dir = pathlib.Path(__file__).parent / "log" +json_file = log_dir / "docker-bench-security.log.json" +output_file = log_dir / "report.html" + +with open(json_file) as f: + data = json.load(f) + +COLORS = {"PASS": "#2ecc71", "WARN": "#e74c3c", "INFO": "#3498db", "NOTE": "#f39c12"} +BG = {"PASS": "#eafaf1", "WARN": "#fdedec", "INFO": "#eaf4fb", "NOTE": "#fef9e7"} + +rows = [] +totals = {"PASS": 0, "WARN": 0, "INFO": 0, "NOTE": 0} + +for section in data.get("tests", []): + rows.append(f'' + f'{section["id"]} — {section["desc"]}') + for r in section.get("results", []): + result = r.get("result", "INFO") + totals[result] = totals.get(result, 0) + 1 + color = COLORS.get(result, "#999") + bg = BG.get(result, "#fff") + details = r.get("details", "") + items = "
".join(r.get("items", [])) + extra = (details + ("
" if details and items else "") + items).strip() + rows.append( + f'' + f'{result}' + f'{r["id"]}' + f'{r["desc"]}' + f'{extra}' + f'' + ) + +score = data.get("score", "?") +html = f""" + + + +Docker Bench Security Report + + + +

Docker Bench for Security v{data.get("dockerbenchsecurity","?")} — Reporte

+
+
Score: {score}
+
PASS: {totals.get("PASS",0)}
+
WARN: {totals.get("WARN",0)}
+
INFO: {totals.get("INFO",0)}
+
NOTE: {totals.get("NOTE",0)}
+
+ + + + + {"".join(rows)} +
ResultadoIDDescripciónDetalle
+ +""" + +output_file.write_text(html) +print(f"Reporte generado: {output_file}")