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

Make spdx SBOMs readable by trivy scanner #1038

Merged
merged 7 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Build/IntrospectGolang.pm
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ sub buildinfo {
my ($fh) = @_;
my ($vers, $mod) = rawbuildinfo($fh);
return undef unless defined $vers;
$vers =~ s/^go(.*)/\1/;

josegomezr marked this conversation as resolved.
Show resolved Hide resolved
josegomezr marked this conversation as resolved.
Show resolved Hide resolved
my $buildinfo = { 'goversion' => $vers };
my $lastmod;
for my $l (split("\n", $mod || '')) {
Expand Down
23 changes: 21 additions & 2 deletions generate_sbom
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,13 @@ sub spdx_encode_pkg {
}
$spdx->{'copyrightText'} = $p->{'COPYRIGHTTEXT'} ? $p->{'COPYRIGHTTEXT'} : 'NOASSERTION';
$spdx->{'homepage'} = $p->{'URL'} if $p->{'URL'};
my $purlurl = gen_purl($p, $distro, $pkgtype);
push @{$spdx->{'externalRefs'}}, { 'referenceCategory' => 'PACKAGE-MANAGER', 'referenceType' => 'purl', 'referenceLocator', $purlurl } if $purlurl;

# Let the caller control the presence of external refs
if($p->{'external_refs'} // 1) {
my $purlurl = gen_purl($p, $distro, $pkgtype);
push @{$spdx->{'externalRefs'}}, { 'referenceCategory' => 'PACKAGE-MANAGER', 'referenceType' => 'purl', 'referenceLocator', $purlurl } if $purlurl;
}

if (!$p->{'spdx_id'}) {
my $spdxtype = "Package-$pkgtype";
$spdxtype = "Package-go-module" if $pkgtype eq 'golang';
Expand Down Expand Up @@ -935,6 +940,17 @@ sub spdx_encode_header {
return $spdx;
}

sub spdx_encode_dist {
my ($dist) = @_;

return spdx_encode_pkg({
NAME => $dist->{id},
VERSION => $dist->{version_id},
spdx_id => sprintf('SPDXRef-OperatingSystem-%s', gen_pkg_id($dist)),
external_refs => 0
}, undef, undef, {});

josegomezr marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

I think it's more clean to not call spdx_encode_pkg but just do the stuff we need for the operating system entry here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even if the filesystem entry is reflected exactly as a package inside the OS?

}

##################################################################################################
#
Expand Down Expand Up @@ -1170,6 +1186,9 @@ if ($format eq 'spdx') {
push @{$doc->{'files'}}, spdx_encode_file($f);
}
}

push @{$doc->{'packages'}}, spdx_encode_dist($dist);

for (sort keys %unknown_spdx_licenses) {
push @{$doc->{'hasExtractedLicensingInfos'}}, spdx_encode_extracted_license($unknown_spdx_licenses{$_});
}
Expand Down