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

rhel: add csaf/vex updater #1165

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

rhel: add csaf/vex updater #1165

wants to merge 4 commits into from

Conversation

crozzy
Copy link
Contributor

@crozzy crozzy commented Nov 29, 2023

TODO

  • Use specific product CVSS scores and normalized them when cvss: add package for dealing with CVSS scores #1143 is merged
  • Delta updating needs to be implemented before this will be mergable
  • Implement ingestion of compressed VEX data (once available)
  • Finalize fetcher logic
  • Write fetcher tests once logic is finalized
  • Extend parser tests
  • Revisit repo matching logic
  • Add CSAF-VEX updater to defaults
  • Remove rhel updater from defaults
  • Delete rhel vulnerabilities

Copy link

codecov bot commented Nov 29, 2023

Codecov Report

Attention: Patch coverage is 55.02959% with 228 lines in your changes are missing coverage. Please review.

Project coverage is 56.25%. Comparing base (4c5aa9e) to head (fbdb2b9).
Report is 1 commits behind head on main.

Files Patch % Lines
rhel/vex/parser.go 61.34% 70 Missing and 22 partials ⚠️
rhel/vex/fetcher.go 52.24% 51 Missing and 34 partials ⚠️
rhel/vex/updater.go 46.03% 28 Missing and 6 partials ⚠️
rhel/matcherfactory.go 0.00% 10 Missing ⚠️
rhel/matcher.go 46.15% 6 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #1165    +/-   ##
========================================
  Coverage   56.24%   56.25%            
========================================
  Files         266      270     +4     
  Lines       16838    17336   +498     
========================================
+ Hits         9471     9752   +281     
- Misses       6402     6558   +156     
- Partials      965     1026    +61     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

rhel/vex/fetcher.go Outdated Show resolved Hide resolved
rhel/vex/fetcher.go Outdated Show resolved Hide resolved
rhel/vex/parser.go Outdated Show resolved Hide resolved
@crozzy crozzy force-pushed the csaf-vex branch 6 times, most recently from e30a749 to abfa0e0 Compare April 29, 2024 18:19
@crozzy crozzy requested a review from hdonnay April 29, 2024 18:20
@crozzy
Copy link
Contributor Author

crozzy commented Apr 29, 2024

I figure this is probably ready for a review even if it can't be fully merged yet

rhel/matcher.go Show resolved Hide resolved
@@ -63,6 +64,7 @@ func inner(ctx context.Context) error {
updater.Register("debian", df)

updater.Register("osv", new(osv.Factory))
updater.Register("rhel-vex", new(vex.Factory))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the idea to support both OVAL and VEX at the same time for a period, or will this PR remove "rhel", too, later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably remove the OVAL in the same PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@RTann check out the last commit

Copy link
Contributor

Choose a reason for hiding this comment

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

just curious about the ordering here. is it pretty arbitrary?

@crozzy crozzy force-pushed the csaf-vex branch 8 times, most recently from bf52b0b to ab36dfd Compare May 10, 2024 16:17
@crozzy crozzy force-pushed the csaf-vex branch 5 times, most recently from 0896bbd to 818d85d Compare May 14, 2024 22:13
Replace the Red Hat OVALv2 update source with the Red Hat CSAF/VEX data.

Signed-off-by: crozzy <joseph.crosland@gmail.com>
Start matching repository CPEs based on the CPE subset relation.
This change interprets VEX CPEs identifying Red Hat repositories as CPE
matching expressions and looks for a subset relation with the record's
repositoty CPE.

Signed-off-by: crozzy <joseph.crosland@gmail.com>
Previously the IgnoreUnpatched config key was a part of the RHEL
updater and would dictate whether or not the updater would ingest
unpatched vulnerabilities. This change moves that key to the RHEL
matcher and dictates whether the matcher should check for a
fixed_in_version when querying potential vulnerabilities. This makes the
config option more usable at the expense of DB size.

Signed-off-by: crozzy <joseph.crosland@gmail.com>
Given that the rhel-vex data will be responsible for Red Hat
vulnerabilities we no longer want the existing OVAL updater to be a
default (or even selectable). This patch also removes existing RHEL OVAL
data from the matcher DB.

Signed-off-by: crozzy <joseph.crosland@gmail.com>
-- The rhel-vex updater will now be responsible for RHEL advisories so we have
-- to delete the existing rhel vulnerabilities.
DELETE FROM update_operation WHERE updater ~ 'RHEL[5-9]-*';
DELETE FROM vuln v2 where v2.updater ~ 'RHEL[5-9]-*';
Copy link
Contributor

Choose a reason for hiding this comment

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

just curious why call this v2?

@@ -70,6 +70,8 @@ func buildGetQuery(record *claircore.IndexRecord, opts *datastore.GetOpts) (stri
ex = goqu.Ex{"dist_arch": record.Distribution.Arch}
case driver.RepositoryName:
ex = goqu.Ex{"repo_name": record.Repository.Name}
case driver.HasFixedInVersion:
ex = goqu.Ex{"fixed_in_version": goqu.Op{"neq": ""}}
Copy link
Contributor

Choose a reason for hiding this comment

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

just curious if this is preferred over something like exp.NeqOp.String(). This is wordier, but protects against mistakes and future-proofs it (though I doubt it'll change, and it looks correct go me)

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the unit test also proves this works and can future-proof it

@@ -142,7 +142,7 @@ func (mc *Controller) filter(ctx context.Context, interested []*claircore.IndexR
if err != nil {
return nil, err
}
filtered[record.Package.ID] = match
filtered[record.Package.ID] = append(filtered[record.Package.ID], match...)
Copy link
Contributor

Choose a reason for hiding this comment

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

hard to tell without context: what was this overwriting before? How bad was this?

driver.PackageModule,
driver.RepositoryName,
func (m *Matcher) Query() []driver.MatchConstraint {
mcs := []driver.MatchConstraint{driver.PackageModule}
Copy link
Contributor

Choose a reason for hiding this comment

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

curious why do we check the package module? does every package have a related module? why not check for distribution name?

Comment on lines +41 to +46
// Vulnerable() will interpret the claircore.Vulnerability.Repo.CPE
// as a CPE match expression and in order to be considered vulnerable
// the relationship between claircore.IndexRecord.Repository.CPE and
// the claircore.Vulnerability.Repo.CPE needs to be a CPE Name Comparison
// Relation of SUBSET(⊂)(source is a subset of, or equal to the target).
// https://nvlpubs.nist.gov/nistpubs/Legacy/IR/nistir7696.pdf Section 6.2.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Vulnerable() will interpret the claircore.Vulnerability.Repo.CPE
// as a CPE match expression and in order to be considered vulnerable
// the relationship between claircore.IndexRecord.Repository.CPE and
// the claircore.Vulnerability.Repo.CPE needs to be a CPE Name Comparison
// Relation of SUBSET(⊂)(source is a subset of, or equal to the target).
// https://nvlpubs.nist.gov/nistpubs/Legacy/IR/nistir7696.pdf Section 6.2.
// Vulnerable will interpret the claircore.Vulnerability.Repo.CPE
// as a CPE match expression, and to be considered vulnerable,
// the relationship between claircore.IndexRecord.Repository.CPE and
// the claircore.Vulnerability.Repo.CPE needs to be a CPE Name Comparison
// Relation of SUBSET(⊂)(source is a subset of, or equal to the target).
// https://nvlpubs.nist.gov/nistpubs/Legacy/IR/nistir7696.pdf Section 6.2.

if err != nil {
return nil, hint, fmt.Errorf("error making advisory request %w", err)
}
if res.StatusCode != http.StatusOK {
Copy link
Contributor

Choose a reason for hiding this comment

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

missing a Body.Close() when we reach this

buf.Reset()
bc.Reset()
l++
res.Body.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

another option is to put this into a separate func so we can defer without worrying about the loop

return nil, hint, fmt.Errorf("unexpected response from advisary URL: %s %s", res.Status, req.URL)
}

_, err = buf.ReadFrom(res.Body)
Copy link
Contributor

Choose a reason for hiding this comment

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

so does this cover the case where this is the first time we read the VEX data and there is a newer version of a few files? This will overwrite data for those files?

)

// Parse implements [driver.Updater].
func (u *VEXUpdater) Parse(ctx context.Context, contents io.ReadCloser) ([]*claircore.Vulnerability, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For StackRox's usage of Claircore at the moment, we pretty much start fresh every time. Does not implementing Parse mean our use case may not work? Related: will the jsonblob stuff work OOTB?

Copy link
Contributor

Choose a reason for hiding this comment

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

Will need to look at this another time

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

Successfully merging this pull request may close these issues.

None yet

3 participants