Skip to content

Commit

Permalink
Merge pull request #2251 from simonbaird/view-clair-hack-tweaks
Browse files Browse the repository at this point in the history
Minor improvements for the script to view clair reports
  • Loading branch information
simonbaird authored Jan 8, 2025
2 parents 82881da + 67d129b commit 6290a43
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions hack/view-clair-reports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,21 @@ IMAGE=${1:-"$DEFAULT_IMAGE"}

OPT=${2:-""}

REPO=$(echo "$IMAGE" | cut -d '@' -f 1)
# Remove digest maybe
REPO=${IMAGE/@*/}

# Remove tag maybe
REPO=${REPO/:*/}

CLAIR_REPORT_SHAS=$(
cosign download attestation $IMAGE | jq -r '.payload|@base64d|fromjson|.predicate.buildConfig.tasks[]|select(.name=="clair-scan").results[]|select(.name=="REPORTS").value|fromjson|.[]'
cosign download attestation $IMAGE | jq -r '
.payload | @base64d | fromjson |
.predicate.buildConfig.tasks[] |
select(.name=="clair-scan").results[] |
select(.name=="REPORTS").value |
fromjson |
.[]
'
)

# For multi-arch the same report maybe associated with each of the per-arch
Expand All @@ -55,14 +66,11 @@ for b in $ALL_BLOBS; do
YQ_QUERY='.'
fi
if [ "$OPT" == "--high" ]; then
echo "# Severity High"
YQ_QUERY="$YQ_QUERY | .[] |select(.normalized_severity == \"High\") | [.]"
fi
if [ "$OPT" == "--critical" ]; then
echo "# Severity Critical"
YQ_QUERY="$YQ_QUERY | .[] |select(.normalized_severity == \"Critical\") | [.]"
if [[ "$OPT" =~ ^--Low|--Medium|--High|--Critical|--Unknown$ ]]; then
# Filter by severity
SEV=${OPT//--}
echo "# Severity $SEV"
YQ_QUERY="$YQ_QUERY | .[] | select(.normalized_severity == \"$SEV\") | [.]"
fi
echo "#"
Expand Down

0 comments on commit 6290a43

Please sign in to comment.