trivy-gate and dtrack-sbom composite actions
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
86409a2413
3 files changed
+264
No files matched your search
@@ -0,0 +1,73 @@
|
||||
name: dtrack-sbom
|
||||
description: >
|
||||
Convert a trivy-gate report to CycloneDX and upload it to Dependency-Track.
|
||||
Never fails the job: an SBOM outage must not stop a deploy, it only warns.
|
||||
|
||||
inputs:
|
||||
report:
|
||||
description: Trivy JSON report from trivy-gate (outputs.report).
|
||||
required: true
|
||||
url:
|
||||
description: Dependency-Track base URL.
|
||||
required: true
|
||||
api-key:
|
||||
description: API key with BOM_UPLOAD (+ PROJECT_CREATION_UPLOAD).
|
||||
required: true
|
||||
ca-pem:
|
||||
description: PEM of the CA that signed the Dependency-Track certificate.
|
||||
default: ""
|
||||
project:
|
||||
description: Project name in Dependency-Track.
|
||||
required: true
|
||||
version:
|
||||
description: Project version (use the deployed tag, e.g. latest).
|
||||
required: true
|
||||
extra-components:
|
||||
description: >
|
||||
JSON file with a CycloneDX components array appended to the SBOM
|
||||
(vendored libraries without package metadata).
|
||||
default: ""
|
||||
min-components:
|
||||
description: Refuse to upload a suspiciously small SBOM.
|
||||
default: "5"
|
||||
trivy-image:
|
||||
description: Trivy container image, pinned by digest.
|
||||
default: aquasec/trivy:0.75.0@sha256:af6acf9a6b85dfe389a1941505c0ce9efef52a4719635e1a962f022a3d855daa
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- shell: bash
|
||||
env:
|
||||
REPORT: ${{ inputs.report }}
|
||||
DT_URL: ${{ inputs.url }}
|
||||
DT_KEY: ${{ inputs.api-key }}
|
||||
CA_PEM: ${{ inputs.ca-pem }}
|
||||
PROJECT: ${{ inputs.project }}
|
||||
VERSION: ${{ inputs.version }}
|
||||
EXTRA: ${{ inputs.extra-components }}
|
||||
MIN: ${{ inputs.min-components }}
|
||||
TRIVY: ${{ inputs.trivy-image }}
|
||||
run: |
|
||||
set -uo pipefail
|
||||
warn() { echo "::warning::SBOM $PROJECT/$VERSION: $*"; exit 0; }
|
||||
[ -n "$REPORT" ] && [ -f "$REPORT" ] || warn "no report (gate skipped?)"
|
||||
[ -n "$DT_KEY" ] || warn "no API key"
|
||||
work="${RUNNER_TEMP:-/tmp}/dtrack-sbom"; mkdir -p "$work"
|
||||
docker run -i --rm --entrypoint sh "$TRIVY" -c \
|
||||
'cat >/tmp/r.json && trivy convert --quiet --format cyclonedx /tmp/r.json' \
|
||||
<"$REPORT" >"$work/bom.json" || warn "trivy convert failed"
|
||||
if [ -n "$EXTRA" ]; then
|
||||
jq --slurpfile extra "$EXTRA" '.components += $extra[0]' "$work/bom.json" >"$work/bom2.json" \
|
||||
&& mv "$work/bom2.json" "$work/bom.json" || warn "cannot merge $EXTRA"
|
||||
fi
|
||||
n=$(jq '.components | length' "$work/bom.json") || warn "unreadable SBOM"
|
||||
[ "$n" -ge "$MIN" ] || warn "only $n components, not uploading"
|
||||
ca=()
|
||||
if [ -n "$CA_PEM" ]; then printf '%s\n' "$CA_PEM" >"$work/ca.pem"; ca=(--cacert "$work/ca.pem"); fi
|
||||
code=$(curl -sS "${ca[@]}" -o "$work/resp.json" -w '%{http_code}' \
|
||||
-X POST "$DT_URL/api/v1/bom" -H "X-Api-Key: $DT_KEY" \
|
||||
-F autoCreate=true -F "projectName=$PROJECT" -F "projectVersion=$VERSION" \
|
||||
-F "bom=@$work/bom.json") || code=000
|
||||
[ "$code" = 200 ] || { cat "$work/resp.json" 2>/dev/null; echo; warn "HTTP $code"; }
|
||||
echo "SBOM $PROJECT/$VERSION: $n components uploaded (token $(jq -r .token "$work/resp.json"))"
|
||||
Reference in new issue
Block a user