Skip to content

Guided Remediation: non-interactive mode #798

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

Merged
merged 9 commits into from
Feb 20, 2024

Conversation

michaelkedar
Copy link
Member

It actually can be used now 🎉

This is basically re-written from the internal equivalent, but it should be functionally similar.
Probably will end up extracting some code to use with the interactive code when I end up needing it.

imo, non-interactive mode is currently too opaque to be generally useful - there's no indication of what vulnerabilities exist and which get fixed.

@codecov-commenter
Copy link

codecov-commenter commented Feb 13, 2024

Codecov Report

Attention: 110 lines in your changes are missing coverage. Please review.

Comparison is base (b50e737) 58.89% compared to head (80326c5) 71.79%.

Files Patch % Lines
cmd/osv-scanner/fix/noninteractive.go 63.19% 48 Missing and 12 partials ⚠️
cmd/osv-scanner/fix/regen_lockfile.go 0.00% 32 Missing ⚠️
cmd/osv-scanner/fix/main.go 57.14% 11 Missing and 1 partial ⚠️
internal/resolution/resolve.go 40.00% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #798       +/-   ##
===========================================
+ Coverage   58.89%   71.79%   +12.90%     
===========================================
  Files         116      118        +2     
  Lines        8452     8677      +225     
===========================================
+ Hits         4978     6230     +1252     
+ Misses       3271     2078     -1193     
- Partials      203      369      +166     

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

@michaelkedar
Copy link
Member Author

Comparison is base (85563d9) 79.98% compared to head (93342b1) 57.73%.

Oof. Is there a way to ignore / separate the fix stuff from the rest of the coverage? At least until I add in tests.


cmd := opts.RelockCmd
if cmd == "" {
cmd = "npm install --package-lock-only"
Copy link
Contributor

Choose a reason for hiding this comment

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

does this mean that npm needs to be installed to re-lock?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, we need npm to regenerate the package-lock.json from scratch.
It doesn't need to be installed if osv-scanner fix isn't regenerating the lockfile, but npm install would need to be run eventually.

}

res.FilterVulns(opts.MatchVuln)
// TODO: count vulnerabilities per unique version as scan action does
Copy link
Collaborator

Choose a reason for hiding this comment

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

how much work is this to do?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's probably not too much work for just the counts, as long as we still take the all-or-nothing approach to resolving the vulns.
I think I'll look at this after I port the interactive mode, since it might change how I list the vulnerabilities there.

// returns the top {maxUpgrades} compatible patches, the number of vulns fixed, and the number unfixable vulns
// if maxUpgrades is < 0, do as many patches as possible
func autoChooseRelockPatches(diffs []resolution.ResolutionDiff, maxUpgrades int) ([]manifest.DependencyPatch, int, int) {
unfixableVulnIDs := make(map[string]struct{})
Copy link
Collaborator

Choose a reason for hiding this comment

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

add some high level comments explaining the logic in this function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added

Version: p.OrigVersion,
}

if _, seen := seenVKs[vk]; maxUpgrades != 0 && !seen {
Copy link
Collaborator

Choose a reason for hiding this comment

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

add a comment explaining this loop logic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added

Copy link
Collaborator

@another-rex another-rex left a comment

Choose a reason for hiding this comment

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

Let's add some simple integration tests just to make sure it runs, and some small changes e.g. changes in the CLI don't accidentally break functionality.

@michaelkedar
Copy link
Member Author

Let's add some simple integration tests just to make sure it runs, and some small changes e.g. changes in the CLI don't accidentally break functionality.

Added two basic end-to-end tests, bringing the coverage back up to ~70%. Might make the tests take slightly longer to run. Hopefully these don't break easily if new versions of packages are released, but I've tried to pick packages that are unlikely to change.

Copy link
Collaborator

@another-rex another-rex left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@oliverchang
Copy link
Collaborator

Is this ready for merge @michaelkedar ?

@michaelkedar
Copy link
Member Author

Oh yeah - this was ready to merge last week 🙂

@michaelkedar michaelkedar merged commit ef3a2a4 into google:main Feb 20, 2024
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.

5 participants