Skip to content

Commit fedbd7f

Browse files
authored
TOOLS-3964: omit the main module from go list for sbom generation (#841)
We fixed this earlier by omitting the `.Module` structs that didn't contain `.Path`, but that was removed by mistake in #810. Rather than add it back and depend on `.Path` being empty, I'm adding a filter to remove the main module. This is indicated in the go list json by `.Main` being set to true in the `.Module` struct.
1 parent a704ee1 commit fedbd7f

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
lines changed

cyclonedx.sbom.json

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -310,19 +310,6 @@
310310
"type": "library",
311311
"version": "v0.0.15"
312312
},
313-
{
314-
"bom-ref": "pkg:golang/github.com/mongodb/mongo-tools",
315-
"externalReferences": [
316-
{
317-
"type": "website",
318-
"url": "https://pkg.go.dev/github.com/mongodb/mongo-tools"
319-
}
320-
],
321-
"group": "github.com/mongodb",
322-
"name": "mongo-tools",
323-
"purl": "pkg:golang/github.com/mongodb/mongo-tools",
324-
"type": "library"
325-
},
326313
{
327314
"bom-ref": "pkg:golang/github.com/montanaflynn/[email protected]",
328315
"externalReferences": [
@@ -813,17 +800,17 @@
813800
"version": "v2.4.0"
814801
},
815802
{
816-
"bom-ref": "pkg:golang/[email protected].12",
803+
"bom-ref": "pkg:golang/[email protected].8",
817804
"externalReferences": [
818805
{
819806
"type": "website",
820-
"url": "https://pkg.go.dev/None/[email protected].12"
807+
"url": "https://pkg.go.dev/None/[email protected].8"
821808
}
822809
],
823810
"name": "std",
824-
"purl": "pkg:golang/[email protected].12",
811+
"purl": "pkg:golang/[email protected].8",
825812
"type": "library",
826-
"version": "go1.23.12"
813+
"version": "go1.23.8"
827814
}
828815
],
829816
"dependencies": [
@@ -863,9 +850,6 @@
863850
{
864851
"ref": "pkg:golang/github.com/mattn/[email protected]"
865852
},
866-
{
867-
"ref": "pkg:golang/github.com/mongodb/mongo-tools"
868-
},
869853
{
870854
"ref": "pkg:golang/github.com/montanaflynn/[email protected]"
871855
},
@@ -927,11 +911,11 @@
927911
"ref": "pkg:golang/gopkg.in/[email protected]"
928912
},
929913
{
930-
"ref": "pkg:golang/[email protected].12"
914+
"ref": "pkg:golang/[email protected].8"
931915
}
932916
],
933917
"metadata": {
934-
"timestamp": "2025-07-18T17:11:37.182995+00:00",
918+
"timestamp": "2025-08-26T21:16:45.957053+00:00",
935919
"tools": [
936920
{
937921
"externalReferences": [
@@ -975,7 +959,7 @@
975959
]
976960
},
977961
"serialNumber": "urn:uuid:ecf433fd-8f8f-476e-bb32-15507acd4361",
978-
"version": 33,
962+
"version": 34,
979963
"$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
980964
"bomFormat": "CycloneDX",
981965
"specVersion": "1.5",

scripts/regenerate-sbom-lite.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ OS_ARCH_COMBOS="$( go run release/release.go print-os-arch-combos )"
1313
# (https://github.com/package-url/purl-spec), one per line. This is used as input for the `silkbomb`
1414
# tool to generate an SBOM. We do this for each OS/architecture combination we support to make sure
1515
# this is the superset of all our dependencies.
16+
# We skip the mongo-tools module in the jq query so that it's not listed as a
17+
# dependency of itself (.Module.Main is set to true for mongo-tools)
1618
#
1719
# shellcheck disable=SC2086 # we intentionally don't quote `$OS_ARCH_COMBOS` so we split on the
1820
# whitespace.
@@ -21,7 +23,7 @@ for c in $OS_ARCH_COMBOS; do
2123
arch="$(echo $c | cut -f2 -d/)"
2224
# shellcheck disable=SC2086 # we don't want to quote `$BINARY_DIRS` for the same reason.
2325
GOOS="$os" GOARCH="$arch" go list -json -mod=mod -deps $BINARY_DIRS |
24-
jq -r '.Module // empty | "pkg:golang/" + .Path + "@" + .Version // empty' >> \
26+
jq -r '.Module // empty | select((.Main // false) == false) | "pkg:golang/" + .Path + "@" + .Version // empty' >> \
2527
purls.txt
2628
done
2729

0 commit comments

Comments
 (0)