|
416 | 416 | [tasks.check] |
417 | 417 | dependencies = [ |
418 | 418 | "check-cargo-version", |
| 419 | + "check-advisories", |
419 | 420 | "unit-tests", |
420 | 421 | "check-fmt", |
421 | 422 | "check-lints", |
|
540 | 541 | ''' |
541 | 542 | ] |
542 | 543 |
|
| 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 | + |
543 | 599 | [tasks.check-golangci-lint] |
544 | 600 | script = [ |
545 | 601 | ''' |
|
0 commit comments