|
| 1 | +name: trivy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["main"] |
| 6 | + paths: |
| 7 | + - "**/*.go" |
| 8 | + - go.mod |
| 9 | + - go.sum |
| 10 | + - cmd/upcloud-csi-plugin/Containerfile |
| 11 | + - '.github/workflows/trivy-scan.yaml' |
| 12 | + pull_request: |
| 13 | + schedule: |
| 14 | + - cron: '5 5 * * 2' |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + |
| 19 | +jobs: |
| 20 | + analyze: |
| 21 | + permissions: |
| 22 | + contents: read |
| 23 | + security-events: write |
| 24 | + actions: read |
| 25 | + name: Trivy scan |
| 26 | + runs-on: ubuntu-24.04 |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 29 | + with: |
| 30 | + fetch-depth: 0 |
| 31 | + |
| 32 | + - uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1 |
| 33 | + id: filter |
| 34 | + with: |
| 35 | + filters: | |
| 36 | + source: |
| 37 | + - '**/*.go' |
| 38 | + - go.mod |
| 39 | + - go.sum |
| 40 | + - 'cmd/upcloud-csi-plugin/Containerfile' |
| 41 | + - '.github/workflows/trivy-scan.yaml' |
| 42 | +
|
| 43 | + - if: steps.filter.outputs.source == 'true' || github.event_name != 'pull_request' |
| 44 | + name: Log in to GHCR |
| 45 | + uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0 |
| 46 | + with: |
| 47 | + registry: ghcr.io |
| 48 | + username: ${{ github.actor }} |
| 49 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 50 | + |
| 51 | + - if: steps.filter.outputs.source == 'true' || github.event_name != 'pull_request' |
| 52 | + name: Run Trivy vulnerability scanner (filesystem) |
| 53 | + uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 |
| 54 | + with: |
| 55 | + scan-type: 'fs' |
| 56 | + scan-ref: . |
| 57 | + format: 'sarif' |
| 58 | + output: 'trivy-fs-results.sarif' |
| 59 | + severity: 'CRITICAL,HIGH' |
| 60 | + ignore-unfixed: true |
| 61 | + |
| 62 | + - if: steps.filter.outputs.source == 'true' || github.event_name != 'pull_request' |
| 63 | + name: Upload filesystem scan results to GitHub Security tab |
| 64 | + uses: github/codeql-action/upload-sarif@dd903d2e4f5405488e5ef1422510ee31c8b32357 # v3.36.2 |
| 65 | + with: |
| 66 | + sarif_file: 'trivy-fs-results.sarif' |
| 67 | + |
| 68 | + - if: github.event_name == 'schedule' |
| 69 | + name: Run Trivy vulnerability scanner (image) |
| 70 | + uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 |
| 71 | + with: |
| 72 | + image-ref: 'ghcr.io/${{ github.repository }}:main' |
| 73 | + format: 'sarif' |
| 74 | + output: 'trivy-image-results.sarif' |
| 75 | + severity: 'CRITICAL,HIGH' |
| 76 | + ignore-unfixed: true |
| 77 | + |
| 78 | + - if: github.event_name == 'schedule' |
| 79 | + name: Upload image scan results to GitHub Security tab |
| 80 | + uses: github/codeql-action/upload-sarif@dd903d2e4f5405488e5ef1422510ee31c8b32357 # v3.36.2 |
| 81 | + with: |
| 82 | + sarif_file: 'trivy-image-results.sarif' |
0 commit comments