From 158adbf1fb720dd17570db027d2e2861b0ff6ae2 Mon Sep 17 00:00:00 2001 From: Eric Hare Date: Tue, 27 Oct 2026 12:55:49 -0700 Subject: [PATCH 1/4] ci: add IBM Mend SCA scan Runs the Mend CLI dependency scan ("mend dep"), the path the DataStax Mend onboarding runbook requires for repos outside IBM's GitHub Enterprise space. Pushes to main and PRs against main report only; release tags also update the Mend platform. Critical or High findings turn the job red without blocking merges. Fork PRs are skipped because they get no secrets. Needs MEND_USER_KEY, MEND_EMAIL and MEND_PRODUCTNAME before it can run. --- .github/workflows/ibm-mend.yaml | 145 ++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 .github/workflows/ibm-mend.yaml diff --git a/.github/workflows/ibm-mend.yaml b/.github/workflows/ibm-mend.yaml new file mode 100644 index 0000000000..fa9820e597 --- /dev/null +++ b/.github/workflows/ibm-mend.yaml @@ -0,0 +1,145 @@ +# Open-source dependency (SCA) scan on IBM Mend, using the Mend CLI ("mend dep") path that the +# DataStax Mend onboarding runbook requires for repos outside IBM's GitHub Enterprise space. +# Results land under Products////Data API - data-api in the IBM Mend platform. +name: IBM Mend SCA Scan + +# runs on +# * pushes to "main" (report only) +# * release tags (updates the project inventory on the Mend platform) +# * pull requests against "main" (report only) +# * manual trigger +on: + push: + branches: [ "main" ] + tags: [ "v*" ] + + pull_request: + types: [ opened, synchronize, reopened ] + branches: [ "main" ] + + workflow_dispatch: + +# cancel same workflows in progress for pull request branches +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} + +permissions: + contents: read + +# global env vars, available in all jobs and steps +env: + MAVEN_OPTS: '-Xmx4g' + DS_ARTIFACTORY_USERNAME: ${{ secrets.DS_ARTIFACTORY_USERNAME }} + DS_ARTIFACTORY_PASSWORD: ${{ secrets.DS_ARTIFACTORY_PASSWORD }} + # the runbook asks for the DataStax product name here, so SecEng can map findings to a product and repo + MEND_PROJECTNAME: "Data API" + MEND_URL: "https://ibmets.whitesourcesoftware.com" + MEND_REPORT: "mend-results.json" + MEND_REPO: ${{ github.event.repository.name }} + +jobs: + + mend: + name: IBM Mend SCA + # pull requests from forks get no org secrets, so the scan could not authenticate + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository + runs-on: ubuntu-latest + # per the runbook, findings turn this job red but never block PRs or releases + continue-on-error: true + + # max run time 20 minutes + timeout-minutes: 20 + + steps: + - uses: actions/checkout@v7 + + # the Mend CLI resolves dependencies through Maven, so it needs the JDK and the private repos + - name: Set up JDK 21 + uses: actions/setup-java@v5 + with: + distribution: 'temurin' + java-version: '21' + cache: maven + + - name: Setup Maven + run: | + mkdir -p ~/.m2 + cat < ~/.m2/settings.xml + + + + stargate-central + ${DS_ARTIFACTORY_USERNAME} + ${DS_ARTIFACTORY_PASSWORD} + + + stargate-snapshots + ${DS_ARTIFACTORY_USERNAME} + ${DS_ARTIFACTORY_PASSWORD} + + + artifactory + ${DS_ARTIFACTORY_USERNAME} + ${DS_ARTIFACTORY_PASSWORD} + + + artifactory-snapshots + ${DS_ARTIFACTORY_USERNAME} + ${DS_ARTIFACTORY_PASSWORD} + + + artifactory-releases + ${DS_ARTIFACTORY_USERNAME} + ${DS_ARTIFACTORY_PASSWORD} + + + + EOF + + # the CLI lives outside the workspace so it is never part of the scanned tree + - name: Download Mend CLI + run: | + curl --fail --silent --show-error --retry 3 --location \ + https://downloads.mend.io/cli/linux_amd64/mend -o "$RUNNER_TEMP/mend" + chmod +x "$RUNNER_TEMP/mend" + + # release tags update the Mend platform; every other run only reports. + # pipefail keeps a CLI failure (bad credentials, unresolvable build) from hiding behind tee. + - name: Mend dependency scan + env: + MEND_USER_KEY: ${{ secrets.MEND_USER_KEY }} + MEND_EMAIL: ${{ secrets.MEND_EMAIL }} + MEND_PRODUCTNAME: ${{ secrets.MEND_PRODUCTNAME }} + MEND_ORGNAME: Products + run: | + set -o pipefail + update_args=() + if [[ "$GITHUB_REF" == refs/tags/* ]]; then + update_args=(--update) + fi + "$RUNNER_TEMP/mend" dep --dir . \ + --scope "$MEND_ORGNAME//$MEND_PRODUCTNAME//$MEND_PROJECTNAME - $MEND_REPO" \ + --export-results "$MEND_REPORT" \ + --non-interactive \ + "${update_args[@]}" 2>&1 | tee mend-output.txt + + # the Mend CLI exits 0 on findings; parse its summary line and fail the job on Critical/High + - name: Fail on Critical/High findings + if: always() + run: | + [ -f mend-output.txt ] || { echo "::warning::Mend scan output not found."; exit 0; } + summary=$(grep 'Detected .* vulnerabilities' mend-output.txt || true) + critical=$(echo "$summary" | sed 's/.*(\([0-9]*\) Critical.*/\1/' | grep -E '^[0-9]+$' || echo 0) + high=$(echo "$summary" | sed 's/.*(\([0-9]* Critical, \)\([0-9]*\) High.*/\2/' | grep -E '^[0-9]+$' || echo 0) + if [ "$((${critical:-0} + ${high:-0}))" -gt 0 ]; then + echo "::error::Mend SCA: ${critical:-0} Critical, ${high:-0} High. See the mend-scan-report artifact." + exit 1 + fi + + - name: Upload Mend scan report + if: always() + uses: actions/upload-artifact@v7 + with: + name: mend-scan-report + path: ${{ env.MEND_REPORT }} From d38bd66cdc6ee8afed761bec4adc81a7a48a355d Mon Sep 17 00:00:00 2001 From: Eric Hare Date: Wed, 28 Oct 2026 08:11:37 -0700 Subject: [PATCH 2/4] ci: add Mend SAST scan and hard-gate both Mend jobs Follows the riptano/shared-github-actions Mend workflows that riptano/cloud-billing uses. The steps are copied rather than called, because a public repository cannot use reusable workflows from an internal one. SAST ("mend sast") fails on a finding of any severity. SCA still fails on Critical or High, now as a real failure instead of continue-on-error, and skips CVEs listed in .github/mend-allowlist.txt. Settings move to the cloud-billing names: ASTRA_DB_MEND_EMAIL and ASTRA_DB_MEND_PRODUCTNAME variables, optional ASTRA_DB_MEND_PROJECTNAME ("Astra DB") and ASTRA_DB_MEND_URL variables, and the ASTRA_DB_MEND_USER_KEY secret. Dependabot PRs are skipped along with fork PRs, since neither gets Actions secrets. --- .github/workflows/ibm-mend.yaml | 177 +++++++++++++++++++++++++++----- 1 file changed, 150 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ibm-mend.yaml b/.github/workflows/ibm-mend.yaml index fa9820e597..50a92acbef 100644 --- a/.github/workflows/ibm-mend.yaml +++ b/.github/workflows/ibm-mend.yaml @@ -1,12 +1,23 @@ -# Open-source dependency (SCA) scan on IBM Mend, using the Mend CLI ("mend dep") path that the -# DataStax Mend onboarding runbook requires for repos outside IBM's GitHub Enterprise space. -# Results land under Products////Data API - data-api in the IBM Mend platform. -name: IBM Mend SCA Scan +# IBM Mend scans, using the Mend CLI path that the DataStax Mend onboarding runbook requires for repos +# outside IBM's GitHub Enterprise space: +# * SCA ("mend dep") checks open-source dependencies and fails on Critical or High findings +# * SAST ("mend sast") checks our own source code and fails on any finding +# Results land under Products////Astra DB - data-api in the IBM Mend platform. +# +# The jobs follow riptano/shared-github-actions mend-sca.yml and mend-sast.yml, which riptano/cloud-billing +# calls. We copy their steps instead of calling them, because GitHub does not let a public repository use +# reusable workflows that live in an internal one. +# +# Needs the same settings as cloud-billing, set on the stargate org or this repo: +# * variables ASTRA_DB_MEND_EMAIL and ASTRA_DB_MEND_PRODUCTNAME (PSIRT_PRODxxxxxx) +# * optional variables ASTRA_DB_MEND_PROJECTNAME (defaults to "Astra DB") and ASTRA_DB_MEND_URL +# * secret ASTRA_DB_MEND_USER_KEY +name: IBM Mend Scan # runs on -# * pushes to "main" (report only) -# * release tags (updates the project inventory on the Mend platform) -# * pull requests against "main" (report only) +# * pushes to "main" +# * release tags (SCA also updates the project inventory on the Mend platform) +# * pull requests against "main" # * manual trigger on: push: @@ -29,29 +40,47 @@ permissions: # global env vars, available in all jobs and steps env: - MAVEN_OPTS: '-Xmx4g' - DS_ARTIFACTORY_USERNAME: ${{ secrets.DS_ARTIFACTORY_USERNAME }} - DS_ARTIFACTORY_PASSWORD: ${{ secrets.DS_ARTIFACTORY_PASSWORD }} - # the runbook asks for the DataStax product name here, so SecEng can map findings to a product and repo - MEND_PROJECTNAME: "Data API" - MEND_URL: "https://ibmets.whitesourcesoftware.com" - MEND_REPORT: "mend-results.json" + MEND_URL: ${{ vars.ASTRA_DB_MEND_URL || 'https://ibmets.whitesourcesoftware.com' }} + MEND_EMAIL: ${{ vars.ASTRA_DB_MEND_EMAIL }} + MEND_ORGNAME: Products + MEND_PRODUCTNAME: ${{ vars.ASTRA_DB_MEND_PRODUCTNAME }} + MEND_PROJECTNAME: ${{ vars.ASTRA_DB_MEND_PROJECTNAME || 'Astra DB' }} MEND_REPO: ${{ github.event.repository.name }} jobs: - mend: + mend-sca: name: IBM Mend SCA - # pull requests from forks get no org secrets, so the scan could not authenticate - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository + # fork and Dependabot pull requests get no Actions secrets, so the scan could not authenticate; + # their changes are scanned on the push to "main" after merge + if: >- + github.event_name != 'pull_request' || + (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') runs-on: ubuntu-latest - # per the runbook, findings turn this job red but never block PRs or releases - continue-on-error: true # max run time 20 minutes timeout-minutes: 20 + env: + MAVEN_OPTS: '-Xmx4g' + DS_ARTIFACTORY_USERNAME: ${{ secrets.DS_ARTIFACTORY_USERNAME }} + DS_ARTIFACTORY_PASSWORD: ${{ secrets.DS_ARTIFACTORY_PASSWORD }} + MEND_REPORT: "mend-sca-result.json" + steps: + - name: Check Mend settings + env: + MEND_USER_KEY: ${{ secrets.ASTRA_DB_MEND_USER_KEY }} + run: | + missing="" + [ -n "$MEND_USER_KEY" ] || missing="$missing secret:ASTRA_DB_MEND_USER_KEY" + [ -n "$MEND_EMAIL" ] || missing="$missing var:ASTRA_DB_MEND_EMAIL" + [ -n "$MEND_PRODUCTNAME" ] || missing="$missing var:ASTRA_DB_MEND_PRODUCTNAME" + if [ -n "$missing" ]; then + echo "::error::Mend settings are not configured:$missing" + exit 1 + fi + - uses: actions/checkout@v7 # the Mend CLI resolves dependencies through Maven, so it needs the JDK and the private repos @@ -108,10 +137,7 @@ jobs: # pipefail keeps a CLI failure (bad credentials, unresolvable build) from hiding behind tee. - name: Mend dependency scan env: - MEND_USER_KEY: ${{ secrets.MEND_USER_KEY }} - MEND_EMAIL: ${{ secrets.MEND_EMAIL }} - MEND_PRODUCTNAME: ${{ secrets.MEND_PRODUCTNAME }} - MEND_ORGNAME: Products + MEND_USER_KEY: ${{ secrets.ASTRA_DB_MEND_USER_KEY }} run: | set -o pipefail update_args=() @@ -124,7 +150,9 @@ jobs: --non-interactive \ "${update_args[@]}" 2>&1 | tee mend-output.txt - # the Mend CLI exits 0 on findings; parse its summary line and fail the job on Critical/High + # the Mend CLI exits 0 on findings; parse its summary line and fail the job on Critical/High. + # CVE IDs listed in .github/mend-allowlist.txt (one per line, # for comments) are reviewed + # exceptions and do not count. - name: Fail on Critical/High findings if: always() run: | @@ -132,8 +160,23 @@ jobs: summary=$(grep 'Detected .* vulnerabilities' mend-output.txt || true) critical=$(echo "$summary" | sed 's/.*(\([0-9]*\) Critical.*/\1/' | grep -E '^[0-9]+$' || echo 0) high=$(echo "$summary" | sed 's/.*(\([0-9]* Critical, \)\([0-9]*\) High.*/\2/' | grep -E '^[0-9]+$' || echo 0) - if [ "$((${critical:-0} + ${high:-0}))" -gt 0 ]; then - echo "::error::Mend SCA: ${critical:-0} Critical, ${high:-0} High. See the mend-scan-report artifact." + + accepted=0 + if [ -f .github/mend-allowlist.txt ]; then + while read -r cve _rest; do + case "$cve" in ''|\#*) continue ;; esac + n=$(grep -cE "^\| (CRITICAL|HIGH) .*\| ${cve} " mend-output.txt || true) + if [ "${n:-0}" -gt 0 ]; then + echo "::notice::Accepted finding ${cve} (listed in .github/mend-allowlist.txt)" + accepted=$((accepted + n)) + fi + done < .github/mend-allowlist.txt + fi + + blocking=$(( ${critical:-0} + ${high:-0} - accepted )) + echo "Mend SCA: ${critical:-0} Critical, ${high:-0} High (${accepted} accepted)" | tee -a "$GITHUB_STEP_SUMMARY" + if [ "$blocking" -gt 0 ]; then + echo "::error::Mend SCA: ${blocking} blocking Critical/High findings. See the mend-sca-report artifact." exit 1 fi @@ -141,5 +184,85 @@ jobs: if: always() uses: actions/upload-artifact@v7 with: - name: mend-scan-report + name: mend-sca-report path: ${{ env.MEND_REPORT }} + if-no-files-found: warn + + mend-sast: + name: IBM Mend SAST + # fork and Dependabot pull requests get no Actions secrets, so the scan could not authenticate; + # their changes are scanned on the push to "main" after merge + if: >- + github.event_name != 'pull_request' || + (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') + runs-on: ubuntu-latest + + # max run time 30 minutes + timeout-minutes: 30 + + env: + # base name only; the Mend CLI appends .json + MEND_REPORT: "mend-sast-results" + + steps: + - name: Check Mend settings + env: + MEND_USER_KEY: ${{ secrets.ASTRA_DB_MEND_USER_KEY }} + run: | + missing="" + [ -n "$MEND_USER_KEY" ] || missing="$missing secret:ASTRA_DB_MEND_USER_KEY" + [ -n "$MEND_EMAIL" ] || missing="$missing var:ASTRA_DB_MEND_EMAIL" + [ -n "$MEND_PRODUCTNAME" ] || missing="$missing var:ASTRA_DB_MEND_PRODUCTNAME" + if [ -n "$missing" ]; then + echo "::error::Mend settings are not configured:$missing" + exit 1 + fi + + - uses: actions/checkout@v7 + + # the CLI lives outside the workspace so it is never part of the scanned tree + - name: Download Mend CLI + run: | + curl --fail --silent --show-error --retry 3 --location \ + https://downloads.mend.io/cli/linux_amd64/mend -o "$RUNNER_TEMP/mend" + chmod +x "$RUNNER_TEMP/mend" + + # every SAST run uploads to the same Mend project, so the latest scan (PR or main) is what it shows + - name: Mend SAST scan + env: + MEND_USER_KEY: ${{ secrets.ASTRA_DB_MEND_USER_KEY }} + run: | + "$RUNNER_TEMP/mend" sast --dir . \ + --scope "$MEND_ORGNAME//$MEND_PRODUCTNAME//$MEND_PROJECTNAME - $MEND_REPO" \ + --report --formats json --filename "$MEND_REPORT" + + - name: Upload Mend scan report + if: always() + uses: actions/upload-artifact@v7 + with: + name: mend-sast-report + path: ${{ env.MEND_REPORT }}.json + if-no-files-found: warn + + # unlike SCA, SAST fails on a finding of any severity; a missing or malformed report also fails + - name: Fail on any SAST finding + if: always() + run: | + total=$(jq -er ' + if type != "array" or length == 0 then + error("Expected a non-empty array of Mend scan reports") + else + map(.stats.totalVulnerabilities | + if type != "number" then + error("Missing or invalid stats.totalVulnerabilities") + elif . < 0 or . != floor then + error("stats.totalVulnerabilities must be a non-negative integer") + else . end + ) | add + end + ' "$MEND_REPORT.json") + echo "Mend SAST total vulnerabilities: $total" | tee -a "$GITHUB_STEP_SUMMARY" + if [ "$total" -gt 0 ]; then + echo "::error::Mend SAST found $total vulnerabilities. See the mend-sast-report artifact." + exit 1 + fi From c67117192cef7813c22b4bad6e520acaa1507ea9 Mon Sep 17 00:00:00 2001 From: Eric Hare Date: Wed, 28 Oct 2026 08:13:05 -0700 Subject: [PATCH 3/4] ci: reword Mend workflow comments --- .github/workflows/ibm-mend.yaml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ibm-mend.yaml b/.github/workflows/ibm-mend.yaml index 50a92acbef..e63534d8b2 100644 --- a/.github/workflows/ibm-mend.yaml +++ b/.github/workflows/ibm-mend.yaml @@ -1,5 +1,5 @@ # IBM Mend scans, using the Mend CLI path that the DataStax Mend onboarding runbook requires for repos -# outside IBM's GitHub Enterprise space: +# outside IBM's GitHub Enterprise space. It runs two jobs. # * SCA ("mend dep") checks open-source dependencies and fails on Critical or High findings # * SAST ("mend sast") checks our own source code and fails on any finding # Results land under Products////Astra DB - data-api in the IBM Mend platform. @@ -8,7 +8,7 @@ # calls. We copy their steps instead of calling them, because GitHub does not let a public repository use # reusable workflows that live in an internal one. # -# Needs the same settings as cloud-billing, set on the stargate org or this repo: +# Needs the same settings as cloud-billing, set on the stargate org or on this repo. # * variables ASTRA_DB_MEND_EMAIL and ASTRA_DB_MEND_PRODUCTNAME (PSIRT_PRODxxxxxx) # * optional variables ASTRA_DB_MEND_PROJECTNAME (defaults to "Astra DB") and ASTRA_DB_MEND_URL # * secret ASTRA_DB_MEND_USER_KEY @@ -51,8 +51,8 @@ jobs: mend-sca: name: IBM Mend SCA - # fork and Dependabot pull requests get no Actions secrets, so the scan could not authenticate; - # their changes are scanned on the push to "main" after merge + # fork and Dependabot pull requests get no Actions secrets, so the scan could not authenticate, + # and their changes are scanned on the push to "main" after merge if: >- github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') @@ -133,7 +133,7 @@ jobs: https://downloads.mend.io/cli/linux_amd64/mend -o "$RUNNER_TEMP/mend" chmod +x "$RUNNER_TEMP/mend" - # release tags update the Mend platform; every other run only reports. + # release tags update the Mend platform, and every other run only reports. # pipefail keeps a CLI failure (bad credentials, unresolvable build) from hiding behind tee. - name: Mend dependency scan env: @@ -150,7 +150,7 @@ jobs: --non-interactive \ "${update_args[@]}" 2>&1 | tee mend-output.txt - # the Mend CLI exits 0 on findings; parse its summary line and fail the job on Critical/High. + # the Mend CLI exits 0 on findings, so parse its summary line and fail the job on Critical/High. # CVE IDs listed in .github/mend-allowlist.txt (one per line, # for comments) are reviewed # exceptions and do not count. - name: Fail on Critical/High findings @@ -190,8 +190,8 @@ jobs: mend-sast: name: IBM Mend SAST - # fork and Dependabot pull requests get no Actions secrets, so the scan could not authenticate; - # their changes are scanned on the push to "main" after merge + # fork and Dependabot pull requests get no Actions secrets, so the scan could not authenticate, + # and their changes are scanned on the push to "main" after merge if: >- github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') @@ -201,7 +201,7 @@ jobs: timeout-minutes: 30 env: - # base name only; the Mend CLI appends .json + # base name only, since the Mend CLI appends .json MEND_REPORT: "mend-sast-results" steps: @@ -244,7 +244,7 @@ jobs: path: ${{ env.MEND_REPORT }}.json if-no-files-found: warn - # unlike SCA, SAST fails on a finding of any severity; a missing or malformed report also fails + # unlike SCA, SAST fails on a finding of any severity, and a missing or malformed report also fails - name: Fail on any SAST finding if: always() run: | From 66c19939528aa5da001bee7f6897a0ea69546d31 Mon Sep 17 00:00:00 2001 From: Eric Hare Date: Wed, 28 Oct 2026 10:33:06 -0700 Subject: [PATCH 4/4] ci: keep Mend findings out of public run logs data-api is public, so anyone signed in to GitHub can read its run logs and download its artifacts. Both scans now write the CLI output to a runner temp file, the logs show only finding counts, and no report is uploaded. If the CLI fails, only lines that look like connection or credential errors are printed, never a findings table row. SCA now also updates the Mend platform on pushes to main, not only on release tags, so main's findings have somewhere to live. --- .github/workflows/ibm-mend.yaml | 77 ++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ibm-mend.yaml b/.github/workflows/ibm-mend.yaml index e63534d8b2..8083855d14 100644 --- a/.github/workflows/ibm-mend.yaml +++ b/.github/workflows/ibm-mend.yaml @@ -4,6 +4,10 @@ # * SAST ("mend sast") checks our own source code and fails on any finding # Results land under Products////Astra DB - data-api in the IBM Mend platform. # +# This repo is public, so anyone signed in to GitHub can read its run logs and artifacts. Scan output +# therefore stays in runner temp files, the logs show only finding counts, and no report is uploaded. +# The findings themselves live on the Mend platform. +# # The jobs follow riptano/shared-github-actions mend-sca.yml and mend-sast.yml, which riptano/cloud-billing # calls. We copy their steps instead of calling them, because GitHub does not let a public repository use # reusable workflows that live in an internal one. @@ -15,10 +19,10 @@ name: IBM Mend Scan # runs on -# * pushes to "main" -# * release tags (SCA also updates the project inventory on the Mend platform) -# * pull requests against "main" -# * manual trigger +# * pushes to "main" and release tags, where SCA also updates the project on the Mend platform +# * pull requests against "main", where SCA only reports +# * manual trigger, where SCA only reports +# SAST updates the Mend platform on every run. on: push: branches: [ "main" ] @@ -65,7 +69,6 @@ jobs: MAVEN_OPTS: '-Xmx4g' DS_ARTIFACTORY_USERNAME: ${{ secrets.DS_ARTIFACTORY_USERNAME }} DS_ARTIFACTORY_PASSWORD: ${{ secrets.DS_ARTIFACTORY_PASSWORD }} - MEND_REPORT: "mend-sca-result.json" steps: - name: Check Mend settings @@ -133,31 +136,39 @@ jobs: https://downloads.mend.io/cli/linux_amd64/mend -o "$RUNNER_TEMP/mend" chmod +x "$RUNNER_TEMP/mend" - # release tags update the Mend platform, and every other run only reports. - # pipefail keeps a CLI failure (bad credentials, unresolvable build) from hiding behind tee. + # pushes to "main" and release tags update the Mend platform, and every other run only reports. + # the CLI output names every finding, so it stays in a temp file. If the CLI fails, only lines that + # look like connection or credential errors reach the log, and never a findings table row. - name: Mend dependency scan env: MEND_USER_KEY: ${{ secrets.ASTRA_DB_MEND_USER_KEY }} run: | - set -o pipefail update_args=() - if [[ "$GITHUB_REF" == refs/tags/* ]]; then + if [[ "$GITHUB_EVENT_NAME" == "push" && ( "$GITHUB_REF" == refs/heads/main || "$GITHUB_REF" == refs/tags/* ) ]]; then update_args=(--update) fi + output="$RUNNER_TEMP/mend-sca-output.txt" + status=0 "$RUNNER_TEMP/mend" dep --dir . \ --scope "$MEND_ORGNAME//$MEND_PRODUCTNAME//$MEND_PROJECTNAME - $MEND_REPO" \ - --export-results "$MEND_REPORT" \ --non-interactive \ - "${update_args[@]}" 2>&1 | tee mend-output.txt + "${update_args[@]}" > "$output" 2>&1 || status=$? + if [ "$status" -ne 0 ]; then + echo "::error::Mend CLI failed with exit code $status." + grep -i -E 'unauthori[sz]ed|forbidden|denied|invalid|authenticat|connection|timed out' "$output" \ + | grep -v '^|' | head -n 20 || true + exit "$status" + fi # the Mend CLI exits 0 on findings, so parse its summary line and fail the job on Critical/High. # CVE IDs listed in .github/mend-allowlist.txt (one per line, # for comments) are reviewed - # exceptions and do not count. + # exceptions and do not count. Only the counts reach the log. - name: Fail on Critical/High findings if: always() run: | - [ -f mend-output.txt ] || { echo "::warning::Mend scan output not found."; exit 0; } - summary=$(grep 'Detected .* vulnerabilities' mend-output.txt || true) + output="$RUNNER_TEMP/mend-sca-output.txt" + [ -f "$output" ] || { echo "::warning::Mend scan output not found."; exit 0; } + summary=$(grep 'Detected .* vulnerabilities' "$output" || true) critical=$(echo "$summary" | sed 's/.*(\([0-9]*\) Critical.*/\1/' | grep -E '^[0-9]+$' || echo 0) high=$(echo "$summary" | sed 's/.*(\([0-9]* Critical, \)\([0-9]*\) High.*/\2/' | grep -E '^[0-9]+$' || echo 0) @@ -165,7 +176,7 @@ jobs: if [ -f .github/mend-allowlist.txt ]; then while read -r cve _rest; do case "$cve" in ''|\#*) continue ;; esac - n=$(grep -cE "^\| (CRITICAL|HIGH) .*\| ${cve} " mend-output.txt || true) + n=$(grep -cE "^\| (CRITICAL|HIGH) .*\| ${cve} " "$output" || true) if [ "${n:-0}" -gt 0 ]; then echo "::notice::Accepted finding ${cve} (listed in .github/mend-allowlist.txt)" accepted=$((accepted + n)) @@ -176,18 +187,10 @@ jobs: blocking=$(( ${critical:-0} + ${high:-0} - accepted )) echo "Mend SCA: ${critical:-0} Critical, ${high:-0} High (${accepted} accepted)" | tee -a "$GITHUB_STEP_SUMMARY" if [ "$blocking" -gt 0 ]; then - echo "::error::Mend SCA: ${blocking} blocking Critical/High findings. See the mend-sca-report artifact." + echo "::error::Mend SCA: ${blocking} blocking Critical/High findings. They stay out of this public log, so see the Mend platform or run mend dep locally." exit 1 fi - - name: Upload Mend scan report - if: always() - uses: actions/upload-artifact@v7 - with: - name: mend-sca-report - path: ${{ env.MEND_REPORT }} - if-no-files-found: warn - mend-sast: name: IBM Mend SAST # fork and Dependabot pull requests get no Actions secrets, so the scan could not authenticate, @@ -227,24 +230,26 @@ jobs: https://downloads.mend.io/cli/linux_amd64/mend -o "$RUNNER_TEMP/mend" chmod +x "$RUNNER_TEMP/mend" - # every SAST run uploads to the same Mend project, so the latest scan (PR or main) is what it shows + # every SAST run uploads to the same Mend project, so the latest scan (PR or main) is what it shows. + # the CLI output stays in a temp file, the same way as for SCA. - name: Mend SAST scan env: MEND_USER_KEY: ${{ secrets.ASTRA_DB_MEND_USER_KEY }} run: | + output="$RUNNER_TEMP/mend-sast-output.txt" + status=0 "$RUNNER_TEMP/mend" sast --dir . \ --scope "$MEND_ORGNAME//$MEND_PRODUCTNAME//$MEND_PROJECTNAME - $MEND_REPO" \ - --report --formats json --filename "$MEND_REPORT" - - - name: Upload Mend scan report - if: always() - uses: actions/upload-artifact@v7 - with: - name: mend-sast-report - path: ${{ env.MEND_REPORT }}.json - if-no-files-found: warn + --report --formats json --filename "$MEND_REPORT" > "$output" 2>&1 || status=$? + if [ "$status" -ne 0 ]; then + echo "::error::Mend CLI failed with exit code $status." + grep -i -E 'unauthori[sz]ed|forbidden|denied|invalid|authenticat|connection|timed out' "$output" \ + | grep -v '^|' | head -n 20 || true + exit "$status" + fi - # unlike SCA, SAST fails on a finding of any severity, and a missing or malformed report also fails + # unlike SCA, SAST fails on a finding of any severity, and a missing or malformed report also fails. + # the report stays on the runner, and only its total reaches the log. - name: Fail on any SAST finding if: always() run: | @@ -263,6 +268,6 @@ jobs: ' "$MEND_REPORT.json") echo "Mend SAST total vulnerabilities: $total" | tee -a "$GITHUB_STEP_SUMMARY" if [ "$total" -gt 0 ]; then - echo "::error::Mend SAST found $total vulnerabilities. See the mend-sast-report artifact." + echo "::error::Mend SAST found $total vulnerabilities. They stay out of this public log, so see the Mend platform." exit 1 fi