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

fix: ignore updates from rhel-alt el7a release #87

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion vmaas/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,11 @@ func cveMapValues(cves map[string]VulnerabilityDetail) []VulnerabilityDetail {
return vals
}

func isApplicable(c *Cache, update, input *utils.Nevra) bool {
func isApplicable(c *Cache, update, input *utils.Nevra, opts *options) bool {
splittedRelease := strings.Split(update.Release, ".")
if opts.excludedReleases[splittedRelease[len(splittedRelease)-1]] {
return false
}
if update.Name != input.Name {
return false
}
Expand Down
34 changes: 17 additions & 17 deletions vmaas/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,25 +570,25 @@ func TestIsApplicabe(t *testing.T) {
bash := pkgID2Nevra(&c, 7)

// newer noarch is applicable to all other archs
assert.True(t, isApplicable(&c, &kernelNoarchNew, &kernelNoarch))
assert.True(t, isApplicable(&c, &kernelNoarchNew, &kernelX86))
assert.True(t, isApplicable(&c, &kernelNoarchNew, &kernelAarch))
assert.True(t, isApplicable(&c, &kernelNoarchNew, &kernelNoarch, &defaultOpts))
assert.True(t, isApplicable(&c, &kernelNoarchNew, &kernelX86, &defaultOpts))
assert.True(t, isApplicable(&c, &kernelNoarchNew, &kernelAarch, &defaultOpts))
// newer x86_64 kernel can be applied only on x86_64 or noarch
assert.True(t, isApplicable(&c, &kernelX86New, &kernelX86))
assert.True(t, isApplicable(&c, &kernelX86New, &kernelNoarch))
assert.True(t, isApplicable(&c, &kernelX86New, &kernelX86, &defaultOpts))
assert.True(t, isApplicable(&c, &kernelX86New, &kernelNoarch, &defaultOpts))
// x86_64 cannot be applied on aarch64 and vice versa
assert.False(t, isApplicable(&c, &kernelX86New, &kernelAarch))
assert.False(t, isApplicable(&c, &kernelAarchNew, &kernelX86))
assert.False(t, isApplicable(&c, &kernelX86New, &kernelAarch, &defaultOpts))
assert.False(t, isApplicable(&c, &kernelAarchNew, &kernelX86, &defaultOpts))
// same or older version cannot be applied
assert.False(t, isApplicable(&c, &kernelNoarch, &kernelNoarch))
assert.False(t, isApplicable(&c, &kernelX86, &kernelX86))
assert.False(t, isApplicable(&c, &kernelAarch, &kernelAarch))
assert.False(t, isApplicable(&c, &kernelNoarch, &kernelNoarchNew))
assert.False(t, isApplicable(&c, &kernelX86, &kernelX86New))
assert.False(t, isApplicable(&c, &kernelAarch, &kernelAarchNew))
assert.False(t, isApplicable(&c, &kernelNoarch, &kernelX86))
assert.False(t, isApplicable(&c, &kernelNoarch, &kernelAarchNew))
assert.False(t, isApplicable(&c, &kernelNoarch, &kernelNoarch, &defaultOpts))
assert.False(t, isApplicable(&c, &kernelX86, &kernelX86, &defaultOpts))
assert.False(t, isApplicable(&c, &kernelAarch, &kernelAarch, &defaultOpts))
assert.False(t, isApplicable(&c, &kernelNoarch, &kernelNoarchNew, &defaultOpts))
assert.False(t, isApplicable(&c, &kernelX86, &kernelX86New, &defaultOpts))
assert.False(t, isApplicable(&c, &kernelAarch, &kernelAarchNew, &defaultOpts))
assert.False(t, isApplicable(&c, &kernelNoarch, &kernelX86, &defaultOpts))
assert.False(t, isApplicable(&c, &kernelNoarch, &kernelAarchNew, &defaultOpts))
// bash cannot be update for kernel or kernel for bash
assert.False(t, isApplicable(&c, &bash, &kernelNoarch))
assert.False(t, isApplicable(&c, &kernelNoarchNew, &bash))
assert.False(t, isApplicable(&c, &bash, &kernelNoarch, &defaultOpts))
assert.False(t, isApplicable(&c, &kernelNoarchNew, &bash, &defaultOpts))
}
16 changes: 15 additions & 1 deletion vmaas/options.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package vmaas

var defaultOpts = options{20, true, map[string]bool{"kernel-alt": true}, true, true}
var defaultOpts = options{
20, true, map[string]bool{"kernel-alt": true}, map[string]bool{"el7a": true}, true, true,
}

type options struct {
maxGoroutines int
evalUnfixed bool
excludedPackages map[string]bool
excludedReleases map[string]bool
newerReleaseverRepos bool
newerReleaseverCsaf bool
}
Expand Down Expand Up @@ -55,6 +58,17 @@ func WithExcludedPackages(pkgs map[string]bool) Option {
return excludedPkgsOption(pkgs)
}

type excludedRelsOption map[string]bool

func (p excludedRelsOption) apply(opts *options) {
opts.excludedReleases = p
}

// Option to set excluded package releases
func WithExcludedReleases(rel map[string]bool) Option {
return excludedRelsOption(rel)
}

type newerReleaseverReposOption bool

func (n newerReleaseverReposOption) apply(opts *options) {
Expand Down
6 changes: 3 additions & 3 deletions vmaas/vulnerabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func evaluate(c *Cache, opts *options, request *Request) (*VulnerabilitiesCvesDe

// 3. evaluate Manually Fixable CVEs
// if CVE is already in Unpatched or CVE list -> skip it
evaluateManualCves(c, products, &cves)
evaluateManualCves(c, products, &cves, opts)
return &cves, nil
}

Expand Down Expand Up @@ -157,7 +157,7 @@ func evaluateUnpatchedCves(c *Cache, products []ProductsPackage, cves *Vulnerabi
}
}

func evaluateManualCves(c *Cache, products []ProductsPackage, cves *VulnerabilitiesCvesDetails) {
func evaluateManualCves(c *Cache, products []ProductsPackage, cves *VulnerabilitiesCvesDetails, opts *options) {
for _, pp := range products {
pp := pp // make copy because &pp is used
seenProducts := make(map[CSAFProduct]bool, len(pp.ProductsFixed))
Expand All @@ -169,7 +169,7 @@ func evaluateManualCves(c *Cache, products []ProductsPackage, cves *Vulnerabilit
}
seenProducts[product] = true
updateNevra := pkgID2Nevra(c, product.PackageID)
if !isApplicable(c, &updateNevra, &pp.Package.Nevra) {
if !isApplicable(c, &updateNevra, &pp.Package.Nevra, opts) {
continue
}

Expand Down
2 changes: 1 addition & 1 deletion vmaas/vulnerabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestCSAF(t *testing.T) {
UnpatchedCves: make(map[string]VulnerabilityDetail),
}
evaluateUnpatchedCves(&c, products, &cves)
evaluateManualCves(&c, products, &cves)
evaluateManualCves(&c, products, &cves, &defaultOpts)

unpatchedCves := maps.Keys(cves.UnpatchedCves)
manualCves := maps.Keys(cves.ManualCves)
Expand Down
Loading