-
Notifications
You must be signed in to change notification settings - Fork 13
ROX-6988: Fix RHEL updates by deleting old CVEs when RH advisories are updated #456
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
Changes from all commits
02a669a
11e1a9d
b3b9021
b85b5ea
8024112
0730ac9
2f9d8d9
0c1aa08
a89f432
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,14 +8,12 @@ import ( | |
archop "github.com/quay/claircore" | ||
"github.com/stackrox/scanner/database" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRHELv2Vulnerability(t *testing.T) { | ||
datastore, err := openDatabaseForTest("InsertRHELv2Vulnerability", false) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
require.NoError(t, err) | ||
defer datastore.Close() | ||
|
||
v1 := &database.RHELv2Vulnerability{ | ||
|
@@ -189,3 +187,126 @@ func TestRHELv2Vulnerability(t *testing.T) { | |
assert.Len(t, vulns[0], 2) | ||
assert.Len(t, vulns[1], 1) | ||
} | ||
|
||
func TestRHELv2VulnerabilityCVERemoval(t *testing.T) { | ||
datastore, err := openDatabaseForTest("TestRHELv2VulnerabilityCVERemoval", false) | ||
require.NoError(t, err) | ||
defer datastore.Close() | ||
|
||
v1 := &database.RHELv2Vulnerability{ | ||
Name: "CVE-2021-1234", | ||
Description: "my vuln", | ||
Link: "https://access.redhat.com/security/cve/CVE-2021-1234", | ||
Severity: "Important", | ||
CVSSv2: "4.0/AV:N/AC:H/Au:N/C:P/I:P/A:N", | ||
CPEs: []string{ | ||
"cpe:/o:redhat:enterprise_linux:8", | ||
}, | ||
PackageInfos: []*database.RHELv2PackageInfo{ | ||
{ | ||
FixedInVersion: "0:1.0.8-13.el8", | ||
ArchOperation: archop.OpEquals, | ||
Packages: []*database.RHELv2Package{ | ||
{ | ||
Name: "package", | ||
Arch: "x86_64", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
v2 := &database.RHELv2Vulnerability{ | ||
Name: "CVE-2021-1235", | ||
Title: "RHSA-2013:0565: Red Hat Enterprise MRG Grid 2.3 security update (Low)", | ||
Description: "my vuln2", | ||
Link: "https://access.redhat.com/security/cve/CVE-2021-1235", | ||
Severity: "Moderate", | ||
CVSSv3: "4.6/CVSS:3.0/AV:A/AC:L/PR:L/UI:R/S:U/C:N/I:L/A:L", | ||
CPEs: []string{ | ||
"cpe:/o:redhat:enterprise_linux:8", | ||
"cpe:/o:redhat:enterprise_linux:7", | ||
}, | ||
PackageInfos: []*database.RHELv2PackageInfo{ | ||
{ | ||
FixedInVersion: "0:1.0.8-13.el8", | ||
ArchOperation: archop.OpEquals, | ||
Packages: []*database.RHELv2Package{ | ||
{ | ||
Name: "package", | ||
Arch: "x86_64", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
err = datastore.InsertRHELv2Vulnerabilities([]*database.RHELv2Vulnerability{v1, v2}) | ||
assert.NoError(t, err) | ||
|
||
// Insert RHSA for CPE cpe:/o:redhat:enterprise_linux:7 with a fix and sub CVE for the two above | ||
// Only the second one should be removed as the CPE will match | ||
v3 := &database.RHELv2Vulnerability{ | ||
Name: "RHSA-2013:0565", | ||
Title: "RHSA-2013:0565: Red Hat Enterprise MRG Grid 2.3 security update (Low)", | ||
Description: "my vuln2", | ||
Link: "https://access.redhat.com/security/cve/CVE-2021-1235", | ||
Severity: "Moderate", | ||
CVSSv3: "4.6/CVSS:3.0/AV:A/AC:L/PR:L/UI:R/S:U/C:N/I:L/A:L", | ||
CPEs: []string{ | ||
"cpe:/o:redhat:enterprise_linux:7", | ||
}, | ||
PackageInfos: []*database.RHELv2PackageInfo{ | ||
{ | ||
FixedInVersion: "0:1.0.8-13.el8", | ||
ArchOperation: archop.OpEquals, | ||
Packages: []*database.RHELv2Package{ | ||
{ | ||
Name: "package", | ||
Arch: "x86_64", | ||
}, | ||
}, | ||
}, | ||
}, | ||
SubCVEs: []string{"CVE-2021-1234", "CVE-2021-1235"}, | ||
} | ||
|
||
err = datastore.InsertRHELv2Vulnerabilities([]*database.RHELv2Vulnerability{v3}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happens if i insert all 3 cves in this call? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the vulnerability is added after the RHSA then it will be in the DB. Realistically, this shouldn't happen though because the RHSAs and CVEs should not overlap and mostly this is the case as seen through the genesis dump |
||
assert.NoError(t, err) | ||
|
||
records := []*database.RHELv2Record{ | ||
{ | ||
Pkg: &database.RHELv2Package{ | ||
Name: "package", | ||
}, | ||
CPE: "cpe:/o:redhat:enterprise_linux:7", | ||
}, | ||
} | ||
|
||
// Sanity check all fields are valid for single vuln. | ||
vulns, err := datastore.GetRHELv2Vulnerabilities(records) | ||
assert.NoError(t, err) | ||
assert.Len(t, vulns, 1) | ||
assert.Len(t, vulns[0], 1) | ||
vuln := vulns[0][0] | ||
assert.Equal(t, v3.Name, vuln.Name) | ||
|
||
records = []*database.RHELv2Record{ | ||
{ | ||
Pkg: &database.RHELv2Package{ | ||
Model: database.Model{ID: 0}, | ||
Name: "package", | ||
}, | ||
CPE: "cpe:/o:redhat:enterprise_linux:8", | ||
}, | ||
} | ||
|
||
// Ensure both vulns are returned. | ||
vulns, err = datastore.GetRHELv2Vulnerabilities(records) | ||
assert.NoError(t, err) | ||
assert.Len(t, vulns, 1) | ||
vulnNames := make([]string, 0, len(vulns[0])) | ||
for _, vuln := range vulns[0] { | ||
vulnNames = append(vulnNames, vuln.Name) | ||
} | ||
assert.ElementsMatch(t, vulnNames, []string{v1.Name, v2.Name}) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.