Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions .github/workflows/security-scan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Security Scan

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

jobs:
trivy-scan:
name: Trivy
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
actions: read

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: "pip"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f pyproject.toml ]; then
pip install -e ".[dev]"
fi

- name: Run Trivy vulnerability scan
uses: aquasecurity/trivy-action@77137e9dc3ab1b329b7c8a38c2eb7475850a14e8
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH,MEDIUM,LOW'
exit-code: '0'

- name: Check for critical and high vulnerabilities
uses: aquasecurity/trivy-action@77137e9dc3ab1b329b7c8a38c2eb7475850a14e8
with:
scan-type: 'fs'
scan-ref: '.'
format: 'table'
severity: 'CRITICAL,HIGH'
exit-code: '1'

- name: Upload Trivy scan results to Security tab
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'trivy-results.sarif'
category: 'trivy-security-scan'

bandit-scan:
name: Bandit
runs-on: ubuntu-latest
permissions:
security-events: write
actions: read
contents: read
checks: write

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"

- name: Create virtual environment
run: |
python -m pip install --upgrade pip
python -m venv .venv

- name: Install dependencies
run: |
source .venv/bin/activate
pip install -e ".[dev]"

- name: Install Bandit
run: |
source .venv/bin/activate
pip install bandit[sarif]

- name: Run Bandit Security Scan
uses: PyCQA/bandit-action@67a458d90fa11fb1463e91e7f4c8f068b5863c7f
with:
targets: "."
exclude: "tests"

- name: Upload SARIF results to GitHub Security tab
if: github.ref == 'refs/heads/main'
uses: github/codeql-action/upload-sarif@86b04fb0e47484f7282357688f21d5d0e32175fe
with:
sarif_file: results.sarif
category: bandit-security-scan
continue-on-error: true

- name: Upload SARIF as artifact
uses: actions/upload-artifact@v4
with:
name: bandit-sarif-results
path: results.sarif
retention-days: 30
continue-on-error: true