Skip to content

Instantly share code, notes, and snippets.

@oceanBT
Created June 21, 2020 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oceanBT/7ec5b81f5300878ff7982185ae78b2e1 to your computer and use it in GitHub Desktop.
Save oceanBT/7ec5b81f5300878ff7982185ae78b2e1 to your computer and use it in GitHub Desktop.
trivy-scan-all-lokal-image-script
#!/bin/bash
if ! [ -x "$(command -v jq)" ]; then
echo 'Error: jq is not installed.' >&2
exit 1
fi
for image in $( docker images --format "{{.Repository}}")
do
for parameter in "$@"
do
if [[ "$image" == "$parameter" ]]
then
continue 2
fi
done
scanResult=$( docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/trivy_cache:/root/.cache/ aquasec/trivy -q --severity CRITICAL --format json $image 2> /dev/null )
if [ $? -ne 0 ]; then
echo -e "trivy-scan failed on image: ${image}"
continue
fi
result=$( echo "$scanResult" | jq -r ".[].Vulnerabilities" 2> /dev/null )
if [ $? -ne 0 ]; then
echo -e "No valid trivy result on image: ${image}"
continue
fi
if [[ "$result" != "null" ]]
then
echo -e "Critical vulnerability on image: ${scanResult}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment