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

sbom tool cycloneDX #3959

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

sbom tool cycloneDX #3959

wants to merge 2 commits into from

Conversation

ErniGH
Copy link
Contributor

@ErniGH ErniGH commented Jan 23, 2025

Copy link
Member

@memsharded memsharded left a comment

Choose a reason for hiding this comment

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

It is looking good, a couple of small additions:

  • Adding the conanfile.subgraph docs somewhere, as experimental too
  • Adding a small example with a hook using the .subgraph.serialize() to serialize the conan graph.json. It can be done also to put it inside the binary package metadata folder in the same way as the cyclonedx. It can be a parallel section to the CycloneDX one, called Conan
  • Remind somewhere that the contents of the files are also subject to modifications and evolution, they might change in future version

json.dump(sbom_cyclonedx_1_4, f, indent=4)
ConanOutput().success(f"CYCLONEDX CREATED - {conanfile.generators_folder}")


Copy link
Member

Choose a reason for hiding this comment

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

Lets add a small reference section for the cyclonedx_1_4() function.

Let's look at two examples:

In the first one, we have the case where we want to generate the SBOM at the moment we create our app, after the
package method. This is very useful for keeping track of the components and dependencies of our software.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
package method. This is very useful for keeping track of the components and dependencies of our software.
package method. This is very useful for keeping track of the components and dependencies of that went into building our software.

import os
from conan.api.output import ConanOutput
from conan.tools.sbom.cyclonedx import cyclonedx_1_4
def post_package(conanfile):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def post_package(conanfile):
def post_package(conanfile, **kwargs):

Most hook examples should have this so that in the future we can more easily update their signature if it's ever needed

import os
from conan.api.output import ConanOutput
from conan.tools.sbom.cyclonedx import cyclonedx_1_4
def post_generate(conanfile):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def post_generate(conanfile):
def post_generate(conanfile, **kwargs):

os.mkdir(os.path.join(generators_folder, "sbom"))
with open(os.path.join(generators_folder, "sbom", file_name), 'w') as f:
json.dump(sbom_cyclonedx_1_4, f, indent=4)
ConanOutput().success(f"CYCLONEDX CREATED - {conanfile.generators_folder}")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a comment that both hooks are outputting their sbom in different places?

import json
import os
from conan.api.output import ConanOutput
def post_package(conanfile):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def post_package(conanfile):
def post_package(conanfile, **kwargs):


Instead of using a standard, we can take a Conan-based approach. Thanks to the ``conanfile.subgraph.serialize()``
function, we can directly obtain information about the dependencies of our program.
In the following example, we can see a hook that generates this simplified SBOM.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
In the following example, we can see a hook that generates this simplified SBOM.
In the following example, we can see a hook that generates a simplified SBOM
consisting of the serialization of the subgraph, which includes all data Conan has
about the specific dependencies.

or something like this, as I don't think either method is too documented right now

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.

4 participants