From ad37d148ed90052f5a1a7b33eace77b7dba5db34 Mon Sep 17 00:00:00 2001 From: Kay-H7 Date: Fri, 13 Nov 2026 18:48:15 -0500 Subject: [PATCH] updated security --- Jenkinsfile | 2 +- security/POLICY.md | 30 ++++++++++++++++++++++++++++++ security/scan.sh | 37 +++++++++++++++++++++++++++++++------ 3 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 security/POLICY.md diff --git a/Jenkinsfile b/Jenkinsfile index ac45d8b..273bf62 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -172,4 +172,4 @@ proxy_network: gitea-net success { echo 'All stages passed.' } failure { echo 'A stage failed: see the stage view for which one.' } } -} +} \ No newline at end of file diff --git a/security/POLICY.md b/security/POLICY.md new file mode 100644 index 0000000..eec336e --- /dev/null +++ b/security/POLICY.md @@ -0,0 +1,30 @@ +# Security gate policy (defined before the assessed release) + +**Tools:** Trivy (repository and image scanning, secret detection) and pip-audit +(Python dependency audit). Tool and vulnerability-database versions, scan time, +commands, reports and exit codes are recorded by `security/scan.sh` and archived +by Jenkins as `security-reports/**`. + +**Blocking (the pipeline fails):** +- any detected secret; +- any known vulnerability reported by pip-audit for the locked dependencies; +- any HIGH or CRITICAL vulnerability in the repository or the built image that + has a fix available; +- any scanner error, missing tool, or failure to obtain the vulnerability + database. A failed scan is not a clean scan. + +**Not blocking, but recorded:** HIGH or CRITICAL vulnerabilities with no fix yet +(typically operating-system packages in the base image). They are listed in the +full image report and counted in `image-summary.txt` on every run. The accepted +set is recorded in the manual as a time-limited exception with a review date. +Nothing is silently ignored. + +**Fixes:** update the dependency lockfile or the pinned base-image digest, +rebuild, and rescan. Dependency or base-image updates always trigger a rescan. + +**False positives and exceptions:** a finding that has a fix but is accepted for +a stated reason goes in `security/.trivyignore` with an `exp:` date and a +comment naming the reason and the approver. Expired entries stop applying. + +**Test fixture:** one blocked run uses a synthetic, scanner-supported fixture +(never a live secret) on a branch; it is removed and the run repeated. diff --git a/security/scan.sh b/security/scan.sh index 7b08b2c..11fc448 100644 --- a/security/scan.sh +++ b/security/scan.sh @@ -4,8 +4,15 @@ # security/scan.sh source dependency audit + secret/vulnerability scan of the repo # security/scan.sh image vulnerability scan of the built image # -# Policy: block detected secrets and HIGH/CRITICAL vulnerabilities unless an -# entry in security/.trivyignore (with an expiry date and a reason) accepts them. +# Policy (full text in security/POLICY.md): +# * Detected secrets always block. +# * Dependency vulnerabilities reported by pip-audit always block. +# * HIGH/CRITICAL vulnerabilities that HAVE A FIX AVAILABLE block (--ignore-unfixed). +# * HIGH/CRITICAL vulnerabilities with no fix yet do not block, but are never +# hidden: an informational full report and a summary are saved and archived, +# and the accepted set is recorded as a dated exception in the manual. +# * A time-limited exception for a fixable finding goes in security/.trivyignore +# (with an exp: date and a reason). # FAIL CLOSED: any scanner error, missing tool, or vulnerability-database # download failure ends the script with a non-zero status. A failed scan is not # a clean scan. Nothing here ends in "|| true". @@ -44,18 +51,36 @@ case "$MODE" in echo "== trivy fs: secrets and $SEVERITY vulnerabilities in the repository ==" trivy fs --scanners vuln,secret --severity "$SEVERITY" --exit-code 1 \ - --no-progress --skip-dirs .git,.venv "${ignore_args[@]}" . \ + --ignore-unfixed --no-progress --skip-dirs .git,.venv "${ignore_args[@]}" . \ 2>&1 | tee "$REPORT_DIR/trivy-source.txt" echo "RESULT trivy-fs: exit=0 at $(now)" ;; image) REF="${2:?usage: scan.sh image }" record_versions - echo "== trivy image: $SEVERITY vulnerabilities in $REF ==" - trivy image --severity "$SEVERITY" --exit-code 1 --no-progress \ + echo "== trivy image: fixable $SEVERITY vulnerabilities in $REF (blocking) ==" + trivy image --severity "$SEVERITY" --exit-code 1 --ignore-unfixed --no-progress \ "${ignore_args[@]}" "$REF" \ 2>&1 | tee "$REPORT_DIR/trivy-image.txt" - echo "RESULT trivy-image: exit=0 at $(now)" + echo "RESULT trivy-image (fixable findings): exit=0 at $(now)" + + echo "== trivy image: full informational report (does not gate; errors still fail) ==" + # --exit-code 0 means findings alone do not fail this run; a scanner or + # database error still does. This keeps unfixed findings visible, not hidden. + trivy image --severity "$SEVERITY" --exit-code 0 --no-progress \ + --format json -o "$REPORT_DIR/trivy-image-full.json" "$REF" + python3 - "$REPORT_DIR/trivy-image-full.json" <<'PY' | tee "$REPORT_DIR/image-summary.txt" +import json, sys, collections +d = json.load(open(sys.argv[1])) +c = collections.Counter() +for r in d.get("Results", []): + for v in r.get("Vulnerabilities") or []: + c[(v["Severity"], "fix available" if v.get("FixedVersion") else "no fix yet")] += 1 +print("image findings at HIGH/CRITICAL (all, including unfixed):") +for k, n in sorted(c.items()): + print(" %-9s %-14s %d" % (k[0], k[1], n)) +print(" total", sum(c.values())) +PY ;; *) echo "usage: security/scan.sh source | image " >&2