Files
ci-actions/dtrack-sbom/action.yml
T
tthandClaude Opus 5.5 7fae1fa2f6 trivy-gate: fs scans of lockfiles, checksum-verified binary when no Docker
dtrack-sbom converts with the same runtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 18:54:03 +01:00

84 lines
3.6 KiB
YAML

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"
# Same runtime as trivy-gate: its container when a Docker daemon is
# reachable, else the checksum-verified binary trivy-gate fetched.
gate_bin="${RUNNER_TEMP:-/tmp}/trivy-gate/bin/trivy"
if command -v docker >/dev/null && docker info >/dev/null 2>&1; then
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"
elif [ -x "$gate_bin" ]; then
"$gate_bin" convert --quiet --format cyclonedx "$REPORT" >"$work/bom.json" || warn "trivy convert failed"
else
warn "neither Docker nor the trivy-gate binary available"
fi
if [ -n "$EXTRA" ]; then
jq --slurpfile extra "$EXTRA" '.components += $extra[0]' "$work/bom.json" >"$work/bom2.json" \
|| warn "cannot merge $EXTRA"
mv "$work/bom2.json" "$work/bom.json"
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"))"