ci(bstein-home): run sonar and supply-chain scans
This commit is contained in:
parent
d2d0daeff1
commit
ad44bc40c3
57
Jenkinsfile
vendored
57
Jenkinsfile
vendored
@ -58,6 +58,13 @@ spec:
|
|||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: workspace-volume
|
- name: workspace-volume
|
||||||
mountPath: /home/jenkins/agent
|
mountPath: /home/jenkins/agent
|
||||||
|
- name: quality-tools
|
||||||
|
image: registry.bstein.dev/bstein/quality-tools:sonar8.0.1-trivy0.70.0-arm64
|
||||||
|
command: ["cat"]
|
||||||
|
tty: true
|
||||||
|
volumeMounts:
|
||||||
|
- name: workspace-volume
|
||||||
|
mountPath: /home/jenkins/agent
|
||||||
volumes:
|
volumes:
|
||||||
- name: workspace-volume
|
- name: workspace-volume
|
||||||
emptyDir: {}
|
emptyDir: {}
|
||||||
@ -108,6 +115,28 @@ spec:
|
|||||||
|
|
||||||
stage('Collect SonarQube evidence') {
|
stage('Collect SonarQube evidence') {
|
||||||
steps {
|
steps {
|
||||||
|
container('quality-tools') {
|
||||||
|
sh '''#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
mkdir -p build
|
||||||
|
args=(
|
||||||
|
"-Dsonar.host.url=${SONARQUBE_HOST_URL}"
|
||||||
|
"-Dsonar.token=${SONARQUBE_TOKEN}"
|
||||||
|
"-Dsonar.projectKey=${SONARQUBE_PROJECT_KEY}"
|
||||||
|
"-Dsonar.projectName=${SONARQUBE_PROJECT_KEY}"
|
||||||
|
"-Dsonar.sources=."
|
||||||
|
"-Dsonar.exclusions=**/.git/**,**/build/**,**/dist/**,**/node_modules/**,**/.venv/**,**/__pycache__/**,**/coverage/**,**/test-results/**,**/playwright-report/**,frontend/public/media/**"
|
||||||
|
"-Dsonar.test.inclusions=**/tests/**,**/testing/**,**/*_test.go,**/*.test.ts,**/*.test.tsx,**/*.spec.ts,**/*.spec.tsx"
|
||||||
|
)
|
||||||
|
[ -f build/backend-coverage.xml ] && args+=("-Dsonar.python.coverage.reportPaths=build/backend-coverage.xml")
|
||||||
|
[ -f frontend/coverage/lcov.info ] && args+=("-Dsonar.javascript.lcov.reportPaths=frontend/coverage/lcov.info")
|
||||||
|
set +e
|
||||||
|
sonar-scanner "${args[@]}" | tee build/sonar-scanner.log
|
||||||
|
rc=${PIPESTATUS[0]}
|
||||||
|
set -e
|
||||||
|
printf '%s\n' "${rc}" > build/sonarqube-analysis.rc
|
||||||
|
'''
|
||||||
|
}
|
||||||
container('tester') {
|
container('tester') {
|
||||||
sh '''
|
sh '''
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
@ -146,6 +175,34 @@ PY
|
|||||||
|
|
||||||
stage('Collect Supply Chain evidence') {
|
stage('Collect Supply Chain evidence') {
|
||||||
steps {
|
steps {
|
||||||
|
container('quality-tools') {
|
||||||
|
sh '''#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
mkdir -p build
|
||||||
|
set +e
|
||||||
|
trivy fs --no-progress --format json --output build/trivy-fs.json --scanners vuln,secret,misconfig --severity HIGH,CRITICAL .
|
||||||
|
trivy_rc=$?
|
||||||
|
set -e
|
||||||
|
if [ ! -s build/trivy-fs.json ]; then
|
||||||
|
cat > build/ironbank-compliance.json <<EOF
|
||||||
|
{"status":"failed","compliant":false,"scanner":"trivy","scan_type":"filesystem","error":"trivy did not produce JSON output","trivy_rc":${trivy_rc}}
|
||||||
|
EOF
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
critical="$(jq '[.Results[]? | .Vulnerabilities[]? | select(.Severity=="CRITICAL")] | length' build/trivy-fs.json)"
|
||||||
|
high="$(jq '[.Results[]? | .Vulnerabilities[]? | select(.Severity=="HIGH")] | length' build/trivy-fs.json)"
|
||||||
|
secrets="$(jq '[.Results[]? | .Secrets[]?] | length' build/trivy-fs.json)"
|
||||||
|
misconfigs="$(jq '[.Results[]? | .Misconfigurations[]? | select(.Status=="FAIL" and (.Severity=="CRITICAL" or .Severity=="HIGH"))] | length' build/trivy-fs.json)"
|
||||||
|
status=ok
|
||||||
|
compliant=true
|
||||||
|
if [ "${critical}" -gt 0 ] || [ "${secrets}" -gt 0 ] || [ "${misconfigs}" -gt 0 ]; then
|
||||||
|
status=failed
|
||||||
|
compliant=false
|
||||||
|
fi
|
||||||
|
jq -n --arg status "${status}" --argjson compliant "${compliant}" --argjson critical "${critical}" --argjson high "${high}" --argjson secrets "${secrets}" --argjson misconfigs "${misconfigs}" --argjson trivy_rc "${trivy_rc}" \
|
||||||
|
'{status:$status, compliant:$compliant, category:"artifact_security", scan_type:"filesystem", scanner:"trivy", critical_vulnerabilities:$critical, high_vulnerabilities:$high, secrets:$secrets, high_or_critical_misconfigurations:$misconfigs, trivy_rc:$trivy_rc, high_vulnerability_policy:"observe"}' > build/ironbank-compliance.json
|
||||||
|
'''
|
||||||
|
}
|
||||||
container('tester') {
|
container('tester') {
|
||||||
sh '''
|
sh '''
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user