Skip to content

GODRIVER-3599 Add task and script to generate CycloneDX SBOM #2154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jasonhills-mongodb
Copy link

GODRIVER-3599

Summary

Added a task, etc/script, and pre-commit hook for generating a CycloneDX SBOM using a pinned version of the cyclonedx-gomod tool. The SBOM includes the aggregate of modules required by packages in the mongo-go-driver library, excluding examples, tests and test packages (i.e., only components used at runtime).

The task (generate-sbom) is added to the default tasks and will run only when go.mod is newer than sbom.json.

The pre-commit hook (sbom-currency) ensures that if go.mod is staged for commit, that an updated sbom.json is also staged.

Future TODO: Add libmongocrypt as an optional component once the libmongocrypt SBOM is updated with newer automation

Background & Motivation

The GODRIVER SBOM (sbom.json) does not contain the direct and transitive dependencies defined in go.mod. Added code to generate a CycloneDX SBOM in order to better meet NITA Minimum Elements for Software Bill of Materials, OWASP Software Component Verification Standard (SCVS) Level 1, as well as include the necessary component identifiers for vulnerability discovery and VEX responses.

Copy link
Contributor

API Change Report

No changes found!

The GODRIVER SBOM (sbom.json) does not contain the direct and transitive dependencies defined in go.mod. Added code to generate a CycloneDX SBOM in order to better meet NITA Minimum Elements for Software Bill of Materials, OWASP Software Component Verification Standard (SCVS) Level 1, as well as include the necessary component identifiers for vulnerability discovery and VEX responses.

Added a task, etc/script, and pre-commit hook for generating a CycloneDX SBOM using a pinned version of the cyclonedx-gomod tool. The SBOM includes the aggregate of modules required by packages in the mongo-go-driver library, excluding examples, tests and test packages.

The task (generate-sbom) is added to the default tasks and will run only when go.mod is newer than sbom.cdx.json.

The pre-commit hook (sbom-currency) ensures that if go.mod is staged for commit, that an updated sbom.json is also staged.

Future TODO: Add libmongocrypt as an optional component once the libmongocrypt SBOM is updated with newer automation
@jasonhills-mongodb jasonhills-mongodb force-pushed the GODRIVER-3599/sbom_generation_using_cyclonedx-gomod branch from 7c63b31 to a0af51a Compare August 5, 2025 22:41
@jasonhills-mongodb jasonhills-mongodb marked this pull request as ready for review August 5, 2025 22:41
@jasonhills-mongodb jasonhills-mongodb requested a review from a team as a code owner August 5, 2025 22:41
@prestonvasquez prestonvasquez added the review-priority-low Low Priority PR for Review: within 3 business days label Aug 14, 2025
- id: sbom-currency
name: sbom-currency
language: system
types: [json]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hook won't run if a commit changes go.mod. Is that intentional?

summary: |
Generate a CycloneDX SBOM with the cyclonedx-gomod 'mod' subcommand
The SBOM includes the aggregate of modules required by packages in the mongo-go-driver library, excluding examples, tests and test packages.
Task will run only when go.mod is newer than sbom.cdx.json.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be sbom.json and not sbom.cdx.json?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good catch. That is a typo leftover from when I was naming the file sbom.cdx.json. Will fix.


if ! $CHECK_CURRENCY; then
# The cyclonedx-gomod 'mod' subcommand is used to generate a CycloneDX SBOM with GOWORK=off to exclude example/test code.
# TODO: Add libmongocrypt as an optional component via a merge once the libmongocrypt SBOM is updated with newer automation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a followup GODRIVER ticket?

Co-authored-by: Preston Vasquez <prestonvasquez@icloud.com>
@github-actions github-actions bot added the review-priority-normal Medium Priority PR for Review: within 1 business day label Aug 14, 2025
@prestonvasquez prestonvasquez removed the review-priority-low Low Priority PR for Review: within 3 business days label Aug 15, 2025
done
#shift $((OPTIND - 1))

if ! $CHECK_CURRENCY; then
Copy link
Member

@prestonvasquez prestonvasquez Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this script fail under certain conditions? For example, if it's being (1) called from the Evergreen CI and (2) calling results in a change to sbom.json? In such cases, I would expect the "Static Analysis" task to fail.

Running directly:

EXPECT_ERROR=1 bash etc/generate-sbon.sh # -> if sbom.json updates, exit 1

In the associated task:

  - name: generate-sbom
    tags: ["ssdlc", "static-analysis"]
    commands:
      - command: subprocess.exec
        params:
          binary: bash
          env:
            EXPECT_ERROR: 1
          args: [*task-runner, generate-sbom]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement review-priority-normal Medium Priority PR for Review: within 1 business day
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants