A 230-statement VEX file (234 KB) made jq fail with 'Argument list too long' (--argjson of the accumulated array). Each file is now one JSON object in an ndjson file, slurped into the report.
69 lines
3.2 KiB
YAML
69 lines
3.2 KiB
YAML
name: 'VEX statements to dtrack-panel'
|
|
description: >
|
|
Post every OpenVEX / CycloneDX VEX file of a repo (the central VEX repo) to
|
|
dtrack-panel, which applies them as NOT_AFFECTED decisions in
|
|
Dependency-Track: to the images a statement names, or wherever the package
|
|
appears. The repo's complete set each time — a removed file or statement
|
|
withdraws its decisions.
|
|
author: 'janhouse'
|
|
|
|
# Usage (janhouse/vex .gitea/workflows/vex.yml, on push to main + weekly):
|
|
# - uses: actions/checkout@v4
|
|
# - uses: https://git.janhouse.lv/janhouse/sbom-tools-action/[email protected]
|
|
# with:
|
|
# dtrack-url: ${{ secrets.DEPENDENCY_TRACK_URL }}
|
|
# dtrack-api-key: ${{ secrets.DEPENDENCY_TRACK_API_KEY }}
|
|
|
|
inputs:
|
|
dtrack-url:
|
|
description: 'Dependency-Track base URL (the panel answers on <dtrack-url>/panel-ci/)'
|
|
required: true
|
|
dtrack-api-key:
|
|
description: 'Dependency-Track API key that may upload BOMs (authenticates the report)'
|
|
required: true
|
|
panel-url:
|
|
description: 'dtrack-panel VEX URL (default: <dtrack-url>/panel-ci/vex)'
|
|
required: false
|
|
default: ''
|
|
path:
|
|
description: 'Directory to collect *.json VEX files from'
|
|
required: false
|
|
default: 'vex'
|
|
|
|
runs:
|
|
using: 'composite'
|
|
steps:
|
|
- name: Post VEX statements
|
|
shell: bash
|
|
env:
|
|
DTRACK_URL: ${{ inputs.dtrack-url }}
|
|
DTRACK_API_KEY: ${{ inputs.dtrack-api-key }}
|
|
PANEL_URL: ${{ inputs.panel-url }}
|
|
VEX_PATH: ${{ inputs.path }}
|
|
REPO: ${{ github.repository }}
|
|
COMMIT: ${{ github.sha }}
|
|
run: |
|
|
set -euo pipefail
|
|
url=${PANEL_URL:-${DTRACK_URL%/}/panel-ci/vex}
|
|
# One JSON object per file on disk (never as an argument: a big VEX
|
|
# file blows the argv limit), slurped into the report.
|
|
: > vex-files.ndjson
|
|
while IFS= read -r f; do
|
|
jq -n --arg p "$f" --rawfile c "$f" '{path: $p, content: $c}' >> vex-files.ndjson
|
|
done < <(find "$VEX_PATH" -name '*.json' -not -path '*/.git/*' | sort | head -500)
|
|
jq -n --arg repo "$REPO" --arg commit "$COMMIT" --slurpfile files vex-files.ndjson \
|
|
'{repo: $repo, commit: $commit, files: $files}' > vex-report.json
|
|
echo "Posting $(jq '.files | length' vex-report.json) VEX file(s) to ${url}"
|
|
# -f: a rejected file (bad JSON, no justification) fails the job.
|
|
code=$(curl -sS -o response.json -w '%{http_code}' -X POST "$url" \
|
|
-H "X-Api-Key: ${DTRACK_API_KEY}" -H "Content-Type: application/json" \
|
|
--data-binary @vex-report.json)
|
|
if [ "$code" != 200 ]; then
|
|
echo "::error::dtrack-panel answered HTTP $code: $(jq -r '.message // .' response.json 2>/dev/null || cat response.json)"
|
|
exit 1
|
|
fi
|
|
jq -r '.vex | "VEX statements: \(.statements) (\(.added) new, \(.changed) changed, \(.removed) removed)"' response.json
|
|
jq -r '.vex.skipped[]? | "::notice file=\(.path)::\(.id) skipped: \(.why)"' response.json || true
|
|
jq -r '.reviewDue[]? | "::warning::VEX re-check due — \(.vulnId) in \(.package) (\(.image)): \(.detail)"' response.json || true
|
|
jq -r '.expiringSoon[]? | "::notice file=\(.path)::\(.vulnId): review date \(.reviewBy[0:10]) is within 14 days"' response.json || true
|