Skip to content

Commit

Permalink
fix: correct apk purls for other distros (#1620)
Browse files Browse the repository at this point in the history
The apk purl spec allows for vendor-specific namespace.  I noticed
in the embedded SBOMs from wolfi that the purls are of the form
`pkg:apk/wolfi/curl@7.83.0-r0?arch=x86`, but the current logic in
syft actually prevents purl generation entirely if the distro isn't
alpine, so this corrects that behaviour.

Signed-off-by: Weston Steimel <weston.steimel@anchore.com>
  • Loading branch information
westonsteimel committed Feb 24, 2023
1 parent 0c5f032 commit 3ee1af0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
5 changes: 2 additions & 3 deletions syft/pkg/cataloger/apkdb/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ func newPackage(d pkg.ApkMetadata, release *linux.Release, locations ...source.L

// packageURL returns the PURL for the specific Alpine package (see https://github.com/package-url/purl-spec)
func packageURL(m pkg.ApkMetadata, distro *linux.Release) string {
if distro == nil || distro.ID != "alpine" {
// note: there is no namespace variation (like with debian ID_LIKE for ubuntu ID, for example)
if distro == nil {
return ""
}

Expand All @@ -44,7 +43,7 @@ func packageURL(m pkg.ApkMetadata, distro *linux.Release) string {

return packageurl.NewPackageURL(
packageurl.TypeAlpine,
"alpine",
strings.ToLower(distro.ID),
m.Package,
m.Version,
pkg.PURLQualifiers(
Expand Down
17 changes: 15 additions & 2 deletions syft/pkg/cataloger/apkdb/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Test_PackageURL(t *testing.T) {
expected string
}{
{
name: "bad distro",
name: "non-alpine distro",
metadata: pkg.ApkMetadata{
Package: "p",
Version: "v",
Expand All @@ -30,7 +30,7 @@ func Test_PackageURL(t *testing.T) {
ID: "something else",
VersionID: "3.4.6",
},
expected: "",
expected: "pkg:apk/something%20else/p@v?arch=a&distro=something%20else-3.4.6",
},
{
name: "gocase",
Expand Down Expand Up @@ -236,6 +236,19 @@ func Test_PackageURL(t *testing.T) {
},
expected: "pkg:apk/alpine/abc101-a12345-1045@101.191.23456?arch=a&upstream=abc101-a12345&distro=alpine-3.4.6",
},
{
name: "wolfi distro",
metadata: pkg.ApkMetadata{
Package: "p",
Version: "v",
Architecture: "a",
},
distro: linux.Release{
ID: "wolfi",
VersionID: "20221230",
},
expected: "pkg:apk/wolfi/p@v?arch=a&distro=wolfi-20221230",
},
}

for _, test := range tests {
Expand Down

0 comments on commit 3ee1af0

Please sign in to comment.