BuildSpec and Jenkins examples with stages for Post-build container image scans, using open source container vulnerability scanners (Trivy / Grype)
See below:
-
ArtifactPath=$(pwd)
-
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
-
cd $ArtifactPath
-
wget https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/html.tpl
-
trivy i -f template --template "@html.tpl" -o {scan-results} --exit-code 0 --severity HIGH,MEDIUM,LOW,CRITICAL $REPOSITORY_URI/repository:tag
-
ArtifactPath=$(pwd)
-
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin
-
cd $ArtifactPath
-
grype $REPOSITORY_URI/repository:tag | tee {scan-results}
ArtifactPath=$(pwd) cd $ArtifactPath
For this stage we leverage trufflehog3, an enhanced version of the truffleHog scanner, which is a popular open source project for finding secrets accidentally committed in repositories. It essentially searches through git repositories for secrets, digging deep into commit history and branches. It identifies secrets by running entropy checks as well as high signal regex checks.