name: devsecops on: push: branches: - main pull_request: schedule: - cron: "0 6 * * 1" workflow_dispatch: concurrency: group: devsecops-${{ github.ref }} cancel-in-progress: false permissions: contents: read security-events: write actions: write pull-requests: write jobs: sast-gosec: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Go uses: actions/setup-go@v5 with: go-version: "1.22" - name: Run gosec continue-on-error: true uses: securego/gosec@1d909e2687abe43eaa81af88d6efde3d20c8d481 with: args: "-no-fail -fmt sarif -out gosec.sarif ./..." - name: Upload SARIF to Security if: always() uses: github/codeql-action/upload-sarif@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 with: sarif_file: gosec.sarif - name: Upload SARIF artifact if: always() uses: actions/upload-artifact@v4 with: name: sarif-gosec path: gosec.sarif sast-govulncheck: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Go uses: actions/setup-go@v5 with: go-version: "1.22" - name: Install govulncheck run: go install golang.org/x/vuln/cmd/govulncheck@latest - name: Run govulncheck continue-on-error: true run: | "$(go env GOPATH)/bin/govulncheck" -json ./... > govulncheck.json - name: Convert govulncheck to SARIF if: always() run: python scripts/govulncheck_to_sarif.py --input govulncheck.json --output govulncheck.sarif - name: Upload SARIF to Security if: always() uses: github/codeql-action/upload-sarif@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 with: sarif_file: govulncheck.sarif - name: Upload SARIF artifact if: always() uses: actions/upload-artifact@v4 with: name: sarif-govulncheck path: govulncheck.sarif secrets-gitleaks: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - name: Run gitleaks id: gitleaks continue-on-error: true uses: gitleaks/gitleaks-action@ff98106e4c7b2bc287b24eaf42907196329070c7 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITLEAKS_ENABLE_COMMENTS: "false" GITLEAKS_ENABLE_SUMMARY: "false" GITLEAKS_ENABLE_UPLOAD_ARTIFACT: "false" - name: Prepare SARIF if: always() env: GITLEAKS_SARIF: ${{ steps.gitleaks.outputs.sarif }} run: | if [ -n "$GITLEAKS_SARIF" ] && [ -f "$GITLEAKS_SARIF" ]; then cp "$GITLEAKS_SARIF" gitleaks.sarif elif [ -f /tmp/gitleaks.sarif ]; then cp /tmp/gitleaks.sarif gitleaks.sarif else cat > gitleaks.sarif <<'JSON' { "version": "2.1.0", "$schema": "https://json.schemastore.org/sarif-2.1.0.json", "runs": [ { "tool": { "driver": { "name": "gitleaks", "rules": [] } }, "results": [] } ] } JSON fi - name: Upload SARIF to Security if: always() uses: github/codeql-action/upload-sarif@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 with: sarif_file: gitleaks.sarif - name: Upload SARIF artifact if: always() uses: actions/upload-artifact@v4 with: name: sarif-gitleaks path: gitleaks.sarif sca-trivy-fs: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Run Trivy filesystem scan uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 with: scan-type: fs format: sarif output: trivy-fs.sarif severity: HIGH,CRITICAL exit-code: "0" limit-severities-for-sarif: true - name: Upload SARIF to Security if: always() uses: github/codeql-action/upload-sarif@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 with: sarif_file: trivy-fs.sarif - name: Upload SARIF artifact if: always() uses: actions/upload-artifact@v4 with: name: sarif-trivy-fs path: trivy-fs.sarif sca-trivy-image: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Build image run: docker build -t pipe2025:${{ github.sha }} . - name: Run Trivy image scan uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 with: scan-type: image image-ref: pipe2025:${{ github.sha }} format: sarif output: trivy-image.sarif severity: HIGH,CRITICAL exit-code: "0" limit-severities-for-sarif: true - name: Upload SARIF to Security if: always() uses: github/codeql-action/upload-sarif@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 with: sarif_file: trivy-image.sarif - name: Upload SARIF artifact if: always() uses: actions/upload-artifact@v4 with: name: sarif-trivy-image path: trivy-image.sarif dast-zap-baseline: runs-on: ubuntu-latest needs: sca-trivy-image steps: - name: Checkout uses: actions/checkout@v4 - name: Start app run: | docker compose up -d for _ in $(seq 1 60); do code="$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8080/ || true)" if [ "$code" != "000" ]; then exit 0 fi sleep 1 done echo "App did not become reachable within 60 seconds." >&2 exit 1 - name: Run ZAP baseline continue-on-error: true uses: zaproxy/action-baseline@de8ad967d3548d44ef623df22cf95c3b0baf8b25 with: target: http://127.0.0.1:8080 cmd_options: "-T 3 -J report.json -w report.md -r report.html" - name: Convert ZAP JSON to SARIF if: always() run: python scripts/zap_to_sarif.py --input report.json --output zap.sarif - name: Upload SARIF to Security if: always() uses: github/codeql-action/upload-sarif@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 with: sarif_file: zap.sarif - name: Upload SARIF artifact if: always() uses: actions/upload-artifact@v4 with: name: sarif-zap path: zap.sarif - name: Stop app if: always() run: docker compose down -v ai-triage: runs-on: ubuntu-latest needs: - sast-gosec - sast-govulncheck - secrets-gitleaks - sca-trivy-fs - sca-trivy-image - dast-zap-baseline if: always() outputs: aiheal_eligible: ${{ steps.triage.outputs.aiheal_eligible }} gate: ${{ steps.triage.outputs.gate }} steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Python uses: actions/setup-python@v5 with: python-version: "3.11" - name: Install dependencies run: pip install -r scripts/requirements.txt - name: Download SARIF artifacts uses: actions/download-artifact@v4 with: pattern: sarif-* path: artifacts/sarif merge-multiple: true - name: Aggregate SARIF findings run: python scripts/sarif_aggregate.py --input-dir artifacts/sarif --output artifacts/security_findings.json - name: Run AI security triage id: triage env: AI_API_KEY: ${{ secrets.AI_API_KEY }} AI_BASE_URL: ${{ secrets.AI_BASE_URL }} AI_MODEL: ${{ secrets.AI_MODEL }} AI_PROVIDER: ${{ secrets.AI_PROVIDER }} run: | python scripts/ai_security_triage.py \ --findings artifacts/security_findings.json \ --report artifacts/security_report.md \ --handoff artifacts/security_handoff.json - name: Publish triage summary if: always() run: cat artifacts/security_report.md >> "$GITHUB_STEP_SUMMARY" - name: Upload security handoff artifact if: ${{ always() && hashFiles('artifacts/security_handoff.json') != '' }} uses: actions/upload-artifact@v4 with: name: security-handoff path: artifacts/security_handoff.json trigger-aiheal: runs-on: ubuntu-latest needs: ai-triage if: needs.ai-triage.outputs.aiheal_eligible == 'true' && needs.ai-triage.result == 'success' environment: ${{ needs.ai-triage.outputs.gate == 'block' && 'aiheal-human' || 'aiheal-auto' }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - name: Announce gate run: | echo "AI gate: ${{ needs.ai-triage.outputs.gate }}" >> "$GITHUB_STEP_SUMMARY" echo "Environment: ${{ needs.ai-triage.outputs.gate == 'block' && 'aiheal-human (human approval)' || 'aiheal-auto (auto-proceed)' }}" >> "$GITHUB_STEP_SUMMARY" - name: Trigger aiheal showcase run: gh workflow run aiheal-showcase.yml --repo ${{ github.repository }} --ref ${{ github.ref }} -f security_source_run_id=${{ github.run_id }}