-
Notifications
You must be signed in to change notification settings - Fork 23
Add Trivy image scanning #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
75c2a7d
Trivy scanning
k-s-dean 7777193
Fix Trivy install permissions
k-s-dean 290b0e7
remove push for testing
k-s-dean 82bb994
fix input
k-s-dean 78e0eb9
fix incorrect path
k-s-dean 3fab758
missing sudo
k-s-dean 5fac63e
Bump trivy version
k-s-dean c20bf35
try folder upload for sarif files
k-s-dean ed8284e
Test
k-s-dean e553791
Test
k-s-dean 60d54d9
test
k-s-dean 0addd68
test
k-s-dean df003de
test
k-s-dean 1489682
Code clean up and fixes
k-s-dean c730780
add push back
k-s-dean 5f2ff76
Get images to scan for seed and overcloud
k-s-dean a0ccf84
Merge branch 'stackhpc/yoga' into feat/trivy-image-scanning-test
m-bull a83e64e
Separate image build and push steps
m-bull dd34768
Merge branch 'stackhpc/yoga' into feat/trivy-image-scanning-test
m-bull 1a9ab2e
Correct workflow syntax
m-bull 30b2c0c
Merge branch 'stackhpc/yoga' into feat/trivy-image-scanning-test
JohnGarbutt f95c705
Merge branch 'stackhpc/yoga' into feat/trivy-image-scanning-test
Alex-Welsh 78bac79
Trivy scanning Feb 2024 refresh
Alex-Welsh 06857bd
Fixup container image scanning PR
Alex-Welsh c032f68
Container image builds misc improvements
Alex-Welsh 2be1d27
Kolla image build - improve output formatting
Alex-Welsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
- name: Login to docker registry | ||
gather_facts: false | ||
hosts: container-image-builders | ||
tasks: | ||
- name: Login to docker registry | ||
docker_login: | ||
registry_url: "{{ kolla_docker_registry or omit }}" | ||
username: "{{ kolla_docker_registry_username }}" | ||
password: "{{ kolla_docker_registry_password }}" | ||
reauthorize: yes |
6 changes: 6 additions & 0 deletions
6
releasenotes/notes/container-image-scanning-e5adf2c6b540b502.yaml
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
security: | ||
- | | ||
Kolla container images created using the | ||
``stackhpc-container-image-build.yml`` workflow are now automatically | ||
scanned for vulnerablilities. |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env bash | ||
set -eo pipefail | ||
Alex-Welsh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Check correct usage | ||
if [[ ! $2 ]]; then | ||
echo "Usage: scan-images.sh <os-distribution> <image-tag>" | ||
exit 2 | ||
fi | ||
|
||
set -u | ||
|
||
# Check that trivy is installed | ||
if ! trivy --version; then | ||
echo 'Please install trivy: curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin v0.49.1' | ||
fi | ||
|
||
# Clear any previous outputs | ||
rm -rf image-scan-output | ||
|
||
# Make a fresh output directory | ||
Alex-Welsh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mkdir -p image-scan-output | ||
|
||
# Get built container images | ||
docker image ls --filter "reference=ark.stackhpc.com/stackhpc-dev/$1-*:$2" > $1-scanned-container-images.txt | ||
|
||
# Make a file of imagename:tag | ||
images=$(grep --invert-match --no-filename ^REPOSITORY $1-scanned-container-images.txt | sed 's/ \+/:/g' | cut -f 1,2 -d:) | ||
|
||
Alex-Welsh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Ensure output files exist | ||
touch image-scan-output/clean-images.txt image-scan-output/dirty-images.txt | ||
|
||
# If Trivy detects no vulnerabilities, add the image name to clean-images.txt. | ||
# If there are vulnerabilities detected, add it to dirty-images.txt and | ||
# generate a csv summary | ||
for image in $images; do | ||
filename=$(basename $image | sed 's/:/\./g') | ||
Alex-Welsh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if $(trivy image \ | ||
--quiet \ | ||
--exit-code 1 \ | ||
--scanners vuln \ | ||
--format json \ | ||
--severity HIGH,CRITICAL \ | ||
--output image-scan-output/${filename}.json \ | ||
--ignore-unfixed \ | ||
$image); then | ||
# Clean up the output file for any images with no vulnerabilities | ||
rm -f image-scan-output/${filename}.json | ||
|
||
# Add the image to the clean list | ||
echo "${image}" >> image-scan-output/clean-images.txt | ||
else | ||
# Add the image to the dirty list | ||
echo "${image}" >> image-scan-output/dirty-images.txt | ||
|
||
# Write a header for the summary CSV | ||
echo '"PkgName","PkgPath","PkgID","VulnerabilityID","FixedVersion","PrimaryURL","Severity"' > image-scan-output/${filename}.summary.csv | ||
|
||
# Write the summary CSV data | ||
jq -r '.Results[] | ||
| select(.Vulnerabilities) | ||
| .Vulnerabilities | ||
# Ignore packages with "kernel" in the PkgName | ||
| map(select(.PkgName | test("kernel") | not )) | ||
| group_by(.VulnerabilityID) | ||
| map( | ||
[ | ||
(map(.PkgName) | unique | join(";")), | ||
(map(.PkgPath | select( . != null )) | join(";")), | ||
.[0].PkgID, | ||
.[0].VulnerabilityID, | ||
.[0].FixedVersion, | ||
.[0].PrimaryURL, | ||
.[0].Severity | ||
] | ||
) | ||
| .[] | ||
| @csv' image-scan-output/${filename}.json >> image-scan-output/${filename}.summary.csv | ||
fi | ||
done |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.