Skip to content

Security

Security #5

Workflow file for this run

name: Security
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: "0 0 * * 0" # Run weekly
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
security-events: write
pull-requests: read
jobs:
security-scan:
name: Security Scan
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
cache: "pip"
- name: Cache Poetry virtualenv
uses: actions/cache@v3
with:
path: ~/.cache/pypoetry
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry config virtualenvs.create true
poetry install --no-interaction
- name: Install security tools
run: |
poetry run pip install bandit safety
- name: Run Bandit
id: bandit
run: poetry run bandit -r . -c pyproject.toml -f json -o bandit-results.json
continue-on-error: true
- name: Upload Bandit results
if: always() && steps.bandit.outcome == 'failure'
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: bandit-results.json
- name: Run Safety Check
id: safety
run: poetry run safety check --json > safety-results.json
continue-on-error: true
- name: Process Safety results
if: always() && steps.safety.outcome == 'failure'
run: |
echo "Safety check found vulnerabilities. Check safety-results.json for details."
cat safety-results.json
codeql:
name: CodeQL Analysis
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
security-events: write
actions: read
contents: read
steps:
- uses: actions/checkout@v3
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: python
queries: security-and-quality
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:python"
dependency-review:
name: Dependency Review
runs-on: ubuntu-latest
timeout-minutes: 15
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v3
- name: Dependency Review
uses: actions/dependency-review-action@v3
with:
fail-on-severity: high
deny-licenses: LGPL-2.0, AGPL-3.0
secret-scan:
name: Secret Scanner
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: TruffleHog OSS
uses: trufflesecurity/trufflehog@main
with:
path: ./
base: ${{ github.event.repository.default_branch }}
head: HEAD
extra_args: --debug --only-verified