Trivy Scan #83
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This workflow uses actions that are not certified by GitHub. | |
| # They are provided by a third-party and are governed by | |
| # separate terms of service, privacy policy, and support | |
| # documentation. | |
| name: Trivy Scan | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '36 18 * * *' | |
| env: | |
| # Use docker.io for Docker Hub if empty | |
| REGISTRY: ghcr.io | |
| permissions: | |
| contents: read | |
| packages: read | |
| jobs: | |
| preparation: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| folders: ${{ steps.devcontainer-folders.outputs.folders }} | |
| repo: ${{ steps.lowercase-repo.outputs.repo }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Get devcontainer folders | |
| id: devcontainer-folders | |
| run: echo "folders=$(ls src | jq -R -s -c 'split("\n")[:-1]')" | tee $GITHUB_OUTPUT | |
| - name: Get lowercase repo name | |
| id: lowercase-repo | |
| run: echo "repo=${GITHUB_REPOSITORY@L}" | tee $GITHUB_OUTPUT | |
| runtime-versions: | |
| name: Get runtime versions | |
| runs-on: ubuntu-latest | |
| needs: preparation | |
| strategy: | |
| matrix: | |
| folder: ${{ fromJson(needs.preparation.outputs.folders) }} | |
| outputs: | |
| runtime_versions: ${{ steps.runtime-versions.outputs.runtime_versions }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Read runtime name from config.json | |
| id: runtime-name | |
| run: | | |
| runtime_name=$(jq -r '.ci.runtime_name' src/${{ matrix.folder }}/config.json) | |
| echo "RUNTIME_NAME=${runtime_name}" | tee $GITHUB_ENV | |
| - name: Load ${{ env.RUNTIME_NAME }} runtime versions to process from config.json | |
| id: runtime-versions | |
| run: | | |
| runtime_versions=$(jq -c --arg runtime_name "${RUNTIME_NAME}_versions" '.ci.[$runtime_name]' src/${{ matrix.folder }}/config.json) | |
| echo "runtime_versions=$runtime_versions" | tee $GITHUB_OUTPUT | |
| env: | |
| RUNTIME_NAME: ${{ env.RUNTIME_NAME }} | |
| scan: | |
| permissions: | |
| #contents: read # for actions/checkout to fetch code | |
| security-events: write # for github/codeql-action/upload-sarif to upload SARIF results | |
| actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status | |
| name: Scan images | |
| runs-on: ubuntu-latest | |
| needs: [preparation, runtime-versions] | |
| strategy: | |
| matrix: | |
| folder: ${{ fromJson(needs.preparation.outputs.folders) }} | |
| runtime_version: ${{ fromJson(needs.runtime-versions.outputs.runtime_versions) }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - uses: xom9ikk/dotenv@v2.4.0 | |
| with: | |
| path: "src/${{ matrix.folder }}" | |
| mode: '' | |
| load-mode: 'skip' | |
| env: | |
| RUNTIME_VERSION: ${{ matrix.runtime_version }} | |
| - name: Run Trivy vulnerability scanner | |
| uses: aquasecurity/trivy-action@v0.36.0 | |
| with: | |
| image-ref: '${{ env.REGISTRY }}/${{ needs.preparation.outputs.repo }}/${{ matrix.folder }}:${{ env.TARGET_IMAGE_BASETAG }}' | |
| #format: 'sarif' | |
| #output: 'trivy-results.sarif' | |
| format: 'template' | |
| output: 'trivy-results.md' | |
| template: "@.github/trivy-markdown.tpl" | |
| severity: 'CRITICAL,HIGH' | |
| ignore-unfixed: true | |
| env: | |
| TRIVY_USERNAME: ${{ github.actor }} | |
| TRIVY_PASSWORD: ${{ secrets.GITHUB_TOKEN }} | |
| INPUT_LIMIT_SEVERITIES_FOR_SARIF: true | |
| TARGET_IMAGE_BASETAG: ${{ env.TARGET_IMAGE_BASETAG }} | |
| - name: Upload Trivy scan results as Markdows report | |
| if: always() | |
| run: | | |
| echo "# Trivy Scan Results for ${{ matrix.folder }}:${{ env.TARGET_IMAGE_BASETAG }}" > ${GITHUB_STEP_SUMMARY} | |
| cat trivy-results.md >> ${GITHUB_STEP_SUMMARY} | |
| echo "Trivy scan results uploaded as Markdown report" | |
| env: | |
| TARGET_IMAGE_BASETAG: ${{ env.TARGET_IMAGE_BASETAG }} | |
| #- name: Upload Trivy scan results to GitHub Security tab | |
| # uses: github/codeql-action/upload-sarif@v4 | |
| # if: always() | |
| # with: | |
| # sarif_file: 'trivy-results.sarif' |