|
| 1 | +name: Security Scan |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + schedule: |
| 9 | + - cron: "0 6 * * 1" |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + security-events: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + dependency-audit: |
| 18 | + name: Dependency vulnerability scan |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Set up Python |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: "3.12" |
| 27 | + |
| 28 | + - name: Install project + audit tools |
| 29 | + run: | |
| 30 | + pip install -e . |
| 31 | + pip install pip-audit safety |
| 32 | +
|
| 33 | + - name: pip-audit (PyPI advisory DB) |
| 34 | + run: pip-audit --strict --desc |
| 35 | + |
| 36 | + - name: Safety check (SafetyCLI DB) |
| 37 | + run: safety check --output json || true |
| 38 | + continue-on-error: true |
| 39 | + |
| 40 | + sast: |
| 41 | + name: Static analysis (Bandit + Semgrep) |
| 42 | + runs-on: ubuntu-latest |
| 43 | + steps: |
| 44 | + - uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: Set up Python |
| 47 | + uses: actions/setup-python@v5 |
| 48 | + with: |
| 49 | + python-version: "3.12" |
| 50 | + |
| 51 | + - name: Install Bandit |
| 52 | + run: pip install bandit[toml] |
| 53 | + |
| 54 | + - name: Bandit security scan |
| 55 | + run: bandit -r src/code_intelligence/ -f json -o bandit-report.json || true |
| 56 | + |
| 57 | + - name: Bandit summary |
| 58 | + if: always() |
| 59 | + run: bandit -r src/code_intelligence/ -f screen -ll || true |
| 60 | + |
| 61 | + - name: Semgrep SAST |
| 62 | + uses: semgrep/semgrep-action@v1 |
| 63 | + with: |
| 64 | + config: p/python p/security-audit p/owasp-top-ten |
| 65 | + continue-on-error: true |
| 66 | + |
| 67 | + wheel-scan: |
| 68 | + name: Wheel integrity scan |
| 69 | + runs-on: ubuntu-latest |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v4 |
| 72 | + |
| 73 | + - name: Set up Python |
| 74 | + uses: actions/setup-python@v5 |
| 75 | + with: |
| 76 | + python-version: "3.12" |
| 77 | + |
| 78 | + - name: Build wheel |
| 79 | + run: | |
| 80 | + pip install build |
| 81 | + python -m build |
| 82 | +
|
| 83 | + - name: Verify wheel metadata |
| 84 | + run: | |
| 85 | + pip install check-wheel-contents |
| 86 | + check-wheel-contents dist/*.whl |
| 87 | +
|
| 88 | + - name: Scan wheel with pip-audit |
| 89 | + run: | |
| 90 | + pip install pip-audit |
| 91 | + pip install dist/*.whl |
| 92 | + pip-audit --strict --desc |
| 93 | +
|
| 94 | + - name: Check for leaked secrets |
| 95 | + uses: trufflesecurity/trufflehog@main |
| 96 | + with: |
| 97 | + extra_args: --only-verified --results=verified |
| 98 | + path: . |
| 99 | + |
| 100 | + license-check: |
| 101 | + name: License compliance |
| 102 | + runs-on: ubuntu-latest |
| 103 | + steps: |
| 104 | + - uses: actions/checkout@v4 |
| 105 | + |
| 106 | + - name: Set up Python |
| 107 | + uses: actions/setup-python@v5 |
| 108 | + with: |
| 109 | + python-version: "3.12" |
| 110 | + |
| 111 | + - name: Install and check licenses |
| 112 | + run: | |
| 113 | + pip install -e . |
| 114 | + pip install pip-licenses |
| 115 | + echo "=== All dependency licenses ===" |
| 116 | + pip-licenses --format=table --with-urls |
| 117 | + echo "" |
| 118 | + echo "=== Checking for copyleft ===" |
| 119 | + pip-licenses --allow-only="MIT;BSD License;BSD-2-Clause;BSD-3-Clause;Apache Software License;Apache-2.0;ISC;PSF;HPND;Python Software Foundation License;Public Domain;Mozilla Public License 2.0 (MPL 2.0)" || echo "WARNING: Found non-permissive licenses" |
0 commit comments