@@ -1 +1,2 @@
|
|||||||
__pycache__/
|
__pycache__/
|
||||||
|
security-reports/
|
||||||
Vendored
+7
-20
@@ -67,17 +67,11 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6.4.5 (kholmes): dependency + secret checks on the source.
|
// 6.4.5: dependency and secret checks on the source. Fails closed:
|
||||||
|
// a missing script, a scanner error, or a finding stops the run.
|
||||||
stage('Security scan: source') {
|
stage('Security scan: source') {
|
||||||
steps {
|
steps { sh 'bash security/scan.sh source' }
|
||||||
sh '''
|
post { always { archiveArtifacts artifacts: 'security-reports/**', allowEmptyArchive: true } }
|
||||||
if [ -x security/scan.sh ]; then
|
|
||||||
security/scan.sh source
|
|
||||||
else
|
|
||||||
echo "security/scan.sh not added yet (6.4.5)"
|
|
||||||
fi
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build image') {
|
stage('Build image') {
|
||||||
@@ -88,17 +82,10 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6.4.5 (kholmes): image vulnerability scan before publishing.
|
// 6.4.5: image vulnerability scan before publishing. Fails closed.
|
||||||
stage('Security scan: image') {
|
stage('Security scan: image') {
|
||||||
steps {
|
steps { sh 'bash security/scan.sh image "$IMAGE_TAG"' }
|
||||||
sh '''
|
post { always { archiveArtifacts artifacts: 'security-reports/**', allowEmptyArchive: true } }
|
||||||
if [ -x security/scan.sh ]; then
|
|
||||||
security/scan.sh image "$IMAGE_TAG"
|
|
||||||
else
|
|
||||||
echo "security/scan.sh not added yet (6.4.5)"
|
|
||||||
fi
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Publish') {
|
stage('Publish') {
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Security gates for the delivery pipeline (manual Chapter 11, "Apply Proportionate
|
||||||
|
# Security Gates"). Usage:
|
||||||
|
# security/scan.sh source dependency audit + secret/vulnerability scan of the repo
|
||||||
|
# security/scan.sh image <image-ref> 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.
|
||||||
|
# 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".
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
MODE="${1:-}"
|
||||||
|
REPORT_DIR="${REPORT_DIR:-security-reports}"
|
||||||
|
SEVERITY="HIGH,CRITICAL"
|
||||||
|
IGNOREFILE="security/.trivyignore"
|
||||||
|
export PATH="/opt/tools-venv/bin:$PATH"
|
||||||
|
|
||||||
|
now() { date -u +%Y-%m-%dT%H:%M:%SZ; }
|
||||||
|
mkdir -p "$REPORT_DIR"
|
||||||
|
|
||||||
|
ignore_args=()
|
||||||
|
if [ -f "$IGNOREFILE" ]; then ignore_args=(--ignorefile "$IGNOREFILE"); fi
|
||||||
|
|
||||||
|
record_versions() {
|
||||||
|
{
|
||||||
|
echo "scan_time_utc: $(now)"
|
||||||
|
echo "--- trivy (tool and vulnerability database versions) ---"
|
||||||
|
trivy --version
|
||||||
|
echo "--- pip-audit ---"
|
||||||
|
pip-audit --version
|
||||||
|
} | tee "$REPORT_DIR/tool-versions.txt"
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$MODE" in
|
||||||
|
source)
|
||||||
|
record_versions
|
||||||
|
echo "== pip-audit: dependency audit of pricing/requirements.txt =="
|
||||||
|
# --strict: a dependency that cannot be audited is a failure, not a pass.
|
||||||
|
pip-audit -r pricing/requirements.txt --strict --progress-spinner off \
|
||||||
|
2>&1 | tee "$REPORT_DIR/pip-audit.txt"
|
||||||
|
echo "RESULT pip-audit: exit=0 at $(now)"
|
||||||
|
|
||||||
|
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[@]}" . \
|
||||||
|
2>&1 | tee "$REPORT_DIR/trivy-source.txt"
|
||||||
|
echo "RESULT trivy-fs: exit=0 at $(now)"
|
||||||
|
;;
|
||||||
|
image)
|
||||||
|
REF="${2:?usage: scan.sh image <image-ref>}"
|
||||||
|
record_versions
|
||||||
|
echo "== trivy image: $SEVERITY vulnerabilities in $REF =="
|
||||||
|
trivy image --severity "$SEVERITY" --exit-code 1 --no-progress \
|
||||||
|
"${ignore_args[@]}" "$REF" \
|
||||||
|
2>&1 | tee "$REPORT_DIR/trivy-image.txt"
|
||||||
|
echo "RESULT trivy-image: exit=0 at $(now)"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "usage: security/scan.sh source | image <image-ref>" >&2
|
||||||
|
exit 2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
Reference in New Issue
Block a user