diff --git a/.github/workflows/security.yaml b/.github/workflows/security.yaml new file mode 100644 index 0000000..b441b12 --- /dev/null +++ b/.github/workflows/security.yaml @@ -0,0 +1,124 @@ +name: Security Scan + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +permissions: + contents: read + security-events: write + +jobs: + + security: + runs-on: ubuntu-latest + + steps: + + ######################################## + # Checkout + ######################################## + + - name: Checkout repository + uses: actions/checkout@v4 + + ######################################## + # Python setup + ######################################## + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install Python security tools + run: | + pip install bandit pip-audit safety + + ######################################## + # Python code scan + ######################################## + + - name: Bandit scan + run: | + bandit -c .github/security/bandit.yml -r . -f json -o bandit-report.json + + ######################################## + # Python dependency scan + ######################################## + + - name: pip-audit dependencies + run: | + pip-audit -r requirements.txt -f json -o pip-audit-report.json || true + + ######################################## + # Node setup + ######################################## + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: "20" + + - name: Install JS dependencies + run: | + if [ -f package.json ]; then + npm install + fi + + ######################################## + # NPM vulnerability scan + ######################################## + + - name: NPM audit + run: | + if [ -f package.json ]; then + npm audit --audit-level=high + fi + + ######################################## + # ESLint security scan + ######################################## + + - name: ESLint security + run: | + if [ -f package.json ]; then + npm install eslint eslint-plugin-security + npx eslint . -c .github/security/eslint-security.json || true + fi + + ######################################## + # Secrets scanning + ######################################## + + - name: Gitleaks scan + uses: gitleaks/gitleaks-action@v2 + + ######################################## + # Trivy vulnerability scan + ######################################## + + - name: Trivy filesystem scan + uses: aquasecurity/trivy-action@0.20.0 + with: + scan-type: fs + scan-ref: . + config: .github/security/trivy.yaml + + ######################################## + # Upload reports + ######################################## + + - name: Upload Bandit report + uses: actions/upload-artifact@v4 + with: + name: bandit-report + path: bandit-report.json + + - name: Upload pip-audit report + uses: actions/upload-artifact@v4 + with: + name: pip-audit-report + path: pip-audit-report.json