mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-12 15:50:15 -08:00
feat(redhat): add os-release detection for RHEL-based images (#9458)
Co-authored-by: DmitriyLewen <dmitriy.lewen@smartforce.io>
This commit is contained in:
@@ -27,7 +27,8 @@ var requiredFiles = []string{
|
||||
type osReleaseAnalyzer struct{}
|
||||
|
||||
func (a osReleaseAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput) (*analyzer.AnalysisResult, error) {
|
||||
var id, versionID string
|
||||
var family types.OSType
|
||||
var versionID string
|
||||
scanner := bufio.NewScanner(input.Content)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
@@ -40,46 +41,14 @@ func (a osReleaseAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInp
|
||||
|
||||
switch key {
|
||||
case "ID":
|
||||
id = strings.Trim(value, `"'`)
|
||||
id := strings.Trim(value, `"'`)
|
||||
family = idToOSFamily(id)
|
||||
case "VERSION_ID":
|
||||
versionID = strings.Trim(value, `"'`)
|
||||
default:
|
||||
continue
|
||||
}
|
||||
|
||||
var family types.OSType
|
||||
switch id {
|
||||
case "alpine":
|
||||
family = types.Alpine
|
||||
case "bottlerocket":
|
||||
family = types.Bottlerocket
|
||||
case "opensuse-tumbleweed":
|
||||
family = types.OpenSUSETumbleweed
|
||||
case "opensuse-leap", "opensuse": // opensuse for leap:42, opensuse-leap for leap:15
|
||||
family = types.OpenSUSELeap
|
||||
case "sles":
|
||||
family = types.SLES
|
||||
// There are various rebrands of SLE Micro, there is also one brief (and reverted rebrand)
|
||||
// for SLE Micro 6.0. which was called "SL Micro 6.0" until very short before release
|
||||
// and there is a "SLE Micro for Rancher" rebrand, which is used by SUSEs K8S based offerings.
|
||||
case "sle-micro", "sl-micro", "sle-micro-rancher":
|
||||
family = types.SLEMicro
|
||||
case "photon":
|
||||
family = types.Photon
|
||||
case "wolfi":
|
||||
family = types.Wolfi
|
||||
case "chainguard":
|
||||
family = types.Chainguard
|
||||
case "azurelinux":
|
||||
family = types.Azure
|
||||
case "mariner":
|
||||
family = types.CBLMariner
|
||||
case "echo":
|
||||
family = types.Echo
|
||||
case "minimos":
|
||||
family = types.MinimOS
|
||||
}
|
||||
|
||||
if family != "" && versionID != "" {
|
||||
return &analyzer.AnalysisResult{
|
||||
OS: types.OS{
|
||||
@@ -93,6 +62,54 @@ func (a osReleaseAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInp
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func idToOSFamily(id string) types.OSType {
|
||||
switch id {
|
||||
case "rhel":
|
||||
return types.RedHat
|
||||
case "centos":
|
||||
return types.CentOS
|
||||
case "rocky":
|
||||
return types.Rocky
|
||||
case "almalinux":
|
||||
return types.Alma
|
||||
case "ol":
|
||||
return types.Oracle
|
||||
case "fedora":
|
||||
return types.Fedora
|
||||
case "alpine":
|
||||
return types.Alpine
|
||||
case "bottlerocket":
|
||||
return types.Bottlerocket
|
||||
case "opensuse-tumbleweed":
|
||||
return types.OpenSUSETumbleweed
|
||||
case "opensuse-leap", "opensuse": // opensuse for leap:42, opensuse-leap for leap:15
|
||||
return types.OpenSUSELeap
|
||||
case "sles":
|
||||
return types.SLES
|
||||
// There are various rebrands of SLE Micro, there is also one brief (and reverted rebrand)
|
||||
// for SLE Micro 6.0. which was called "SL Micro 6.0" until very short before release
|
||||
// and there is a "SLE Micro for Rancher" rebrand, which is used by SUSEs K8S based offerings.
|
||||
case "sle-micro", "sl-micro", "sle-micro-rancher":
|
||||
return types.SLEMicro
|
||||
case "photon":
|
||||
return types.Photon
|
||||
case "wolfi":
|
||||
return types.Wolfi
|
||||
case "chainguard":
|
||||
return types.Chainguard
|
||||
case "azurelinux":
|
||||
return types.Azure
|
||||
case "mariner":
|
||||
return types.CBLMariner
|
||||
case "echo":
|
||||
return types.Echo
|
||||
case "minimos":
|
||||
return types.MinimOS
|
||||
}
|
||||
// This OS is not supported for this analyzer.
|
||||
return ""
|
||||
}
|
||||
|
||||
func (a osReleaseAnalyzer) Required(filePath string, _ os.FileInfo) bool {
|
||||
return slices.Contains(requiredFiles, filePath)
|
||||
}
|
||||
|
||||
@@ -19,6 +19,66 @@ func Test_osReleaseAnalyzer_Analyze(t *testing.T) {
|
||||
want *analyzer.AnalysisResult
|
||||
wantErr string
|
||||
}{
|
||||
{
|
||||
name: "Fedora",
|
||||
inputFile: "testdata/fedora",
|
||||
want: &analyzer.AnalysisResult{
|
||||
OS: types.OS{
|
||||
Family: types.Fedora,
|
||||
Name: "42",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Red Hat Enterprise Linux",
|
||||
inputFile: "testdata/rhel",
|
||||
want: &analyzer.AnalysisResult{
|
||||
OS: types.OS{
|
||||
Family: types.RedHat,
|
||||
Name: "9.4",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "CentOS",
|
||||
inputFile: "testdata/centos",
|
||||
want: &analyzer.AnalysisResult{
|
||||
OS: types.OS{
|
||||
Family: types.CentOS,
|
||||
Name: "7",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Rocky Linux",
|
||||
inputFile: "testdata/rocky",
|
||||
want: &analyzer.AnalysisResult{
|
||||
OS: types.OS{
|
||||
Family: types.Rocky,
|
||||
Name: "9.3",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "AlmaLinux",
|
||||
inputFile: "testdata/alma",
|
||||
want: &analyzer.AnalysisResult{
|
||||
OS: types.OS{
|
||||
Family: types.Alma,
|
||||
Name: "9.4",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Oracle Linux",
|
||||
inputFile: "testdata/oracle",
|
||||
want: &analyzer.AnalysisResult{
|
||||
OS: types.OS{
|
||||
Family: types.Oracle,
|
||||
Name: "8.10",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "alpine",
|
||||
inputFile: "testdata/alpine",
|
||||
|
||||
19
pkg/fanal/analyzer/os/release/testdata/alma
vendored
Normal file
19
pkg/fanal/analyzer/os/release/testdata/alma
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
NAME="AlmaLinux"
|
||||
VERSION="9.4 (Seafoam Ocelot)"
|
||||
ID="almalinux"
|
||||
ID_LIKE="rhel centos fedora"
|
||||
VERSION_ID="9.4"
|
||||
PLATFORM_ID="platform:el9"
|
||||
PRETTY_NAME="AlmaLinux 9.4 (Seafoam Ocelot)"
|
||||
ANSI_COLOR="0;34"
|
||||
LOGO="fedora-logo-icon"
|
||||
CPE_NAME="cpe:/o:almalinux:almalinux:9::baseos"
|
||||
HOME_URL="https://almalinux.org/"
|
||||
DOCUMENTATION_URL="https://wiki.almalinux.org/"
|
||||
BUG_REPORT_URL="https://bugs.almalinux.org/"
|
||||
|
||||
ALMALINUX_MANTISBT_PROJECT="AlmaLinux-9"
|
||||
ALMALINUX_MANTISBT_PROJECT_VERSION="9.4"
|
||||
REDHAT_SUPPORT_PRODUCT="AlmaLinux"
|
||||
REDHAT_SUPPORT_PRODUCT_VERSION="9.4"
|
||||
SUPPORT_END=2032-06-01
|
||||
15
pkg/fanal/analyzer/os/release/testdata/centos
vendored
Normal file
15
pkg/fanal/analyzer/os/release/testdata/centos
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
NAME="CentOS Linux"
|
||||
VERSION="7 (Core)"
|
||||
ID="centos"
|
||||
ID_LIKE="rhel fedora"
|
||||
VERSION_ID="7"
|
||||
PRETTY_NAME="CentOS Linux 7 (Core)"
|
||||
ANSI_COLOR="0;31"
|
||||
CPE_NAME="cpe:/o:centos:centos:7"
|
||||
HOME_URL="https://www.centos.org/"
|
||||
BUG_REPORT_URL="https://bugs.centos.org/"
|
||||
|
||||
CENTOS_MANTISBT_PROJECT="CentOS-7"
|
||||
CENTOS_MANTISBT_PROJECT_VERSION="7"
|
||||
REDHAT_SUPPORT_PRODUCT="centos"
|
||||
REDHAT_SUPPORT_PRODUCT_VERSION="7"
|
||||
23
pkg/fanal/analyzer/os/release/testdata/fedora
vendored
Normal file
23
pkg/fanal/analyzer/os/release/testdata/fedora
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
NAME="Fedora Linux"
|
||||
VERSION="42 (Container Image)"
|
||||
RELEASE_TYPE=stable
|
||||
ID=fedora
|
||||
VERSION_ID=42
|
||||
VERSION_CODENAME=""
|
||||
PLATFORM_ID="platform:f42"
|
||||
PRETTY_NAME="Fedora Linux 42 (Container Image)"
|
||||
ANSI_COLOR="0;38;2;60;110;180"
|
||||
LOGO=fedora-logo-icon
|
||||
CPE_NAME="cpe:/o:fedoraproject:fedora:42"
|
||||
DEFAULT_HOSTNAME="fedora"
|
||||
HOME_URL="https://fedoraproject.org/"
|
||||
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f42/"
|
||||
SUPPORT_URL="https://ask.fedoraproject.org/"
|
||||
BUG_REPORT_URL="https://bugzilla.redhat.com/"
|
||||
REDHAT_BUGZILLA_PRODUCT="Fedora"
|
||||
REDHAT_BUGZILLA_PRODUCT_VERSION=42
|
||||
REDHAT_SUPPORT_PRODUCT="Fedora"
|
||||
REDHAT_SUPPORT_PRODUCT_VERSION=42
|
||||
SUPPORT_END=2026-05-13
|
||||
VARIANT="Container Image"
|
||||
VARIANT_ID=container
|
||||
18
pkg/fanal/analyzer/os/release/testdata/oracle
vendored
Normal file
18
pkg/fanal/analyzer/os/release/testdata/oracle
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
NAME="Oracle Linux Server"
|
||||
VERSION="8.10"
|
||||
ID="ol"
|
||||
ID_LIKE="fedora"
|
||||
VARIANT="Server"
|
||||
VARIANT_ID="server"
|
||||
VERSION_ID="8.10"
|
||||
PLATFORM_ID="platform:el8"
|
||||
PRETTY_NAME="Oracle Linux Server 8.10"
|
||||
ANSI_COLOR="0;31"
|
||||
CPE_NAME="cpe:/o:oracle:linux:8:10:server"
|
||||
HOME_URL="https://linux.oracle.com/"
|
||||
BUG_REPORT_URL="https://github.com/oracle/oracle-linux"
|
||||
|
||||
ORACLE_BUGZILLA_PRODUCT="Oracle Linux 8"
|
||||
ORACLE_BUGZILLA_PRODUCT_VERSION=8.10
|
||||
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
|
||||
ORACLE_SUPPORT_PRODUCT_VERSION=8.10
|
||||
18
pkg/fanal/analyzer/os/release/testdata/rhel
vendored
Normal file
18
pkg/fanal/analyzer/os/release/testdata/rhel
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
NAME="Red Hat Enterprise Linux"
|
||||
VERSION="9.4 (Plow)"
|
||||
ID="rhel"
|
||||
ID_LIKE="fedora"
|
||||
VERSION_ID="9.4"
|
||||
PLATFORM_ID="platform:el9"
|
||||
PRETTY_NAME="Red Hat Enterprise Linux 9.4 (Plow)"
|
||||
ANSI_COLOR="0;31"
|
||||
LOGO="fedora-logo-icon"
|
||||
CPE_NAME="cpe:/o:redhat:enterprise_linux:9::baseos"
|
||||
HOME_URL="https://www.redhat.com/"
|
||||
DOCUMENTATION_URL="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9"
|
||||
BUG_REPORT_URL="https://issues.redhat.com/"
|
||||
|
||||
REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 9"
|
||||
REDHAT_BUGZILLA_PRODUCT_VERSION=9.4
|
||||
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
|
||||
REDHAT_SUPPORT_PRODUCT_VERSION="9.4"
|
||||
17
pkg/fanal/analyzer/os/release/testdata/rocky
vendored
Normal file
17
pkg/fanal/analyzer/os/release/testdata/rocky
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
NAME="Rocky Linux"
|
||||
VERSION="9.3 (Blue Onyx)"
|
||||
ID="rocky"
|
||||
ID_LIKE="rhel centos fedora"
|
||||
VERSION_ID="9.3"
|
||||
PLATFORM_ID="platform:el9"
|
||||
PRETTY_NAME="Rocky Linux 9.3 (Blue Onyx)"
|
||||
ANSI_COLOR="0;32"
|
||||
LOGO="fedora-logo-icon"
|
||||
CPE_NAME="cpe:/o:rocky:rocky:9::baseos"
|
||||
HOME_URL="https://rockylinux.org/"
|
||||
BUG_REPORT_URL="https://bugs.rockylinux.org/"
|
||||
SUPPORT_END="2032-05-31"
|
||||
ROCKY_SUPPORT_PRODUCT="Rocky-Linux-9"
|
||||
ROCKY_SUPPORT_PRODUCT_VERSION="9.3"
|
||||
REDHAT_SUPPORT_PRODUCT="Rocky Linux"
|
||||
REDHAT_SUPPORT_PRODUCT_VERSION="9.3"
|
||||
Reference in New Issue
Block a user