-
Notifications
You must be signed in to change notification settings - Fork 919
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
jasonhills-mongodb
wants to merge
5
commits into
mongodb:master
Choose a base branch
from
jasonhills-mongodb:GODRIVER-3599/sbom_generation_using_cyclonedx-gomod
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+438
−12
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a0af51a
GODRIVER-3599 Add task script to generate CycloneDX SBOM
jasonhills-mongodb 4e52215
Update .evergreen/config.yml
jasonhills-mongodb 10dd0cc
Merge branch 'master' into GODRIVER-3599/sbom_generation_using_cyclon…
matthewdale 8d5d80f
Use correct file for pre-commit and correct comment in Taskfile.
matthewdale 3aa5972
Add updated SBOM file.
matthewdale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #!/usr/bin/env bash | ||
| set -e | ||
|
|
||
| CHECK_CURRENCY="false" | ||
|
|
||
| # Options are: | ||
| # -c : check currency of staged sbom.json versus go.mod. | ||
| while getopts "c" opt; do | ||
| case $opt in | ||
| c) | ||
| CHECK_CURRENCY="true" | ||
| ;; | ||
| *) | ||
| echo "usage: $0 [-c]" >&2 | ||
| echo " -c : (optional) check currency of staged sbom.json versus go.mod." >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| done | ||
| #shift $((OPTIND - 1)) | ||
|
|
||
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need a followup GODRIVER ticket?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just went ahead and added the |
||
|
|
||
| ## The pipe to jq is a temporary workaround until this issue is resolved: https://github.com/CycloneDX/cyclonedx-gomod/issues/662. | ||
| ## When resolved, bump version and replace with commented line below. | ||
| # GOWORK=off go run github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@[UPDATED VERSION] mod -type library -licenses -assert-licenses -output-version 1.5 -json -output sbom.json . | ||
| GOWORK=off go run github.com/CycloneDX/cyclonedx-gomod/cmd/[email protected] mod -type library -licenses -assert-licenses -output-version 1.5 -json . | jq '.metadata.component.purl |= split("?")[0]' | jq '.components[].purl |= split("?")[0]' > sbom.json | ||
| elif [[ $(git diff --name-only --cached go.mod) && ! $(git diff --name-only --cached sbom.json) ]]; then | ||
| echo "'go.mod' has changed. 'sbom.json' must be re-generated (run 'task generate-sbom' or 'etc/generate-sbom.sh') and staged." && exit 1 | ||
| fi | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 1In the associated task:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. The expected workflow is that upon changing the
go.modfile the contributor will also commit an updatedsbom.json, which is enforced with the pre-commit check. But, this is not guaranteed and if thego.modis newer thansbom.jsonin Evergreen CI, that indicates that the repository files are out-of-sync and the Evergreen "static-analysis" task should fail. I will account for this and strengthen the check with a schema validation step.