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

Add format 'cyclonedx' as output format for the graph command #14405

Closed
wants to merge 2 commits into from
Closed

Add format 'cyclonedx' as output format for the graph command #14405

wants to merge 2 commits into from

Conversation

hedtke
Copy link

@hedtke hedtke commented Aug 1, 2023

Changelog: Feature: Add format 'cyclonedx' as output format for the graph command
Docs: https://github.com/conan-io/docs/pull/XXXX

Close #9787

The new output format cyclonedx for the graph command creates a SBOM in CycloneDX JSON 1.4 format to be parsed by dependency management / vulnerability tools like https://www.dependencytrack.org/

  • Refer to the issue that supports this Pull Request.
  • If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
  • I've read the Contributing guide.
  • I've followed the PEP8 style guides for Python code.
  • I've opened another PR in the Conan docs repo to the develop branch, documenting this one.

@CLAassistant
Copy link

CLAassistant commented Aug 1, 2023

CLA assistant check
All committers have signed the CLA.

@hedtke
Copy link
Author

hedtke commented Aug 1, 2023

Hi, this is my first PR. I am not sure whether I work on the correct branches

@hedtke
Copy link
Author

hedtke commented Aug 1, 2023

The resulting JSON can be parsed by dependencytrack. Here is an example:
image

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.

Thanks for your contribution @hedtke

At this moment we are avoiding this kind of specialized formats as built-in, and we are implementing them as extensions in https://github.com/conan-io/conan-extensions (thanks to conan config install it is very easy to use them).

No need to do any changes, we will check this, investigate a bit and discuss the approaches and let you know. Thanks!

@@ -7,3 +7,4 @@ fasteners>=0.15
distro>=1.4.0, <=1.8.0; sys_platform == 'linux' or sys_platform == 'linux2'
Jinja2>=3.0, <4.0.0
python-dateutil>=2.8.0, <3
packageurl-python>=0.10.0
Copy link
Member

Choose a reason for hiding this comment

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

We are avoiding adding new dependencies like this one, unless it is extremely necessary. Every additional Python dependency has proven to be a liability (the state of dependency management in Python is not great), so we prefer to avoid this.

@tsondergaard
Copy link

I hope this PR is approved. Every organization have to deal with SBOM generation and having it built in just makes it easier for all of us.

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.

We have had a look at this, and the main problem is that the full cycloneDX specification is way more complete than the currently proposed one: https://cyclonedx.org/specification/overview/

This means that this is very likely to evolve, and we would like Conan to create a more complete one, and this cannot be implemented in a "formatter", it is too much responsibility for it. Having it in the core as built-in is also problematic for faster evolution.

So my recommendation is to move it to the conan-extensions repository, it fits much better there. There is already a very similar functionality which is the creation of "BuildInfo" (another type of SBOM).

We can discuss there what is the best approach for it, if it is a custom command or a deployer. I'd say try with a custom command first. We also need to think about the "Location" where a potential new command like this belongs, the command naming too, etc.

result["graph"].serialize() # fills ids
deps = result["graph"].nodes[1:] # first node is app itself
cyclonedx = {
"bomFormat": "CycloneDX",

Choose a reason for hiding this comment

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

would you add the schema to the json, so its more clear how to validate the result?

  "$schema": "http://cyclonedx.org/schema/bom-1.4.schema.json",

"name": n.name,
"version": n.conanfile.version,
"supplier": {
"url": [n.conanfile.homepage]

Choose a reason for hiding this comment

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

homepage - why not externalReferences of type website?
see https://cyclonedx.org/use-cases/#external-references

Copy link
Author

Choose a reason for hiding this comment

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

What is the advantage of using that over supplier? external references are not part of the BOM: https://cyclonedx.org/docs/1.4/json/#components_items_supplier VS https://cyclonedx.org/docs/1.4/json/#components_items_externalReferences

Copy link

@jkowalleck jkowalleck Aug 3, 2023

Choose a reason for hiding this comment

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

What is the advantage of using that over supplier

It's a matter of correctness.
One is the URL to the homepage of a supplier(or contractor, legal proxy, etc),
the other is the URL to the homepage of the component/project.

From what I've seen, n.conanfile.homepage contains the project's homepage, not the homepage of an author or supplier.
see https://docs.conan.io/2/reference/conanfile/attributes.html?highlight=homepage#homepage

I found that n.conanfile.url could be the externalReference of type vcs
see https://docs.conan.io/2/reference/conanfile/attributes.html?highlight=url#url

Linking a component's metadata and URLs via externalReferences is the intended way.
see the many examples here: https://cyclonedx.org/use-cases/

Copy link
Author

Choose a reason for hiding this comment

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

conanfile.url points to the GitHub repo of conan-center. Not sure that is useful in this case.

I will use the homepage attribute and move it to externalReferences

@@ -229,6 +231,29 @@ def serialize(self):
result["test"] = self.test
return result

def package_url(self):
"""
Creates a PURL following https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Do you want me to change the comment, or is there an error in how I build the JSON?

Choose a reason for hiding this comment

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

wanted to put a more precise link here, so nobody needs to scroll trough the whole document.

"bomFormat": "CycloneDX",
"specVersion": "1.4",
"version": 1,
"dependencies": [n.id for n in deps],

Choose a reason for hiding this comment

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

This code looks wrong, according to CycloneDX spec.
Could you provide an example SBOM generated with your code, so we can check if the JSON results is actually valid according to http://cyclonedx.org/schema/bom-1.4.schema.json

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, that is not correct. I will fix it in the conan extension

@memsharded
Copy link
Member

@hedtke it seems the review from @jkowalleck is also supporting our conclusions above: this would be better as an "extension" where all these matters are way easier to fix and evolve.

@hedtke
Copy link
Author

hedtke commented Aug 3, 2023

Here is the "extension" version: conan-io/conan-extensions#66

@memsharded
Copy link
Member

Ok, thanks very much, lets follow up everyone in the extensions repo: conan-io/conan-extensions#66

@memsharded memsharded closed this Aug 4, 2023
@hedtke hedtke deleted the freature/cyclonedx-sbom branch August 28, 2023 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature] Add support for CycloneDX output to the info command
5 participants