Skip to content

Instantly share code, notes, and snippets.

@ams0
Created March 11, 2021 00:35
Show Gist options
  • Save ams0/2a3ab70d7a2d03fa301e750704e03fa5 to your computer and use it in GitHub Desktop.
Save ams0/2a3ab70d7a2d03fa301e750704e03fa5 to your computer and use it in GitHub Desktop.
A script to scan all images in the current Kubernetes cluster with Trivy (https://github.com/aquasecurity/trivy) for high & critical vulnerabilities.
#/bin/bash
if [ ! -f /usr/local/bin/trivy ]; then
echo "Trivy not found! Please install it from https://github.com/aquasecurity/trivy"
fi
for image in `kubectl get pods --all-namespaces -o jsonpath="{..image}" |\
tr -s '[[:space:]]' '\n' |\
sort |\
uniq -c | awk '{print $2}'`; do trivy image -s HIGH,CRITICAL $image; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment