Scan images #489
This file contains 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: Scan images | |
on: | |
schedule: | |
# every day at 1:12AM UTC | |
- cron: '12 1 * * *' | |
workflow_dispatch: | |
jobs: | |
get-images: | |
name: Get images | |
runs-on: ubuntu-22.04 | |
outputs: | |
images-array: ${{ steps.set-images-array.outputs.images-array }} | |
strategy: | |
matrix: | |
# specify location of bundle(s) to be scanned | |
bundle: | |
- releases/1.8/stable/kubeflow | |
- releases/1.9/stable | |
- releases/latest/edge | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Run get-all-images.py | |
run: | | |
BUNDLE="${{ matrix.bundle }}" | |
BUNDLE_SPLIT=(${BUNDLE//\// }) | |
RELEASE=${BUNDLE_SPLIT[1]} | |
RISK=${BUNDLE_SPLIT[2]} | |
pip3 install -r scripts/requirements.txt | |
python3 scripts/get-all-images.py ${{ matrix.bundle }}/bundle.yaml > /tmp/images_list.txt | |
echo "Image list:" | |
cat /tmp/images_list.txt | |
echo "release_risk=${RELEASE}-${RISK}" >> $GITHUB_OUTPUT | |
- name: Generate an array of images | |
id: set-images-array | |
run: | | |
# Output the images as an array that can be used in the matrix strategy for the scan images job | |
# This array contains all the images from /tmp/image_list.txt | |
sudo snap install jq | |
DATA=$(cat /tmp/images_list.txt | jq -R -s -c 'split("\n")[:-1]') | |
echo "::set-output name=images-array::$DATA" | |
scan-images: | |
name: Scan images in bundle | |
runs-on: ubuntu-22.04 | |
needs: get-images | |
outputs: | |
report-path: ${{ steps.report-path.outputs.report-path }} | |
strategy: | |
matrix: | |
image: ${{ fromJSON(needs.get-images.outputs.images-array) }} | |
steps: | |
- name: Prepare environment | |
run: mkdir -p /tmp/trivy-reports | |
- name: Run Trivy vulnerability scanner | |
uses: aquasecurity/[email protected] | |
with: | |
image-ref: ${{ matrix.image }} | |
output: ${{ steps.report-path.outputs.report-path }} | |
format: 'json' | |
exit-code: '1' | |
ignore-unfixed: true | |
severity: 'CRITICAL,HIGH' | |
- name: Generate report path | |
id: report-path | |
run: | | |
FILENAME=$(echo ${{ matrix.image }} | sed 's/:/-/g; s/\//-/g; s/\./-/g') | |
PATH="/tmp/trivy-reports/${FILENAME}.json" | |
echo "::set-output name=report-path::$PATH" | |
# | |
# - name: Prepare artifacts | |
# run: | | |
# tar zcvf trivy-reports-${{ steps.setup.outputs.date}}-${{ steps.images.outputs.release_risk }}-${{ strategy.job-index }}.tar.gz /tmp/trivy-reports | |
# | |
# - name: Upload Trivy reports | |
# uses: actions/upload-artifact@v3 | |
# with: | |
# name: trivy-reports | |
# path: trivy-reports-${{ steps.setup.outputs.date}}-${{ steps.images.outputs.release_risk }}-${{ strategy.job-index }}.tar.gz | |
# - name: Upload summary | |
# uses: actions/upload-artifact@v3 | |
# with: | |
# name: summary | |
# path: scan-summary-${{ steps.setup.outputs.date}}-${{ steps.images.outputs.release_risk }}.csv |