|
| 1 | +name: Trivy scanning |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + inputs: |
| 5 | + upload-to-github-security-tab: |
| 6 | + default: false |
| 7 | + required: false |
| 8 | + type: boolean |
| 9 | + export-csv: |
| 10 | + default: false |
| 11 | + required: false |
| 12 | + type: boolean |
| 13 | + |
| 14 | +jobs: |
| 15 | + trivy-scan-licenses: |
| 16 | + runs-on: ubuntu-22.04 |
| 17 | + steps: |
| 18 | + - name: Checkout |
| 19 | + uses: actions/checkout@v3 |
| 20 | + |
| 21 | + - name: Run Trivy in fs mode |
| 22 | + uses: aquasecurity/trivy-action@master |
| 23 | + with: |
| 24 | + scan-type: fs |
| 25 | + scan-ref: . |
| 26 | + exit-code: 1 |
| 27 | + scanners: license |
| 28 | + severity: "UNKNOWN,MEDIUM,HIGH,CRITICAL" |
| 29 | + |
| 30 | + trivy-scan-vulns: |
| 31 | + runs-on: ubuntu-22.04 |
| 32 | + steps: |
| 33 | + - name: Checkout |
| 34 | + uses: actions/checkout@v3 |
| 35 | + |
| 36 | + - name: Run Trivy in fs mode |
| 37 | + continue-on-error: true |
| 38 | + uses: aquasecurity/trivy-action@master |
| 39 | + with: |
| 40 | + scan-type: fs |
| 41 | + scan-ref: . |
| 42 | + exit-code: 1 |
| 43 | + list-all-pkgs: true |
| 44 | + format: json |
| 45 | + output: trivy-report.json |
| 46 | + |
| 47 | + - name: Show report in human-readable format |
| 48 | + uses: aquasecurity/trivy-action@master |
| 49 | + with: |
| 50 | + scan-type: convert |
| 51 | + vuln-type: '' |
| 52 | + severity: '' |
| 53 | + image-ref: trivy-report.json |
| 54 | + format: table |
| 55 | + |
| 56 | + - name: Convert report to sarif |
| 57 | + if: ${{ inputs.upload-to-github-security-tab }} |
| 58 | + uses: aquasecurity/trivy-action@master |
| 59 | + with: |
| 60 | + scan-type: convert |
| 61 | + vuln-type: '' |
| 62 | + severity: '' |
| 63 | + image-ref: trivy-report.json |
| 64 | + format: sarif |
| 65 | + output: trivy-report.sarif |
| 66 | + |
| 67 | + - name: Upload sarif report to GitHub Security tab |
| 68 | + if: ${{ inputs.upload-to-github-security-tab }} |
| 69 | + uses: github/codeql-action/upload-sarif@v2 |
| 70 | + with: |
| 71 | + sarif_file: trivy-report.sarif |
| 72 | + |
| 73 | + - name: Convert report to csv |
| 74 | + if: ${{ inputs.export-csv }} |
| 75 | + uses: aquasecurity/trivy-action@master |
| 76 | + with: |
| 77 | + scan-type: convert |
| 78 | + vuln-type: '' |
| 79 | + severity: '' |
| 80 | + image-ref: trivy-report.json |
| 81 | + format: template |
| 82 | + template: "@.github/workflows/trivy-csv.tpl" |
| 83 | + output: trivy-report.csv |
| 84 | + |
| 85 | + - name: Upload CSV report as an artifact |
| 86 | + if: ${{ inputs.export-csv }} |
| 87 | + uses: actions/upload-artifact@v3 |
| 88 | + with: |
| 89 | + name: trivy-report |
| 90 | + path: trivy-report.csv |
0 commit comments