diff --git a/.github/workflows/trivy.yaml b/.github/workflows/trivy.yaml new file mode 100644 index 00000000..28cf3a9a --- /dev/null +++ b/.github/workflows/trivy.yaml @@ -0,0 +1,97 @@ +name: Trivy Security Scan +on: + pull_request: + paths: + - 'terraform/**' + - '.github/workflows/trivy.yaml' + push: + branches: + - main + paths: + - 'terraform/**' + - '.github/workflows/trivy.yaml' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + trivy-aws: + name: Trivy IaC Scan (AWS) + runs-on: ubuntu-latest + permissions: + contents: read + security-events: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run Trivy scanner (table output) + uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0 + with: + scan-type: 'fs' + scan-ref: 'terraform/aws/modules/' + scanners: 'vuln,secret,misconfig' + ignore-unfixed: false + exit-code: '0' + format: 'table' + severity: 'CRITICAL,HIGH' + + - name: Run Trivy scanner (SARIF output) + uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0 + with: + scan-type: 'fs' + scan-ref: 'terraform/aws/modules/' + scanners: 'vuln,secret,misconfig' + ignore-unfixed: false + exit-code: '0' + format: 'sarif' + output: 'trivy-aws-results.sarif' + severity: 'CRITICAL,HIGH' + + - name: Upload AWS scan results to GitHub Security tab + uses: github/codeql-action/upload-sarif@v3 + if: always() + with: + sarif_file: 'trivy-aws-results.sarif' + category: 'trivy-iac-aws' + + trivy-azure: + name: Trivy IaC Scan (Azure) + runs-on: ubuntu-latest + permissions: + contents: read + security-events: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run Trivy scanner (table output) + uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0 + with: + scan-type: 'fs' + scan-ref: 'terraform/azure/modules/' + scanners: 'vuln,secret,misconfig' + ignore-unfixed: false + exit-code: '0' + format: 'table' + severity: 'CRITICAL,HIGH' + + - name: Run Trivy scanner (SARIF output) + uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0 + with: + scan-type: 'fs' + scan-ref: 'terraform/azure/modules/' + scanners: 'vuln,secret,misconfig' + ignore-unfixed: false + exit-code: '0' + format: 'sarif' + output: 'trivy-azure-results.sarif' + severity: 'CRITICAL,HIGH' + + - name: Upload Azure scan results to GitHub Security tab + uses: github/codeql-action/upload-sarif@v3 + if: always() + with: + sarif_file: 'trivy-azure-results.sarif' + category: 'trivy-iac-azure' \ No newline at end of file