Skip to content
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

feat: add "sbom" command that produces a CycloneDX 1.4 JSON SBOM #3983

Closed
wants to merge 1 commit into from

Conversation

candrews
Copy link
Contributor

@candrews candrews commented Oct 1, 2022

What does this PR do?

Adds a new command, sbom, that produces an SBOM in the CycloneDX JSON 1.4 format.

By default, sbom will just list the dependency files and the count of the dependencies each contains, for example:

$ npx . sbom --target-dir /home/candrews/projects/test --fail-fast --all-projects
../test/build.gradle: Found 177 gradle dependencies
../test/frontend/yarn.lock: Found 111 yarn dependencies

Passing the --cyclonedx-json option will output CycloneDX 1.4 JSON to stdout:

$ npx . sbom --target-dir /home/candrews/projects/test --all-projects --fail-fast --cyclonedx-json

Passing the --cyclonedx-json-file-output=<file> option will output CycloneDX 1.4 JSON to the given file:

$ npx . sbom --target-dir /home/candrews/projects/test --all-projects --fail-fast --cyclonedx-json-file-output=bom.json

The SBOM includes the dependencies (in the "components" section) and the dependency graph (in the "dependencies" section).

See: https://cyclonedx.org/

This feature facilitates compliance with the May 21, 2021 Executive Order on Improving the Nation’s Cybersecurity . It also bring Snyk CLI into alignment with the industry move towards SBOMs, of which Snyk itself has stressed the importance.

Where should the reviewer start?

I suggest looking at the new sbom command's implementation.

How should this be manually tested?

  • snyk sbom --target-dir <project>
  • snyk sbom --target-dir <project> --cyclonedx-json
  • snyk sbom --target-dir <project> --cyclonedx-json-file-output=bom.json

As well as the other options as documented.

Any background context you want to provide?

The CycloneDX JSON file is constructed using https://www.npmjs.com/package/%40cyclonedx/cyclonedx-library

What are the relevant tickets?

Closes: https://github.com/snyk/cli/issues/3862

Screenshots

Additional questions

@candrews
Copy link
Contributor Author

candrews commented Oct 5, 2022

During our call on Monday, October 1, Snyk expressed interest in having the SBOM generation command be "snyk sbom" instead of "snyk deps" . I personally like "snyk deps" more, but I'd also be happy with any name :) Therefore, I've updated ths pull request with a commit that just changes the command name from "deps" to "sbom" with no other changes.

@candrews candrews changed the title feat: add "deps" command that produces a CycloneDX 1.4 JSON SBOM feat: add "sbom" command that produces a CycloneDX 1.4 JSON SBOM Oct 5, 2022
@candrews candrews requested a review from a team as a code owner October 13, 2022 23:41
@jkowalleck
Copy link

jkowalleck commented Oct 23, 2022

hello everyone,

if the upgrade to TypeScript 4.8 (via #3875) was an issue,
i could imagine the https://www.npmjs.com/package/%40cyclonedx/cyclonedx-library could be modified to render inter-compatible type-definition files, instead of abusing its own TS-sources for this purpose :-)
if you feel like this could be helpful, feel free to open an issue here: https://github.com/CycloneDX/cyclonedx-javascript-library/issues

@candrews
Copy link
Contributor Author

Regardless of what Snyk does with this request, I think it would be greatly beneficial to users of the CycloneDX library to publish these compatible type definitions to enhance its utility for other projects so I opened the issue at CycloneDX/cyclonedx-javascript-library#291

@candrews
Copy link
Contributor Author

Snyk itself advises keeping dependencies up to date. So regardless of what Snyk wants to do with this request, I hope they will upgrade their Typescript dependency. I'm more than happy to work with Snyk to do with upgrade at #3875 if they would work with me.

"node": ">=14.0.0"
},
"optionalDependencies": {
"xmlbuilder2": "^3.0.2"
Copy link

@jkowalleck jkowalleck Oct 25, 2022

Choose a reason for hiding this comment

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

this is an optional depedency, that causes transitive dependnecies to install.
if you do not serialize to XML, then you could omit this optional dependency when adding @cyclonedx/cyclonedx-library as a dependency. see https://docs.npmjs.com/cli/v8/commands/npm-install#omit

from this PR it appears that the XML functionality is not used.

see https://github.com/snyk/cli/pull/3983/files#r1004859860

bomRef: `${targetFile}:${packageURL}`,
},
);
// The "snyk" property namespace has been reserved: https://github.com/CycloneDX/cyclonedx-property-taxonomy

Choose a reason for hiding this comment

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

👍

@@ -19741,6 +19804,35 @@
"node": ">=4.0"
}
},
"node_modules/xmlbuilder2": {

Choose a reason for hiding this comment

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

@CLAassistant
Copy link

CLAassistant commented Apr 14, 2023

CLA assistant check
All committers have signed the CLA.

The SBOM includes the dependencies and the dependency graph.

The SBOM is generated entirely client side; it does not communicate with the Snyk server/API.

See: https://cyclonedx.org/
Closes: https://github.com/snyk/cli/issues/3862
Signed-off-by: Craig Andrews <candrews@integralblue.com>
@bastiandoetsch
Copy link
Contributor

Hi Craig,

we really appreciate the contribution. Unfortunately, it diverges a bit from our product vision and therefore we decided to close this PR.

Thanks again,
Bastian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate SBOM
4 participants