Security Scan (OSV + Cppcheck) #98
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Security Scan (OSV + Cppcheck) | |
| on: | |
| pull_request: | |
| branches: [main] | |
| push: | |
| branches: [main] | |
| schedule: | |
| - cron: "0 5 * * *" # Nightly full scan at 05:00 UTC | |
| workflow_dispatch: {} | |
| jobs: | |
| security-scan: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Go (for osv-scanner) | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: "1.22" | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y cppcheck python3 python3-pip cmake | |
| - name: Ensure build (generate compile_commands) | |
| run: | | |
| cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug | |
| - name: Restore cppcheck cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: build/cppcheck-cache | |
| key: cppcheck-${{ runner.os }}-${{ hashFiles('libs/**/*.cpp', 'libs/**/*.h', 'apps/**/*.cpp', 'apps/**/*.h') }} | |
| restore-keys: | | |
| cppcheck-${{ runner.os }}- | |
| - name: Run security scan (OSV + Cppcheck) | |
| id: security | |
| continue-on-error: true | |
| run: | | |
| set -o pipefail | |
| SCAN_FLAGS="--install" | |
| # PR runs get fast mode; pushes/nightly get full scan | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| SCAN_FLAGS="$SCAN_FLAGS --fast" | |
| fi | |
| python3 scripts/tool.py security scan $SCAN_FLAGS 2>&1 | tee security-scan.log || true | |
| # We capture output and continue; next step evaluates policy | |
| - name: Evaluate security policy (fail on CRITICAL; warn on HIGH) | |
| run: | | |
| set -o pipefail | |
| python3 scripts/ci/ci_security_policy.py security-scan.log || rc=$? | |
| rc=${rc:-0} | |
| if [ "$rc" -eq 2 ]; then | |
| echo "::error file=security-scan.log::Critical vulnerability found; failing policy" | |
| cat security-scan.log | |
| exit 1 | |
| elif [ "$rc" -eq 1 ]; then | |
| echo "::warning file=security-scan.log::High severity vulnerabilities detected" | |
| # keep job green but upload log for review | |
| fi | |
| - name: Upload security scan log | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: security-scan-log | |
| path: security-scan.log |