Container Security Scanning #435
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: Container Security Scanning | |
| on: | |
| workflow_run: | |
| workflows: ["Publish Docker Images"] | |
| types: | |
| - completed | |
| schedule: | |
| # Scan images weekly on Sundays at 3 AM UTC | |
| - cron: '0 3 * * 0' | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| security-events: write | |
| packages: read | |
| jobs: | |
| scan-images: | |
| name: Scan Container Images | |
| runs-on: ubuntu-latest | |
| if: | | |
| (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') || | |
| (github.event_name == 'schedule') || | |
| (github.event_name == 'workflow_dispatch') | |
| strategy: | |
| max-parallel: 1 # Run scans sequentially to prevent disk space issues | |
| matrix: | |
| image: | |
| - ols4-dataload | |
| - ols4-embed | |
| - ols4-backend | |
| - ols4-frontend | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Free up disk space before scan | |
| run: | | |
| echo "Disk space before cleanup:" | |
| df -h | |
| sudo rm -rf /usr/share/dotnet | |
| sudo rm -rf /usr/local/lib/android | |
| sudo rm -rf /opt/ghc | |
| sudo rm -rf /opt/hostedtoolcache/CodeQL | |
| docker system prune -af --volumes | |
| echo "Disk space after cleanup:" | |
| df -h | |
| - name: Log in to the Container registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Determine image tag | |
| id: tag | |
| run: | | |
| if [ "${{ github.event_name }}" = "schedule" ] || [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| echo "tag=dev" >> $GITHUB_OUTPUT | |
| else | |
| echo "tag=${{ github.event.workflow_run.head_branch }}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Pull Docker image | |
| run: | | |
| docker pull ghcr.io/ebispot/${{ matrix.image }}:${{ steps.tag.outputs.tag }} | |
| - name: Run Trivy vulnerability scanner | |
| uses: aquasecurity/trivy-action@master | |
| env: | |
| TMPDIR: ${{ runner.temp }} | |
| with: | |
| image-ref: ghcr.io/ebispot/${{ matrix.image }}:${{ steps.tag.outputs.tag }} | |
| format: 'sarif' | |
| output: 'trivy-results-${{ matrix.image }}.sarif' | |
| severity: 'CRITICAL,HIGH,MEDIUM' | |
| scanners: 'vuln' | |
| vuln-type: 'os,library' | |
| timeout: '10m' | |
| - name: Upload Trivy results to GitHub Security tab | |
| uses: github/codeql-action/upload-sarif@v3 | |
| if: always() | |
| with: | |
| sarif_file: 'trivy-results-${{ matrix.image }}.sarif' | |
| category: 'container-${{ matrix.image }}' | |
| - name: Cleanup after scan | |
| if: always() | |
| run: | | |
| echo "Cleaning up to free disk space..." | |
| docker rmi ghcr.io/ebispot/${{ matrix.image }}:${{ steps.tag.outputs.tag }} || true | |
| docker system prune -af --volumes | |
| rm -rf ${{ runner.temp }}/* | |
| echo "Disk space after cleanup:" | |
| df -h |