ci: add Harbor vulnerability scan after image push
All checks were successful
CI / Lint & Format (push) Successful in 23s
CI / Security Scan (push) Successful in 22s
CI / Memory Leak Check (push) Successful in 21s
CI / SBOM Generation (push) Successful in 20s
CI / Security Tests (push) Successful in 26s
CI / Unit Tests (push) Successful in 33s
CI / Advanced Security Tests (push) Successful in 15s
CI / Build & Push Image (push) Successful in 7s
CI / Harbor Vulnerability Scan (push) Successful in 13s
All checks were successful
CI / Lint & Format (push) Successful in 23s
CI / Security Scan (push) Successful in 22s
CI / Memory Leak Check (push) Successful in 21s
CI / SBOM Generation (push) Successful in 20s
CI / Security Tests (push) Successful in 26s
CI / Unit Tests (push) Successful in 33s
CI / Advanced Security Tests (push) Successful in 15s
CI / Build & Push Image (push) Successful in 7s
CI / Harbor Vulnerability Scan (push) Successful in 13s
This commit is contained in:
@@ -310,3 +310,74 @@ jobs:
|
|||||||
$BUILD_CMD push "${HARBOR_REGISTRY}/library/flaskpaste:${tag}"
|
$BUILD_CMD push "${HARBOR_REGISTRY}/library/flaskpaste:${tag}"
|
||||||
echo "Pushed: ${HARBOR_REGISTRY}/library/flaskpaste:${tag}"
|
echo "Pushed: ${HARBOR_REGISTRY}/library/flaskpaste:${tag}"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
vuln-scan:
|
||||||
|
name: Harbor Vulnerability Scan
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [build-push]
|
||||||
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
|
container:
|
||||||
|
image: python:3.11-slim
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Setup
|
||||||
|
run: |
|
||||||
|
apt-get update -qq && apt-get install -yqq --no-install-recommends git curl >/dev/null
|
||||||
|
|
||||||
|
- name: Fetch harbor-ctl
|
||||||
|
run: |
|
||||||
|
curl -sL "https://git.mymx.me/username/harbor/raw/branch/master/harbor-ctl.py" -o harbor-ctl.py
|
||||||
|
chmod +x harbor-ctl.py
|
||||||
|
|
||||||
|
- name: Trigger and wait for scan
|
||||||
|
env:
|
||||||
|
HARBOR_USER: ${{ secrets.HARBOR_USER }}
|
||||||
|
HARBOR_PASS: ${{ secrets.HARBOR_PASS }}
|
||||||
|
run: |
|
||||||
|
if [ -z "$HARBOR_USER" ] || [ -z "$HARBOR_PASS" ]; then
|
||||||
|
echo "::warning::Harbor credentials not configured - skipping scan"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Triggering vulnerability scan..."
|
||||||
|
python harbor-ctl.py --url https://harbor.mymx.me \
|
||||||
|
-u "$HARBOR_USER" -p "$HARBOR_PASS" \
|
||||||
|
scan library flaskpaste --wait --timeout 180
|
||||||
|
|
||||||
|
- name: Check for critical vulnerabilities
|
||||||
|
env:
|
||||||
|
HARBOR_USER: ${{ secrets.HARBOR_USER }}
|
||||||
|
HARBOR_PASS: ${{ secrets.HARBOR_PASS }}
|
||||||
|
run: |
|
||||||
|
if [ -z "$HARBOR_USER" ]; then exit 0; fi
|
||||||
|
|
||||||
|
echo "Checking for fixable critical/high vulnerabilities..."
|
||||||
|
|
||||||
|
# Get vulnerability report
|
||||||
|
python harbor-ctl.py --url https://harbor.mymx.me \
|
||||||
|
-u "$HARBOR_USER" -p "$HARBOR_PASS" \
|
||||||
|
vulns library flaskpaste -s critical -l 100 > /tmp/critical.txt 2>&1 || true
|
||||||
|
|
||||||
|
python harbor-ctl.py --url https://harbor.mymx.me \
|
||||||
|
-u "$HARBOR_USER" -p "$HARBOR_PASS" \
|
||||||
|
vulns library flaskpaste -s high -l 100 > /tmp/high.txt 2>&1 || true
|
||||||
|
|
||||||
|
# Check for fixable vulns (have a "Fixed" version that's not "N/A")
|
||||||
|
CRITICAL_FIXABLE=$(grep -v "N/A *$" /tmp/critical.txt | grep -c "^CVE\|^GHSA" || echo 0)
|
||||||
|
HIGH_FIXABLE=$(grep -v "N/A *$" /tmp/high.txt | grep -c "^CVE\|^GHSA" || echo 0)
|
||||||
|
|
||||||
|
echo "Critical fixable: $CRITICAL_FIXABLE"
|
||||||
|
echo "High fixable: $HIGH_FIXABLE"
|
||||||
|
|
||||||
|
if [ "$CRITICAL_FIXABLE" -gt 0 ]; then
|
||||||
|
echo "::error::Found $CRITICAL_FIXABLE fixable critical vulnerabilities"
|
||||||
|
cat /tmp/critical.txt
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$HIGH_FIXABLE" -gt 0 ]; then
|
||||||
|
echo "::warning::Found $HIGH_FIXABLE fixable high vulnerabilities"
|
||||||
|
cat /tmp/high.txt
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Vulnerability scan passed"
|
||||||
|
|||||||
Reference in New Issue
Block a user