From afcd86769aa33487bb517d752778a447a705423c Mon Sep 17 00:00:00 2001 From: Will Murphy Date: Tue, 7 May 2024 17:07:41 -0400 Subject: [PATCH] feat: add distro mapping for azure linux 3 Signed-off-by: Will Murphy --- grype/db/v5/namespace/index.go | 5 +++++ grype/db/v5/namespace/index_test.go | 16 ++++++++++++++++ grype/distro/distro_test.go | 10 ++++++++++ grype/distro/type.go | 2 ++ 4 files changed, 33 insertions(+) diff --git a/grype/db/v5/namespace/index.go b/grype/db/v5/namespace/index.go index ad6f752e817..454272ee4e2 100644 --- a/grype/db/v5/namespace/index.go +++ b/grype/db/v5/namespace/index.go @@ -134,6 +134,11 @@ func (i *Index) NamespacesForDistro(d *grypeDistro.Distro) []*distro.Namespace { if v, ok := i.byDistroKey[distroKey]; ok { return v } + case grypeDistro.Azure, grypeDistro.Mariner: // mariner was pre-release name for azure + distroKey = fmt.Sprintf("%s:%s", strings.ToLower(string(grypeDistro.Mariner)), d.FullVersion()) + if v, ok := i.byDistroKey[distroKey]; ok { + return v + } } } diff --git a/grype/db/v5/namespace/index_test.go b/grype/db/v5/namespace/index_test.go index 00ac10da3e1..979cd8acc8f 100644 --- a/grype/db/v5/namespace/index_test.go +++ b/grype/db/v5/namespace/index_test.go @@ -137,6 +137,8 @@ func TestIndex_NamespacesForDistro(t *testing.T) { "other-provider:distro:debian:8", "other-provider:distro:redhat:9", "suse:distro:sles:12.5", + "mariner:distro:mariner:2.0", + "mariner:distro:mariner:3.0", "msrc:distro:windows:471816", "ubuntu:distro:ubuntu:18.04", "oracle:distro:oraclelinux:8", @@ -295,6 +297,20 @@ func TestIndex_NamespacesForDistro(t *testing.T) { distro: newDistro(t, osDistro.Mariner, "20.1", []string{}), namespaces: nil, }, + { + name: "Mariner 2.0 matches mariner namespace", + distro: newDistro(t, osDistro.Mariner, "2.0", []string{}), + namespaces: []*distro.Namespace{ + distro.NewNamespace("mariner", "mariner", "2.0"), + }, + }, + { + name: "azurelinux 3 is matched by mariner 3 namespace", + distro: newDistro(t, osDistro.Azure, "3.0", []string{}), + namespaces: []*distro.Namespace{ + distro.NewNamespace("mariner", "mariner", "3.0"), + }, + }, { name: "Oracle Linux Major semvar matches oracle namespace with exact version", distro: newDistro(t, osDistro.OracleLinux, "8", []string{}), diff --git a/grype/distro/distro_test.go b/grype/distro/distro_test.go index 29ac4d94afa..cbeec3af185 100644 --- a/grype/distro/distro_test.go +++ b/grype/distro/distro_test.go @@ -82,6 +82,16 @@ func Test_NewDistroFromRelease(t *testing.T) { expectedRawVersion: "unstable", expectedVersion: "", }, + { + name: "azure linux 3", + release: linux.Release{ + ID: "azurelinux", + Version: "3.0.20240417", + VersionID: "3.0", + }, + expectedType: Azure, + expectedRawVersion: "3.0", + }, } for _, test := range tests { diff --git a/grype/distro/type.go b/grype/distro/type.go index f079b6ea260..22c9f28f380 100644 --- a/grype/distro/type.go +++ b/grype/distro/type.go @@ -25,6 +25,7 @@ const ( Photon Type = "photon" Windows Type = "windows" Mariner Type = "mariner" + Azure Type = "azurelinux" RockyLinux Type = "rockylinux" AlmaLinux Type = "almalinux" Gentoo Type = "gentoo" @@ -73,6 +74,7 @@ var IDMapping = map[string]Type{ "photon": Photon, "windows": Windows, "mariner": Mariner, + "azurelinux": Azure, "rocky": RockyLinux, "almalinux": AlmaLinux, "gentoo": Gentoo,