|
| 1 | +name: "Vulnerability Scan on Docker Image" |
| 2 | +description: "This uses Trivy to run a security scan on a docker image" |
| 3 | + |
| 4 | +inputs: |
| 5 | + image-ref: |
| 6 | + description: Image reference |
| 7 | + required: true |
| 8 | + latest: |
| 9 | + description: Skip calling the setup-trivy action to install trivy |
| 10 | + default: "false" |
| 11 | + |
| 12 | +runs: |
| 13 | + using: composite |
| 14 | + steps: |
| 15 | + - name: Run Trivy vulnerability scanner |
| 16 | + uses: aquasecurity/trivy-action@0.28.0 |
| 17 | + env: |
| 18 | + TRIVY_DISABLE_VEX_NOTICE: true |
| 19 | + with: |
| 20 | + image-ref: ${{ inputs.image-ref }} |
| 21 | + format: 'table' # Output format (table, json, template, sarif, cyclonedx, spdx, spdx-json, github, cosign-vuln) |
| 22 | + exit-code: '0' # Exit code for runner when a vulnerability is found. Non-0 exit will fail the job |
| 23 | + ignore-unfixed: true # Ignore unpatched/unfixed vulnerabilities |
| 24 | + vuln-type: 'os,library' |
| 25 | + severity: 'CRITICAL,HIGH,MEDIUM' # UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL |
| 26 | + cache: 'true' # By default, cache is only accessed within the current branch. |
| 27 | + output: trivy-report.txt |
| 28 | + |
| 29 | + - name: Publish Trivy Output to Summary |
| 30 | + id: trivy-summary |
| 31 | + shell: bash |
| 32 | + run: | |
| 33 | + if [[ -s trivy-report.txt ]]; then |
| 34 | + { |
| 35 | + echo "### Security Output" |
| 36 | + echo "<details><summary>Click to expand</summary>" |
| 37 | + echo "" |
| 38 | + echo '```' |
| 39 | + cat trivy-report.txt |
| 40 | + echo '```' |
| 41 | + echo "</details>" |
| 42 | + } >> $GITHUB_STEP_SUMMARY |
| 43 | + fi |
| 44 | +
|
| 45 | + - name: Comment on PR |
| 46 | + if: github.event_name == 'pull_request' |
| 47 | + uses: actions/github-script@v7 |
| 48 | + with: |
| 49 | + script: | |
| 50 | + const fs = require('fs') |
| 51 | + const path = 'trivy-report.txt' |
| 52 | + const issueComment = (content) => { |
| 53 | + github.rest.issues.createComment({ |
| 54 | + issue_number: context.issue.number, |
| 55 | + owner: context.repo.owner, |
| 56 | + repo: context.repo.repo, |
| 57 | + body: '```'+content+'```' |
| 58 | + }) |
| 59 | + } |
| 60 | +
|
| 61 | + try { |
| 62 | + const content = fs.readFileSync(path, 'utf8') |
| 63 | + issueComment(content); |
| 64 | + } catch (error) { |
| 65 | + issueComment(error) |
| 66 | + } |
0 commit comments