Security Analysis #419
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
| name: Security Analysis | |
| on: | |
| schedule: | |
| - cron: '0 2 * * *' | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| security-events: write | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| security-scan: | |
| runs-on: ubuntu-latest | |
| name: Security and SBOM Analysis | |
| timeout-minutes: 20 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - name: Build Docker image for scanning | |
| id: build | |
| continue-on-error: true | |
| run: | | |
| IMAGE_NAME="dev-template:${{ github.sha }}" | |
| docker build --pull -t "$IMAGE_NAME" .devcontainer/ | |
| echo "IMAGE_NAME=$IMAGE_NAME" >> "$GITHUB_ENV" | |
| - name: Run Trivy vulnerability scanner (image) | |
| if: steps.build.outcome == 'success' | |
| uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 | |
| with: | |
| image-ref: '${{ env.IMAGE_NAME }}' | |
| format: 'sarif' | |
| output: 'trivy-results.sarif' | |
| severity: 'CRITICAL,HIGH' | |
| exit-code: '0' | |
| - name: Upload Trivy image scan results | |
| if: steps.build.outcome == 'success' | |
| uses: github/codeql-action/upload-sarif@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4 | |
| with: | |
| sarif_file: 'trivy-results.sarif' | |
| category: 'security-analysis/trivy-image' | |
| - name: Generate SBOM | |
| if: steps.build.outcome == 'success' | |
| uses: anchore/sbom-action@e22c389904149dbc22b58101806040fa8d37a610 # v0 | |
| with: | |
| image: '${{ env.IMAGE_NAME }}' | |
| format: 'spdx-json' | |
| output-file: 'sbom.spdx.json' | |
| - name: Upload SBOM as artifact | |
| if: steps.build.outcome == 'success' | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 | |
| with: | |
| name: sbom-${{ github.sha }} | |
| path: sbom.spdx.json | |
| retention-days: 30 | |
| - name: Run Trivy vulnerability scanner (filesystem) | |
| uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 | |
| with: | |
| scan-type: 'fs' | |
| scan-ref: '.' | |
| format: 'sarif' | |
| output: 'trivy-fs-results.sarif' | |
| severity: 'CRITICAL,HIGH' | |
| exit-code: '0' | |
| - name: Upload Trivy filesystem scan results | |
| if: always() | |
| uses: github/codeql-action/upload-sarif@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4 | |
| with: | |
| sarif_file: 'trivy-fs-results.sarif' | |
| category: 'security-analysis/trivy-filesystem' |