4
0
Эх сурвалжийг харах

feat: publish a CycloneDX and SPDX SBOM with every release

All archives, packages and the MSI ship the same Go binary and webui
bundle, so one release SBOM covers them. Go modules come from the built
binary's buildinfo (not service/go.mod, which carries golangci-lint tool
deps), and npm runtime deps from frontend/package-lock.json, which the
minified webui bundle would otherwise hide from scanners. Container
images keep their existing BuildKit SBOM attestations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jamesread 1 өдөр өмнө
parent
commit
8b65f844f5

+ 6 - 0
.github/workflows/build-and-release.yml

@@ -22,6 +22,7 @@ on:
       - 'var/entities/**'
       - 'var/entities/**'
       - 'var/helper-actions/**'
       - 'var/helper-actions/**'
       - 'var/macos/**'
       - 'var/macos/**'
+      - 'var/sbom/**'
       - 'var/windows/**'
       - 'var/windows/**'
   workflow_dispatch:
   workflow_dispatch:
   push:
   push:
@@ -50,6 +51,7 @@ on:
       - 'var/entities/**'
       - 'var/entities/**'
       - 'var/helper-actions/**'
       - 'var/helper-actions/**'
       - 'var/macos/**'
       - 'var/macos/**'
+      - 'var/sbom/**'
       - 'var/windows/**'
       - 'var/windows/**'
 
 
 permissions:
 permissions:
@@ -159,6 +161,10 @@ jobs:
         with:
         with:
           install-only: true
           install-only: true
 
 
+      - name: Install syft (release SBOM, var/sbom/generate.sh)
+        if: env.WILL_PUBLISH == 'true'
+        uses: anchore/sbom-action/download-syft@v0
+
       - name: Set up Docker Buildx
       - name: Set up Docker Buildx
         if: env.WILL_PUBLISH == 'true'
         if: env.WILL_PUBLISH == 'true'
         uses: docker/setup-buildx-action@v4
         uses: docker/setup-buildx-action@v4

+ 13 - 0
.goreleaser.yml

@@ -58,6 +58,19 @@ checksum:
     - default
     - default
     - openrc
     - openrc
 
 
+# One SBOM per release covers every archive, package and MSI (same Go binary + webui).
+# See var/sbom/generate.sh. Container images get BuildKit SBOM attestations (dockers_v2 sbom: true).
+sboms:
+  # id must be in release.ids and checksum.ids, otherwise those filters drop the SBOM files.
+  - id: default
+    artifacts: any
+    cmd: ../var/sbom/generate.sh
+    args:
+      - "{{ .Version }}"
+    documents:
+      - "{{ .ProjectName }}-{{ .Version }}-sbom.cdx.json"
+      - "{{ .ProjectName }}-{{ .Version }}-sbom.spdx.json"
+
 snapshot:
 snapshot:
   version_template: "{{ .Branch }}-{{ .ShortCommit }}"
   version_template: "{{ .Branch }}-{{ .ShortCommit }}"
 changelog:
 changelog:

+ 1 - 0
docs/modules/dev/nav.adoc

@@ -1,2 +1,3 @@
 * xref:index.adoc[Index]
 * xref:index.adoc[Index]
 * xref:signing.adoc[Signing]
 * xref:signing.adoc[Signing]
+* xref:sbom.adoc[SBOMs]

+ 37 - 0
docs/modules/dev/pages/sbom.adoc

@@ -0,0 +1,37 @@
+= Software Bills of Materials (SBOMs)
+
+Every OliveTin release publishes SBOMs so you can see exactly which third-party components ship in it.
+
+== Release SBOM
+
+Each GitHub release has two release assets, both describing the same contents:
+
+* `OliveTin-<version>-sbom.cdx.json` - CycloneDX JSON
+* `OliveTin-<version>-sbom.spdx.json` - SPDX JSON
+
+One SBOM covers every archive, `.deb`, `.rpm`, `.apk` and MSI in the release, because they all contain the same two things:
+
+* *The OliveTin service binary.* Go modules are read from the built binary's build info, so the list only includes modules that are actually compiled in. Build tools such as golangci-lint are left out.
+* *The web UI.* The npm runtime dependencies come from `frontend/package-lock.json`. Development dependencies such as Vite and ESLint are left out.
+
+The SBOM is generated by `var/sbom/generate.sh`, which GoReleaser runs during the release.
+
+== Container image SBOMs
+
+Container images get their SBOM as a BuildKit attestation, one for each platform (`linux/amd64`, `linux/arm64`). It covers the Fedora base image packages as well as the OliveTin binary. To view it:
+
+[source,shell]
+----
+docker buildx imagetools inspect ghcr.io/olivetin/olivetin:<version> --format '{{ json .SBOM }}'
+----
+
+NOTE: The image attestation does not list the web UI's npm dependencies, because the image only contains the minified bundle. Use the release SBOM for those.
+
+== Scanning for vulnerabilities
+
+Any SBOM-aware scanner can read these files, for example:
+
+[source,shell]
+----
+grype sbom:OliveTin-<version>-sbom.cdx.json
+----

+ 55 - 0
var/sbom/generate.sh

@@ -0,0 +1,55 @@
+#!/usr/bin/env bash
+# Generate the per-release SBOM (CycloneDX + SPDX) for OliveTin.
+#
+# Called by GoReleaser (sboms, artifacts: any) with the working directory set to dist/.
+# Usage: generate.sh <version> [dist-dir]
+#
+# One SBOM covers every archive/package/MSI because they all ship the same two things:
+#   - the Go service binary: modules are read from its buildinfo, NOT from service/go.mod
+#     (go.mod also carries tool deps like golangci-lint that are never linked);
+#   - the webui bundle: npm runtime deps from frontend/package-lock.json (dev deps excluded).
+# Container images get their own per-platform SBOM attestations from BuildKit (dockers_v2 sbom: true).
+set -euo pipefail
+
+VERSION="${1:?version is required}"
+DIST_DIR="$(cd "${2:-.}" && pwd)"
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
+
+# linux/amd64 is the reference: its module set is a superset of the other targets
+# (darwin/windows only drop the Linux-only github.com/prometheus/procfs).
+BINARY="${DIST_DIR}/OliveTin_linux_amd64_v1/OliveTin"
+OUT="${DIST_DIR}/OliveTin-${VERSION}-sbom"
+
+command -v syft >/dev/null || { echo "syft is required to generate SBOMs" >&2; exit 1; }
+command -v jq >/dev/null || { echo "jq is required to check SBOMs" >&2; exit 1; }
+[[ -f "${BINARY}" ]] || { echo "Reference binary not found: ${BINARY}" >&2; exit 1; }
+
+STAGE="$(mktemp -d)"
+trap 'rm -rf "${STAGE}"' EXIT
+
+mkdir -p "${STAGE}/bin" "${STAGE}/webui"
+cp "${BINARY}" "${STAGE}/bin/OliveTin"
+cp "${REPO_ROOT}/frontend/package.json" "${REPO_ROOT}/frontend/package-lock.json" "${STAGE}/webui/"
+
+SYFT_JAVASCRIPT_INCLUDE_DEV_DEPENDENCIES=false syft scan "dir:${STAGE}" \
+  --source-name OliveTin \
+  --source-version "${VERSION}" \
+  -o "cyclonedx-json=${OUT}.cdx.json" \
+  -o "spdx-json=${OUT}.spdx.json"
+
+# Sanity checks: catch a scan that picked up go.mod/dev deps or missed a whole ecosystem.
+names="$(jq -r '.components[].name' "${OUT}.cdx.json")"
+
+for required in github.com/expr-lang/expr @connectrpc/connect; do
+  grep -qxF "${required}" <<<"${names}" || { echo "SBOM is missing expected component: ${required}" >&2; exit 1; }
+done
+
+for forbidden in github.com/golangci/golangci-lint/v2 vite eslint; do
+  if grep -qxF "${forbidden}" <<<"${names}"; then
+    echo "SBOM contains a build/dev-only component: ${forbidden}" >&2
+    exit 1
+  fi
+done
+
+echo "SBOM written: ${OUT}.cdx.json ($(wc -l <<<"${names}") components), ${OUT}.spdx.json"