diff --git a/.github/scripts/format-cve-scan-results.sh b/.github/scripts/format-cve-scan-results.sh new file mode 100755 index 00000000000..3abe35252ad --- /dev/null +++ b/.github/scripts/format-cve-scan-results.sh @@ -0,0 +1,47 @@ +#!/bin/bash +set -o errexit -o nounset -o pipefail +[[ "${TRACE:-0}" == "1" ]] && set -o xtrace + +## +# Formats CVE results in a markdown table to display a summary in a GitHub Action UI +## + +# Check if the number of arguments is correct +if [ $# -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +_results_filename="${1}" + +# Check if the file exists +if [ ! -f "${_results_filename}" ]; then + echo "Error: File '${_results_filename}' does not exist" + exit 1 +fi + +_number_of_cves_found=$(jq -r '.matches | length' "${_results_filename}") + +echo -e "# CVE Scan Results\n" + +if [ ${_number_of_cves_found} -eq 0 ]; then + echo -e "## Success! No vulnerabilities found.\n" +else + echo -e "## Failure: ${_number_of_cves_found} vulnerabilities found.\n" + + _table_headers='"NAME","INSTALLED","FIXED-IN","TYPE","VULNERABILITY","SEVERITY"' + _table_underlines='"----","---------","--------","----","-------------","--------"' + + jq -r "[${_table_headers}], + [${_table_underlines}], + (.matches[] | [ + .artifact.name, + .artifact.version, + .vulnerability.fix.versions[0], + .artifact.type, + .vulnerability.id, + .vulnerability.severity + ]) | @tsv" "${_results_filename}" \ + | sed 's/|/\\|/g' \ + | sed 's/\t/ | /g' +fi \ No newline at end of file diff --git a/.github/workflows/check-cves.yml b/.github/workflows/check-cves.yml new file mode 100644 index 00000000000..cef3430824f --- /dev/null +++ b/.github/workflows/check-cves.yml @@ -0,0 +1,32 @@ +name: "Check CVEs" + +on: + workflow_dispatch: + pull_request: + +jobs: + check-cves: + runs-on: ubuntu-latest + + steps: + - name: Check out codebase + uses: actions/checkout@v4 + + - name: Scan current project + uses: anchore/scan-action@v3 + with: + path: "." + add-cpes-if-none: true + by-cve: true + output-format: json + + - name: Print scan results + run: .github/scripts/format-cve-scan-results.sh results.json > $GITHUB_STEP_SUMMARY + if: always() + + - name: Archive CVE scan results + uses: actions/upload-artifact@v4 + if: always() + with: + name: cve-scan-results-${{ github.sha }}-${{ github.run_id }}-${{ github.run_number }} + path: results.json \ No newline at end of file