Security Scanning #201
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 Scanning | |
on: | |
schedule: | |
# Run security scans daily at 2 AM UTC | |
- cron: '0 2 * * *' | |
pull_request: | |
branches: [ main, develop ] | |
push: | |
branches: [ main ] | |
jobs: | |
# ============================================================================= | |
# DEPENDENCY SCAN | |
# ============================================================================= | |
dependency-scan: | |
name: Dependency 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: Scan dependencies | |
run: | | |
pip install safety | |
safety check --file requirements.txt || echo "Vulnerabilities found - review required" | |
# ============================================================================= | |
# CODE SECURITY SCAN | |
# ============================================================================= | |
code-security: | |
name: Code Security | |
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: Run security analysis | |
run: | | |
pip install bandit | |
bandit -r src/ || echo "Security issues found - review required" | |
# ============================================================================= | |
# SECRETS SCAN | |
# ============================================================================= | |
secrets-scan: | |
name: Secrets Scan | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
# Fetch more history for proper commit comparison | |
fetch-depth: 0 | |
- name: Determine scan range | |
id: scan-range | |
run: | | |
if [ "${{ github.event_name }}" = "push" ]; then | |
# For push events, scan from the previous commit to current commit | |
if [ "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]; then | |
echo "base=${{ github.event.before }}" >> $GITHUB_OUTPUT | |
echo "head=${{ github.sha }}" >> $GITHUB_OUTPUT | |
else | |
# New branch or initial commit - scan just the current commit | |
echo "base=HEAD~1" >> $GITHUB_OUTPUT | |
echo "head=HEAD" >> $GITHUB_OUTPUT | |
fi | |
elif [ "${{ github.event_name }}" = "pull_request" ]; then | |
# For PRs, scan from base branch to PR head | |
echo "base=${{ github.event.pull_request.base.sha }}" >> $GITHUB_OUTPUT | |
echo "head=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT | |
else | |
# For scheduled runs, scan the last commit only | |
echo "base=HEAD~1" >> $GITHUB_OUTPUT | |
echo "head=HEAD" >> $GITHUB_OUTPUT | |
fi | |
- name: Scan for secrets | |
uses: trufflesecurity/trufflehog@main | |
with: | |
path: ./ | |
base: ${{ steps.scan-range.outputs.base }} | |
head: ${{ steps.scan-range.outputs.head }} | |
extra_args: --only-verified | |
# ============================================================================= | |
# DOCKER SECURITY | |
# ============================================================================= | |
docker-security: | |
name: Docker Security | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Build and scan image | |
run: docker build -t service-quality-oracle:security-scan . | |
- name: Run vulnerability scan | |
uses: aquasecurity/trivy-action@master | |
with: | |
image-ref: 'service-quality-oracle:security-scan' | |
format: 'table' |