Skip to content
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

Feat/trivyignore #211

Merged
merged 17 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/autoremove_trivyignore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

name: Auto-remove ignored CVEs
on:
workflow_call:

jobs:
update-lib:
merkata marked this conversation as resolved.
Show resolved Hide resolved
permissions:
id-token: write # Enable OIDC
pull-requests: write
contents: write
name: Autoremove ignored CVEs
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Check trivyignore
run: |
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin v0.18.3
if [ -f ".trivyignore" ]
then
output=$(trivy fs . -q -f json --ignorefile "" | jq -r '.Results[].Vulnerabilities[].VulnerabilityID' 2>/dev/null || echo "No vulnerabilities found")
merkata marked this conversation as resolved.
Show resolved Hide resolved
newTrivyIgnore=()
for CVE in $(cat .trivyignore)
do
if [[ "$output" != *"$CVE"* ]]
then
echo "$CVE not present anymore, moving out of trivyignore file"
newTrivyIgnore+=( $CVE )
else
echo "$CVE still present"
fi
done
echo "Removing entries from trivyignore"
for IgnoredCVE in ${newTrivyIgnore[@]}
do
sed -i "/$IgnoredCVE/d" .trivyignore
done
fi
- name: Create pull request
uses: canonical/create-pull-request@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "chore: auto-remove ignored CVEs"
branch-name: "chore/autoremove-cves"
title: Auto-remote ignored CVEs
body: |
Automated action to remove ignored CVEs that are fixed.
The branch of this PR will be wiped during the next check.
Unless you really know what you're doing, you most likely don't want
to push any commits to this branch.
upsert: true
ignore-no-changes: true
22 changes: 22 additions & 0 deletions .github/workflows/build_rocks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ jobs:
path: ${{ fromJSON(needs.get-rocks.outputs.rock-paths) }}
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0
- name: Extract rock information
run: |
IMAGE_NAME=$(yq '.name' "${{ matrix.path }}/rockcraft.yaml")
Expand Down Expand Up @@ -224,3 +226,23 @@ jobs:
env:
TRIVY_USERNAME: ${{ github.actor }}
TRIVY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
- name: Check trivyignore
jdkandersson marked this conversation as resolved.
Show resolved Hide resolved
run: |
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin v0.46.0
if [ -f ".trivyignore" ]
then
output=$(trivy image $ROCK_IMAGE --severity HIGH,CRITICAL -q -f json --ignorefile "" | jq -r '.Results[].Vulnerabilities[].VulnerabilityID' 2>/dev/null || echo "No vulnerabilities found")
merkata marked this conversation as resolved.
Show resolved Hide resolved
line=0
while read CVE;
do
line=$(( line + 1 ))
if [[ "$output" != *"$CVE"* ]] && [[ ! "$CVE" =~ ^#.* ]]
then
echo "::notice file=.trivyignore,line=${line}::$CVE not present anymore, can be safely removed."
fi
done < .trivyignore
fi
env:
TRIVY_USERNAME: ${{ github.actor }}
TRIVY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
ROCK_IMAGE: ${{ env.IMAGE_REF }}