Skip to content

Commit 8cae9d8

Browse files
committed
twoliter: add check-advisories task to lint BRSAs
Lint BRSAs for non-ASCII characters that may be included in advisory information in a new task, check-advisories. Also ensure that each directory under "advisories" in a project has an associated tag on the project Add this to the list in the meta task "check" Signed-off-by: Gavin Inglis <[email protected]>
1 parent b66ba99 commit 8cae9d8

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

twoliter/embedded/Makefile.toml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ done
416416
[tasks.check]
417417
dependencies = [
418418
"check-cargo-version",
419+
"check-advisories",
419420
"unit-tests",
420421
"check-fmt",
421422
"check-lints",
@@ -540,6 +541,61 @@ fi
540541
'''
541542
]
542543

544+
# Task to lint Bottlerocket Security Advisories by checking for valid CVE or GHSA IDs
545+
# and verifying that each versioned directory under "advisories" has a corresponding
546+
# tag on the Twoliter project this task runs against.
547+
[tasks.check-advisories]
548+
script_runner = "bash"
549+
script = [
550+
'''
551+
if find advisories -name '*.toml' -type f >/dev/null 2>&1 ; then
552+
553+
# Ensure each versioned advisories directory has a corresponding release tag.
554+
for version in $(find advisories/* -type d -not -path advisories/staging); do
555+
set +e; grep -q v$(basename ${version})$ <(PAGER= git tag); rc="$?"; set -e;
556+
if [ "${rc}" -ne 0 ]; then
557+
echo "error: no corresponding tag found for ${version} advisories directory" >&2
558+
exit 1
559+
fi
560+
done
561+
562+
563+
# Not all BRSAs might have a CVE; there can be cases where an advisory
564+
# is for a GHSA, for example, but no corresponding CVE, and vice versa.
565+
# Check separately for GHSA ID regex when a 'ghsa' is included and for
566+
# CVE ID regex when a 'cve' is included.
567+
568+
# 1. If ghsa line exists and GHSA ID does not match regex, error
569+
570+
# Regex to strictly match a GHSA identifier in an advisory
571+
# https://github.com/github/advisory-database?tab=readme-ov-file#ghsa-ids
572+
ghsa_regex="^ghsa\s+=\s+\"GHSA(-[23456789cfghjmpqrvwx]{4}){3}\""
573+
574+
# Find all non-matching GHSA lines and report
575+
ghsa_found="$(grep -L --include '*.toml' -R -P ${ghsa_regex} advisories | xargs awk '/ghsa/')"
576+
if [ ! -z "${ghsa_found}" ] ; then
577+
echo "error: advisory GHSA ID did not match expression '${ghsa_regex}' and may contain non-ASCII characters" >&2
578+
echo "${ghsa_found}" >&2
579+
exit 1
580+
fi
581+
582+
# 2. If cve line exists and CVE ID does not match regex, error
583+
584+
# Regex to strictly match CVE identifier in an advisory
585+
# https://cve.mitre.org/cve/identifiers/tech-guidance.html#input_format
586+
cve_regex="^cve\s+=\s+\"CVE-\d{4}-(0\d{3}|[1-9]\d{3,})\""
587+
588+
# Find all non-matching CVE lines and report
589+
cve_found="$(grep -L --include '*.toml' -R -P ${cve_regex} advisories | xargs awk '/cve/')"
590+
if [ ! -z "${cve_found}" ] ; then
591+
echo "error: advisory CVE ID did not match expression '${cve_regex}' and may contain non-ASCII characters" >&2
592+
echo "${cve_found}" >&2
593+
exit 1
594+
fi
595+
fi
596+
'''
597+
]
598+
543599
[tasks.check-golangci-lint]
544600
script = [
545601
'''

0 commit comments

Comments
 (0)