name: Security Checks
on:
push:
branches: [main, production]
pull_request:
branches: [main, production]
schedule:
- cron: '0 9 * * 1'
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
jobs:
secret-scan:
name: Secret Scanning
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: TruffleHog Secret Scan
uses: trufflesecurity/trufflehog@main
with:
path: ./
base: ${{ github.event.repository.default_branch }}
head: HEAD
extra_args: --debug --only-verified
- name: Gitleaks Secret Scan
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
cargo-audit:
name: Cargo Audit
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-audit
run: cargo install cargo-audit
- name: Run cargo audit
run: cargo audit --deny warnings
- name: Run cargo audit (json output)
run: cargo audit --json > audit-report.json
continue-on-error: true
- name: Upload audit report
uses: actions/upload-artifact@v4
if: always()
with:
name: cargo-audit-report
path: audit-report.json
license-check:
name: License Check
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-license
run: cargo install cargo-license
- name: Check licenses
run: |
cargo license --json > licenses.json
echo "## Dependency Licenses" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
cargo license >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
- name: Upload license report
uses: actions/upload-artifact@v4
with:
name: license-report
path: licenses.json
security-policy:
name: Security Policy Check
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check for security policy
run: |
if [ ! -f "SECURITY.md" ]; then
echo "::error::SECURITY.md file is missing"
exit 1
fi
echo "✅ SECURITY.md exists" >> $GITHUB_STEP_SUMMARY
- name: Validate security policy
run: |
# Check that SECURITY.md contains required sections
required_sections=("Supported Versions" "Reporting a Vulnerability" "Security Update Process")
for section in "${required_sections[@]}"; do
if ! grep -q "$section" SECURITY.md; then
echo "::warning::SECURITY.md is missing section: $section"
else
echo "✅ Found section: $section" >> $GITHUB_STEP_SUMMARY
fi
done
supply-chain:
name: Supply Chain Security
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Generate SBOM (Software Bill of Materials)
run: |
cargo install cargo-sbom
cargo sbom > sbom.spdx
- name: Upload SBOM
uses: actions/upload-artifact@v4
with:
name: sbom
path: sbom.spdx
- name: Check for outdated dependencies
run: |
cargo install cargo-outdated
echo "## Outdated Dependencies" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
cargo outdated >> $GITHUB_STEP_SUMMARY || true
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
security-tests:
name: Security Tests
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Run security-focused tests
run: |
# Run tests with security prefix
cargo test --lib security
cargo test --lib ssrf
cargo test --lib injection
cargo test --lib auth
cargo test --lib policy
- name: Check for hardcoded secrets in tests
run: |
# Simple check for common patterns
if grep -r "api[_-]key.*=.*['\"].*['\"]" --include="*.rs" .; then
echo "::warning::Potential hardcoded API key found"
fi
if grep -r "password.*=.*['\"].*['\"]" --include="*.rs" .; then
echo "::warning::Potential hardcoded password found"
fi
security-report:
name: Security Report
needs: [secret-scan, cargo-audit, license-check, security-policy, supply-chain, security-tests]
runs-on: self-hosted
if: always()
steps:
- name: Create summary
run: |
echo "# Security Check Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Secret Scanning | ${{ needs.secret-scan.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Cargo Audit | ${{ needs.cargo-audit.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| License Check | ${{ needs.license-check.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Security Policy | ${{ needs.security-policy.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Supply Chain | ${{ needs.supply-chain.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Security Tests | ${{ needs.security-tests.result }} |" >> $GITHUB_STEP_SUMMARY