Skip to content

Container Security Scan #107

Container Security Scan

Container Security Scan #107

# Copyright AGNTCY Contributors (https://github.com/agntcy)
# SPDX-License-Identifier: Apache-2.0
name: Container Security Scan
on:
schedule:
- cron: "0 3 * * *" # Daily at 03:00 UTC
workflow_dispatch:
permissions:
contents: read
security-events: write # for uploading SARIF
actions: read
issues: write # create issues for critical CVEs
jobs:
image-list:
name: Resolve image list
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Install Task
uses: go-task/setup-task@3be4020d41929789a01026e0e427a4321ce0ad44 #v2.0.0
- name: Get image list from task
id: matrix
run: |
matrix=$(task --silent deps:vuln:images:list | jq -R -s -c 'split("\n") | map(select(length > 0)) | {image: .}')
echo "matrix<<EOF" >> $GITHUB_OUTPUT
echo "$matrix" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
trivy-scan:
name: Trivy Scan
runs-on: ubuntu-latest
needs: [image-list]
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.image-list.outputs.matrix) }}
steps:
- name: Set image name
id: image-name
run: |
# Extract image name from full reference (e.g., ghcr.io/owner/image:tag -> image)
IMAGE_NAME=$(echo "${{ matrix.image }}" | sed -E 's|.*/||; s|[:@].*||')
echo "name=$IMAGE_NAME" >> $GITHUB_OUTPUT
- name: Scan image
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0
with:
image-ref: ${{ matrix.image }}
github-pat: ${{ secrets.GITHUB_TOKEN }}
format: sarif
output: trivy-${{ steps.image-name.outputs.name }}.sarif
vuln-type: "os,library"
severity: "CRITICAL,HIGH,MEDIUM"
ignore-unfixed: true
- name: Export image metadata
run: echo "${{ matrix.image }}" > trivy-${{ steps.image-name.outputs.name }}.meta
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@38697555549f1db7851b81482ff19f1fa5c4fedc # v4.34.1
with:
sarif_file: trivy-${{ steps.image-name.outputs.name }}.sarif
category: trivy-${{ steps.image-name.outputs.name }}
- name: Upload report artifacts
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: trivy-report-${{ steps.image-name.outputs.name }}
path: |
trivy-${{ steps.image-name.outputs.name }}.sarif
trivy-${{ steps.image-name.outputs.name }}.meta
retention-days: 7
summarize:
name: Summarize Results
needs: [trivy-scan]
runs-on: ubuntu-latest
if: always()
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Download artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
pattern: trivy-report-*
path: trivy-artifacts
- name: Generate summary
run: |
chmod +x .github/workflows/scripts/security/generate_trivy_summary.sh
.github/workflows/scripts/security/generate_trivy_summary.sh