From 5f725d98e64b1619a1f85cb7d6c3a3f70b704efc Mon Sep 17 00:00:00 2001 From: npu Date: Sat, 14 Nov 2026 21:48:32 +0200 Subject: [PATCH] Fail the gate on incomplete scans Add fail-on-incomplete (default true) and the gate-incomplete output from data.gate.incomplete; list data.truncated packages in the job summary. A response without the field counts as complete. Add a fixture CI job. --- .github/workflows/ci.yml | 43 +++++++++++++++++++++++++++++++++++++++ README.md | 2 ++ action.yml | 16 +++++++++++++++ test/scan-incomplete.json | 9 ++++++++ 4 files changed, 70 insertions(+) create mode 100644 test/scan-incomplete.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 86672ab..bc31385 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,3 +38,46 @@ jobs: upload-sarif: ${{ github.event_name != 'pull_request' }} - if: steps.key.outputs.present == 'true' run: test "${{ steps.radar.outputs.gate-tripped }}" = false + + # Runs the action against a local stub that replays a fixture response. + fixture: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - run: | + python3 - <<'PY' & + from http.server import BaseHTTPRequestHandler, HTTPServer + body = open("test/scan-incomplete.json", "rb").read() + class H(BaseHTTPRequestHandler): + def do_POST(self): + self.rfile.read(int(self.headers["Content-Length"])) + self.send_response(200) + self.send_header("Content-Type", "application/json") + self.end_headers() + self.wfile.write(body) + HTTPServer(("127.0.0.1", 8080), H).serve_forever() + PY + until curl -s -o /dev/null http://127.0.0.1:8080; do sleep 0.2; done + - id: radar + continue-on-error: true + uses: ./ + with: + api-key: test + file: test/package-lock.json + fail-on: high + upload-sarif: false + api-url: http://127.0.0.1:8080 + - id: tolerant + uses: ./ + with: + api-key: test + file: test/package-lock.json + fail-on: high + fail-on-incomplete: false + upload-sarif: false + api-url: http://127.0.0.1:8080 + - run: | + test "${{ steps.radar.outcome }}" = failure + test "${{ steps.radar.outputs.gate-tripped }}" = false + test "${{ steps.radar.outputs.gate-incomplete }}" = true + test "${{ steps.tolerant.outputs.gate-incomplete }}" = true diff --git a/README.md b/README.md index fbb3118..cf0948c 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ Get an API key in [Console → Settings](https://radar.offseq.com/console) and s | `api-key` | – | Radar API key. Required. | | `file` | – | SBOM or lockfile to scan. Required. | | `fail-on` | empty | `critical`, `high`, `medium`, `low`, `kev` or `exploited`. Only version-confirmed findings count. Empty never fails. | +| `fail-on-incomplete` | `true` | Fail when the gate could not evaluate every package, e.g. over the server's candidate cap. The job summary lists the packages. | | `upload-sarif` | `true` | Upload SARIF to code scanning. Needs `security-events: write`. | | `api-url` | `https://radar.offseq.com` | Radar base URL. | @@ -49,6 +50,7 @@ Get an API key in [Console → Settings](https://radar.offseq.com/console) and s | Output | | |---|---| | `gate-tripped` | `true` when `fail-on` matched. | +| `gate-incomplete` | `true` when the gate could not evaluate every package. | | `sarif-file` | Path of the SARIF report. | ## Supported files diff --git a/action.yml b/action.yml index fd23903..3d4f98e 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,10 @@ inputs: description: Fail the job on a confirmed finding at this level - critical, high, medium, low, kev or exploited. Empty never fails. required: false default: '' + fail-on-incomplete: + description: Fail the job when the gate could not evaluate every package, so an incomplete scan never passes. + required: false + default: 'true' upload-sarif: description: Upload the SARIF report to GitHub code scanning (needs security-events write permission). required: false @@ -29,6 +33,9 @@ outputs: gate-tripped: description: '"true" when fail-on matched a confirmed finding.' value: ${{ steps.scan.outputs.gate-tripped }} + gate-incomplete: + description: '"true" when the gate could not evaluate every package.' + value: ${{ steps.scan.outputs.gate-incomplete }} sarif-file: description: Path of the SARIF report, when upload-sarif is true. value: ${{ steps.scan.outputs.sarif-file }} @@ -63,7 +70,10 @@ runs: fi jq -r '.markdown' "$out" >> "$GITHUB_STEP_SUMMARY" + jq -r '(.data.truncated // []) as $t | select($t | length > 0) | + "\n**Incomplete:** \($t | length) package(s) not fully evaluated: \($t | map("`\(.purl)` (\(.reason))") | join(", "))."' "$out" >> "$GITHUB_STEP_SUMMARY" echo "gate-tripped=$(jq -r '.data.gate.tripped == true' "$out")" >> "$GITHUB_OUTPUT" + echo "gate-incomplete=$(jq -r '.data.gate.incomplete == true' "$out")" >> "$GITHUB_OUTPUT" if [ "$RADAR_UPLOAD" = true ]; then jq '.sarif' "$out" > "$RUNNER_TEMP/radar.sarif" @@ -83,3 +93,9 @@ runs: run: | echo "::error::OffSeq Radar found a confirmed $RADAR_FAIL_ON finding. See the job summary." exit 1 + + - if: steps.scan.outputs.gate-incomplete == 'true' && inputs.fail-on-incomplete == 'true' + shell: bash + run: | + echo "::error::OffSeq Radar could not evaluate every package, so the gate is incomplete. See the job summary." + exit 1 diff --git a/test/scan-incomplete.json b/test/scan-incomplete.json new file mode 100644 index 0000000..9997a1f --- /dev/null +++ b/test/scan-incomplete.json @@ -0,0 +1,9 @@ +{ + "markdown": "## OffSeq Radar\n\nNo confirmed findings.\n", + "sarif": { "version": "2.1.0", "runs": [] }, + "summary": { "truncated": 1 }, + "data": { + "gate": { "tripped": false, "incomplete": true }, + "truncated": [{ "purl": "pkg:npm/lodash@4.17.21", "reason": "candidate-cap" }] + } +}