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

[feature] Improve CDX parsing #1884

Closed
pxp928 opened this issue Apr 30, 2024 · 5 comments · Fixed by #1903
Closed

[feature] Improve CDX parsing #1884

pxp928 opened this issue Apr 30, 2024 · 5 comments · Fixed by #1903
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@pxp928
Copy link
Collaborator

pxp928 commented Apr 30, 2024

Is your feature request related to a problem? Please describe.
Currently, the CDX parser appends all dependencies to the top level package which may be inaccurate:

https://github.com/guacsec/guac/blob/main/pkg/ingestor/parser/cyclonedx/parser_cyclonedx.go#L243-L262

Instead, this needs to be done based on the relationships defined by the CDX SBOM.

Describe the solution you'd like

This is not based on the relationship so that can be inaccurate (can capture both direct and in-direct).
This needs to be done by utilizing *c.cdxBom.Dependencies 

see CycloneDX/specification#33

Describe alternatives you've considered
None

@pxp928 pxp928 added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Apr 30, 2024
@Yaxhveer
Copy link
Contributor

Yaxhveer commented May 9, 2024

Hey @pxp928, I would like to work on this. Just wanted to ask here how we use the direct dependencies that we get from *c.cdxBom.Dependencies?

@pxp928
Copy link
Collaborator Author

pxp928 commented May 9, 2024

Hey @Yaxhveer!

So c.cdxBom.Dependencies is implemented https://github.com/guacsec/guac/blob/main/pkg/ingestor/parser/cyclonedx/parser_cyclonedx.go#L285-L309 but we are not following the logic set forth by CycloneDX/specification#33 (comment). We want to be able to check if this dependency is direct, in-direct (transitive) or both. It can be both a direct and in-direct dependency in which case there will be two assembler.IsDependencyIngest created for the direct one and the in-direct one. Currently, we are marking them all as unknown: https://github.com/guacsec/guac/blob/main/pkg/ingestor/parser/common/helpers.go#L53

It should be unknown by default, but if you can determine it via the logic provided, it should be specified as Direct or In-direct.

Let me know if you have other questions! Looking forward to the contribution :)

@Yaxhveer
Copy link
Contributor

Hey @pxp928, just a simple doubt here the dependency type is between top level and foundPkg or between foundPkg and DepPkg (in func GetIsDep())

Pkg: foundNode,
DepPkg: rpackNode,
DepPkgMatchFlag: GetMatchFlagsFromPkgInput(rpackNode),
IsDependency: &model.IsDependencyInputSpec{
DependencyType: model.DependencyTypeUnknown,
Justification: justification,
VersionRange: *rpackNode.Version,
},

@pxp928
Copy link
Collaborator Author

pxp928 commented May 10, 2024

Based off this CycloneDX/specification#33 (comment) it can be both. So if c.cdxBom.Dependencies is defined (not null), we should not do this: https://github.com/guacsec/guac/blob/main/pkg/ingestor/parser/cyclonedx/parser_cyclonedx.go#L260 but instead use the relationships defined to create both the top level and foundPkg (direct) and between foundPkg and DepPkg (in-direct) in the function:

for _, deps := range *c.cdxBom.Dependencies {
currPkg, found := c.packagePackages[deps.Ref]
if !found {
continue
}
if reflect.DeepEqual(currPkg, toplevel) {
continue
}
if deps.Dependencies != nil {
for _, depPkg := range *deps.Dependencies {
if depPkg, exist := c.packagePackages[depPkg]; exist {
for _, packNode := range currPkg {
p, err := common.GetIsDep(packNode, depPkg, []*model.PkgInputSpec{}, "CDX BOM Dependency")
if err != nil {
logger.Errorf("error generating CycloneDX edge %v", err)
continue
}
if p != nil {
preds.IsDependency = append(preds.IsDependency, *p)
}
}
}
}
}
}

In that case you will have to remove this lines:

if reflect.DeepEqual(currPkg, toplevel) {
	continue
}

as we dont want to skip.

If c.cdxBom.Dependencies is null then keep doing https://github.com/guacsec/guac/blob/main/pkg/ingestor/parser/cyclonedx/parser_cyclonedx.go#L260 like it is currently.

@Yaxhveer
Copy link
Contributor

Thanks just wanted to confirm that.

@Yaxhveer Yaxhveer mentioned this issue May 10, 2024
3 tasks
@kodiakhq kodiakhq bot closed this as completed in #1903 May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants