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

feat: add distro mapping for azure linux 3 #1848

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion grype/db/v3/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,9 @@ func Test_NamespaceForDistro(t *testing.T) {
allDistros.Add(d.String())
}

// TODO: what do we do with mariner
// v3 and older schemas don't include these newer distros:
allDistros.Remove(distro.Mariner.String())
allDistros.Remove(distro.Azure.String())

for _, test := range tests {
name := fmt.Sprintf("%s:%s", test.dist, test.version)
Expand Down
16 changes: 16 additions & 0 deletions grype/db/v5/namespace/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:azurelinux:3.0",
"msrc:distro:windows:471816",
"ubuntu:distro:ubuntu:18.04",
"oracle:distro:oraclelinux:8",
Expand Down Expand Up @@ -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", osDistro.Azure, "3.0"),
},
},
{
name: "Oracle Linux Major semvar matches oracle namespace with exact version",
distro: newDistro(t, osDistro.OracleLinux, "8", []string{}),
Expand Down
15 changes: 15 additions & 0 deletions grype/distro/distro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -206,6 +216,11 @@ func Test_NewDistroFromRelease_Coverage(t *testing.T) {
Type: Mariner,
Version: "1.0.0",
},
{
fixture: "test-fixtures/os/azurelinux",
Type: Azure,
Version: "3.0.0",
},
{
fixture: "test-fixtures/os/rockylinux",
Type: RockyLinux,
Expand Down
9 changes: 9 additions & 0 deletions grype/distro/test-fixtures/os/azurelinux/etc/os-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
NAME="Microsoft Azure Linux"
VERSION="3.0.20240417"
ID=azurelinux
VERSION_ID="3.0"
PRETTY_NAME="Microsoft Azure Linux 3.0"
ANSI_COLOR="1;34"
HOME_URL="https://aka.ms/azurelinux"
BUG_REPORT_URL="https://aka.ms/azurelinux"
SUPPORT_URL="https://aka.ms/azurelinux"
3 changes: 3 additions & 0 deletions grype/distro/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -49,6 +50,7 @@ var All = []Type{
Photon,
Windows,
Mariner,
Azure,
RockyLinux,
AlmaLinux,
Gentoo,
Expand All @@ -73,6 +75,7 @@ var IDMapping = map[string]Type{
"photon": Photon,
"windows": Windows,
"mariner": Mariner,
"azurelinux": Azure,
"rocky": RockyLinux,
"almalinux": AlmaLinux,
"gentoo": Gentoo,
Expand Down