|
| 1 | +name: Trivy scan image for vulnerabilities |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - ci/nightly-builds |
| 10 | + |
| 11 | +jobs: |
| 12 | + scan: |
| 13 | + concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os_version }}-${{ matrix.build }} # to branch/PR + OS + build |
| 15 | + cancel-in-progress: true |
| 16 | + runs-on: ubuntu-latest |
| 17 | + strategy: |
| 18 | + fail-fast: false |
| 19 | + matrix: |
| 20 | + os_version: |
| 21 | + - RL8 |
| 22 | + - RL9 |
| 23 | + build: |
| 24 | + - openstack.openhpc |
| 25 | + - openstack.openhpc-cuda |
| 26 | + exclude: |
| 27 | + - os_version: RL8 |
| 28 | + build: openstack.openhpc-cuda |
| 29 | + env: |
| 30 | + BUILD: ${{ matrix.build }}-${{ matrix.os_version }} |
| 31 | + |
| 32 | + steps: |
| 33 | + - name: Download image details artifact |
| 34 | + uses: actions/download-artifact@v4 |
| 35 | + with: |
| 36 | + name: image-details |
| 37 | + path: ./ |
| 38 | + |
| 39 | + - name: Use the downloaded artifact |
| 40 | + id: manifest |
| 41 | + run: | |
| 42 | + IMAGE_ID=$(cat image-id-${{ env.BUILD }}.txt) |
| 43 | + IMAGE_NAME=$(cat image-name-${{ env.BUILD }}.txt) |
| 44 | + echo "image-name=${IMAGE_NAME}" >> "$GITHUB_OUTPUT" |
| 45 | + echo "image-id=${IMAGE_ID}" >> "$GITHUB_OUTPUT" |
| 46 | +
|
| 47 | + - name: Download image |
| 48 | + run: | |
| 49 | + . venv/bin/activate |
| 50 | + sudo mkdir /mnt/images |
| 51 | + sudo chmod 777 /mnt/images |
| 52 | + openstack image save --file /mnt/images/${{ steps.manifest.outputs.image-name }}.qcow2 ${{ steps.manifest.outputs.image-name }} |
| 53 | +
|
| 54 | + - name: Set up QEMU |
| 55 | + uses: docker/setup-qemu-action@v3 |
| 56 | + |
| 57 | + - name: install libguestfs |
| 58 | + run: | |
| 59 | + sudo apt -y update |
| 60 | + sudo apt -y install libguestfs-tools |
| 61 | +
|
| 62 | + - name: mkdir for mount |
| 63 | + run: sudo mkdir -p './${{ steps.manifest.outputs.image-name }}' |
| 64 | + |
| 65 | + - name: mount qcow2 file |
| 66 | + run: sudo guestmount -a /mnt/images/${{ steps.manifest.outputs.image-name }}.qcow2 -i --ro -o allow_other './${{ steps.manifest.outputs.image-name }}' |
| 67 | + |
| 68 | + - name: Run Trivy vulnerability scanner |
| 69 | + uses: aquasecurity/[email protected] |
| 70 | + with: |
| 71 | + scan-type: fs |
| 72 | + scan-ref: "${{ steps.manifest.outputs.image-name }}" |
| 73 | + scanners: "vuln" |
| 74 | + format: sarif |
| 75 | + output: "${{ steps.manifest.outputs.image-name }}.sarif" |
| 76 | + # turn off secret scanning to speed things up |
| 77 | + |
| 78 | + - name: Upload Trivy scan results to GitHub Security tab |
| 79 | + uses: github/codeql-action/upload-sarif@v3 |
| 80 | + with: |
| 81 | + sarif_file: "${{ steps.manifest.outputs.image-name }}.sarif" |
| 82 | + category: "${{ matrix.os_version }}-${{ matrix.build }}" |
| 83 | + |
| 84 | + - name: Fail if scan has CRITICAL vulnerabilities |
| 85 | + uses: aquasecurity/[email protected] |
| 86 | + with: |
| 87 | + scan-type: fs |
| 88 | + scan-ref: "${{ steps.manifest.outputs.image-name }}" |
| 89 | + scanners: "vuln" |
| 90 | + format: table |
| 91 | + exit-code: '1' |
| 92 | + severity: 'CRITICAL' |
| 93 | + ignore-unfixed: true |
0 commit comments