Skip to content

Commit

Permalink
🧹 support origin package information sbom
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-rock committed Mar 13, 2024
1 parent 00f3bbb commit 3ebede0
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 38 deletions.
4 changes: 3 additions & 1 deletion sbom/report_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ type BomAsset struct {
type BomPackage struct {
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
Origin string `json:"origin,omitempty"`
Arch string `json:"arch,omitempty"`
Format string `json:"format,omitempty"`
Purl string `json:"purl,omitempty"`
CPEs []string `json:"cpes.map,omitempty"`
// used by python packages
// deprecated: remove once python.packages uses files
FilePath string `json:"file.path,omitempty"`
// used by os packages
FilePaths []string `json:"files.map,omitempty"`
Format string `json:"format,omitempty"`
}

type BomReport struct {
Expand Down
12 changes: 7 additions & 5 deletions sbom/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ func GenerateBom(r *ReportCollectionJson) ([]Sbom, error) {
if rb.Packages != nil {
for _, pkg := range rb.Packages {
bomPkg := &Package{
Name: pkg.Name,
Version: pkg.Version,
Purl: pkg.Purl,
Cpes: pkg.CPEs,
Type: pkg.Format,
Name: pkg.Name,
Version: pkg.Version,
Architecture: pkg.Arch,
Origin: pkg.Origin,
Purl: pkg.Purl,
Cpes: pkg.CPEs,
Type: pkg.Format,
}

for _, filepath := range pkg.FilePaths {
Expand Down
2 changes: 1 addition & 1 deletion sbom/sbom.mql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ packs:
mql: asset { name platform version arch ids labels cpes.map(uri) }
- uid: mondoo-sbom-packages
title: Retrieve list of installed packages
mql: packages { name version purl cpes.map(uri) format files.map(path) }
mql: packages { name version purl cpes.map(uri) arch origin format files.map(path) }
- uid: mondoo-sbom-python-packages
title: Retrieve list of installed Python packages
mql: python.packages { name version purl cpes.map(uri) file.path }
Expand Down
73 changes: 42 additions & 31 deletions sbom/sbom.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions sbom/sbom.proto
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ message Package {
// 'evidence_list' is a collection of evidence that supports the presence of
// the package in the asset. This evidence could include eg. file paths
repeated Evidence evidence_list = 21;
// Package Origin (e.g. other package name, or source of the package)
string origin = 22;
}

enum EvidenceType {
Expand Down
5 changes: 5 additions & 0 deletions sbom/textlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ func (s *TextList) Render(w io.Writer, bom *Sbom) error {
sb.WriteString(" ")
sb.WriteString(pkg.Architecture)
}
if pkg.Origin != "" {
sb.WriteString(" (origin:")
sb.WriteString(pkg.Origin)
sb.WriteString(")")
}

// we only print the location if it is not empty
// this approach is deprecated and we should remove that once everything moved to evidence
Expand Down

0 comments on commit 3ebede0

Please sign in to comment.