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

refactor: SUSE - update OSType constants and references for compatibi… #8202

Merged

Conversation

santhosh1729
Copy link
Contributor

@santhosh1729 santhosh1729 commented Jan 6, 2025

Description

  1. Renamed deprecated SUE OSType constants to maintain backward compatibility.
  2. Modified all occurrences where the old constants were used to ensure consistency

Related Issues:

@knqyf263
Copy link
Collaborator

knqyf263 commented Jan 7, 2025

Can we just replace the legacy names with the new names in a single place? For example:

diff --git a/pkg/fanal/types/artifact.go b/pkg/fanal/types/artifact.go
index b25aaa954..18f026653 100644
--- a/pkg/fanal/types/artifact.go
+++ b/pkg/fanal/types/artifact.go
@@ -45,6 +45,14 @@ func (o *OS) Merge(newOS OS) {
                        o.Extended = true
                }
        }
+       o.Normalize()
+}
+
+// Normalize normalizes OS family names for backward compatibility
+func (o *OS) Normalize() {
+       if alias, ok := OSTypeAliases[o.Family]; ok {
+               o.Family = alias
+       }
 }

 type Repository struct {
diff --git a/pkg/fanal/types/const.go b/pkg/fanal/types/const.go
index 42f248ba1..2e07709ad 100644
--- a/pkg/fanal/types/const.go
+++ b/pkg/fanal/types/const.go
@@ -41,14 +41,17 @@ const (
        SLES               OSType = "sles"
        Ubuntu             OSType = "ubuntu"
        Wolfi              OSType = "wolfi"
-
-       // These below constants are retained for backward compatibility with older versions of Aqua
-       OpenSUSELeapLegacy       OSType = "opensuse.leap"
-       OpenSUSETumbleweedLegacy OSType = "opensuse.tumbleweed"
-       SLEMicroLegacy           OSType = "suse linux enterprise micro"
-       SLESLegacy               OSType = "suse linux enterprise server"
 )

+// OSTypeAliases is a map of aliases for operating systems.
+// This is used to map the old family names to the new ones for backward compatibility.
+var OSTypeAliases = map[OSType]OSType{
+       "opensuse.leap":                OpenSUSELeap,
+       "opensuse.tumbleweed":          OpenSUSETumbleweed,
+       "suse linux enterprise micro":  SLEMicro,
+       "suse linux enterprise server": SLES,
+}
+
 // Programming language dependencies
 const (
        Bundler        LangType = "bundler"

@santhosh1729 santhosh1729 force-pushed the sant-suse-comp branch 4 times, most recently from 2f52db6 to 2aca44f Compare January 7, 2025 12:57
@santhosh1729
Copy link
Contributor Author

Can we just replace the legacy names with the new names in a single place? For example:

diff --git a/pkg/fanal/types/artifact.go b/pkg/fanal/types/artifact.go
index b25aaa954..18f026653 100644
--- a/pkg/fanal/types/artifact.go
+++ b/pkg/fanal/types/artifact.go
@@ -45,6 +45,14 @@ func (o *OS) Merge(newOS OS) {
                        o.Extended = true
                }
        }
+       o.Normalize()
+}
+
+// Normalize normalizes OS family names for backward compatibility
+func (o *OS) Normalize() {
+       if alias, ok := OSTypeAliases[o.Family]; ok {
+               o.Family = alias
+       }
 }

 type Repository struct {
diff --git a/pkg/fanal/types/const.go b/pkg/fanal/types/const.go
index 42f248ba1..2e07709ad 100644
--- a/pkg/fanal/types/const.go
+++ b/pkg/fanal/types/const.go
@@ -41,14 +41,17 @@ const (
        SLES               OSType = "sles"
        Ubuntu             OSType = "ubuntu"
        Wolfi              OSType = "wolfi"
-
-       // These below constants are retained for backward compatibility with older versions of Aqua
-       OpenSUSELeapLegacy       OSType = "opensuse.leap"
-       OpenSUSETumbleweedLegacy OSType = "opensuse.tumbleweed"
-       SLEMicroLegacy           OSType = "suse linux enterprise micro"
-       SLESLegacy               OSType = "suse linux enterprise server"
 )

+// OSTypeAliases is a map of aliases for operating systems.
+// This is used to map the old family names to the new ones for backward compatibility.
+var OSTypeAliases = map[OSType]OSType{
+       "opensuse.leap":                OpenSUSELeap,
+       "opensuse.tumbleweed":          OpenSUSETumbleweed,
+       "suse linux enterprise micro":  SLEMicro,
+       "suse linux enterprise server": SLES,
+}
+
 // Programming language dependencies
 const (
        Bundler        LangType = "bundler"

@santhosh1729
Copy link
Contributor Author

@knqyf263 I have updated the pr with suggested changes, Thank you!!

@santhosh1729 santhosh1729 reopened this Jan 8, 2025
Copy link
Collaborator

@knqyf263 knqyf263 left a comment

Choose a reason for hiding this comment

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

The logic looks good, but we need to add a test.

@santhosh1729
Copy link
Contributor Author

The logic looks good, but we need to add a test.

Sure, I will add it. Thank you!!

@santhosh1729
Copy link
Contributor Author

The logic looks good, but we need to add a test.

@knqyf263 I have added test for the change, can you please review it once?

@santhosh1729 santhosh1729 requested a review from knqyf263 January 9, 2025 13:10
Copy link
Collaborator

@knqyf263 knqyf263 left a comment

Choose a reason for hiding this comment

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

Left a small comment. The rest looks good.

@@ -961,6 +961,91 @@ func TestApplier_ApplyLayers(t *testing.T) {
},
wantErr: "unknown OS",
},
{
name: "SUSE Images - Legacy OS Name with Backward Compatibility",
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Other cases are lowercase.

Suggested change
name: "SUSE Images - Legacy OS Name with Backward Compatibility",
name: "SUSE images - legacy OS name with backward compatibility",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@knqyf263 I have updated the Test Name as suggested, Thank you!!

@knqyf263
Copy link
Collaborator

@DmitriyLewen Would you also take a look?

@santhosh1729 santhosh1729 force-pushed the sant-suse-comp branch 2 times, most recently from 049d0a0 to 8d89b2a Compare January 10, 2025 16:49
Copy link
Contributor

@DmitriyLewen DmitriyLewen left a comment

Choose a reason for hiding this comment

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

LGTM.
I suggested adding one comment - so that we don't forget that we also merge OSs when merging layers.

pkg/fanal/types/artifact.go Show resolved Hide resolved
…lity

1. Renamed deprecated OSType constants to maintain backward compatibility.
2. Modified all occurrences where the old constants were used to ensure consistency

(cherry picked from commit 3d21d19)
@DmitriyLewen DmitriyLewen added this pull request to the merge queue Jan 13, 2025
Merged via the queue into aquasecurity:release/v0.58 with commit 69f1baf Jan 13, 2025
12 checks passed
@DmitriyLewen
Copy link
Contributor

This PR was mistakenly merged into release/v0.58.
69f1baf was removed from the release/v0.58 branch.

#8236 was merged instead of this PR.

@htcosta
Copy link

htcosta commented Jan 19, 2025

Would be possible to add OpenSUSE MicroOS and OpenSUSE Leap Micro, they are based on Tumbleweed an Leap (immutable OS versions), they have their own OS family type?

@DmitriyLewen
Copy link
Contributor

Hello @htcosta

they have their own OS family type?

Trivy doesn't have specific types for them.

I checked cvrf suse. It contains advisories only for Leap Micro.
Also these advisories only for 2022 year:

➜  opensuse grep -r RelatesToProductReference | grep -i "micro"
./2022/openSUSE-SU-2022-2562-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2546-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2649-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2177-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2663-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2801-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2173-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2173-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2549-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2549-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2941-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-1157-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-1157-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-1157-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-1157-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2422-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2422-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2361-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2947-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2328-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2328-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2328-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2328-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2882-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2882-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",
./2022/openSUSE-SU-2022-2882-1.json:        "RelatesToProductReference": "openSUSE Leap Micro 5.2",

Perhaps Suse considers them as Tumbleweed an Leap?

Can you check /etc/os-release file for these OSes?

@htcosta
Copy link

htcosta commented Jan 20, 2025

openSUSE MicroOS is just immutable Tumbleweed no difference, the are build from the same packages, same repos. I just a question of adding an extra os family in trivy and that would work out-of-box, them same applies to openSUSE Aeon and Kalpa, they all share the same packages the all are built from Factory/Tumbleweed.

openSUSE Leap Micro currently is built from SLE Micro, is 1:1 binary compatible. This was not always the case has you see in the advisories, the reason is the the code base has changes along the way, before it was built from openSUSE Leap.

I will provide you the os-release information, late today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants