Files
semantica/.github/workflows/security.yml
T

107 lines
2.7 KiB
YAML

name: Security Scan
# Scans code and dependencies for security vulnerabilities
# Runs on: push, pull requests, or manual trigger
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
schedule:
- cron: '0 0 * * 1' # Weekly on Monday
workflow_dispatch:
permissions:
contents: read
security-events: write
jobs:
dependency-scan:
name: Dependency Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install security tools
run: |
python -m pip install --upgrade pip
pip install safety pip-audit
- name: Install project dependencies
run: |
pip install -e ".[dev]"
- name: Run pip-audit
run: |
set +e
pip-audit --format json --output pip-audit-report.json 2>&1 || echo "pip-audit scan completed"
pip-audit 2>&1 || echo "pip-audit completed with findings"
exit 0
continue-on-error: true
- name: Run safety check
run: |
set +e
safety check --json --output safety-report.json 2>&1 || echo "Safety check completed"
safety check 2>&1 || echo "Safety check completed with findings"
exit 0
continue-on-error: true
- name: Upload security reports
if: always()
uses: actions/upload-artifact@v3
with:
name: security-reports
path: |
pip-audit-report.json
safety-report.json
retention-days: 30
if-no-files-found: ignore
code-scan:
name: Code Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
continue-on-error: true
- name: Upload Trivy results to GitHub Security
if: always() && hashFiles('trivy-results.sarif') != ''
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'trivy-results.sarif'
continue-on-error: true
secret-scan:
name: Secret Scanning
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run Gitleaks
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true