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

feat: add --experimental-offline-vulnerabilities and --experimental-no-resolve flags #1342

Merged
merged 5 commits into from
Oct 24, 2024

Conversation

michaelkedar
Copy link
Member

Closes #1339 and closes #1121
Adds flags to use offline mode for vulnerabilities (--experimental-offline-vulnerabilities) and transitive resolution separately (--experimental-no-resolve)

The original --experimental-offline flag retains the same behaviour by functionally setting both of these flags.

@codecov-commenter
Copy link

codecov-commenter commented Oct 23, 2024

Codecov Report

Attention: Patch coverage is 71.42857% with 6 lines in your changes missing coverage. Please review.

Project coverage is 68.43%. Comparing base (e054385) to head (aa0a734).

Files with missing lines Patch % Lines
cmd/osv-scanner/scan/main.go 68.75% 3 Missing and 2 partials ⚠️
cmd/osv-scanner/fix/main.go 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1342      +/-   ##
==========================================
- Coverage   68.43%   68.43%   -0.01%     
==========================================
  Files         183      183              
  Lines       17606    17620      +14     
==========================================
+ Hits        12049    12058       +9     
- Misses       4895     4898       +3     
- Partials      662      664       +2     

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

Comment on lines 234 to 238
if context.Bool("experimental-offline") {
// Set the corresponding offline flags, unless they were already set explicitly.
if !context.IsSet("experimental-offline-vulnerabilities") {
offlineVulns = true
}
Copy link
Member Author

Choose a reason for hiding this comment

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

The CompareOffline field that experimental-offline-vulnerabilities sets also affects the SkipGit and license scanning in osvscanner.DoScan.
I think it might be a bit clearer to instead set them here similarly, but that could create a subtle change in behaviour in DoScan.

disableTransitive := context.Bool("experimental-no-resolve")
if context.Bool("experimental-offline") {
// Set the corresponding offline flags, unless they were already set explicitly.
if !context.IsSet("experimental-offline-vulnerabilities") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to check if they were already set? if someone is setting --experimental-offline, then IMO that should just always disable everything regardless of what other flags are set?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess I was thinking someone has to intentionally pass e.g. --experimental-offline --experimental-offline-vulnerabilities=false, which seems like how you'd want to override the default offline options.

idk if we actually want to allow this, but if not this should probably at least log a warning.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I may understand the use case a bit here: someone wants to disable all network requests but not the ones for vulnerabilities.
Also as Michael mentioned below, CompareOffline also controls others things for example license scanning, maybe we should change it to a struct with a list of booleans? Each boolean field corresponds to one type of request requiring network.
Even further, can we change experimental-offline to be a list of strings taking all or vulnerability,license and all takes precedence over all other.

Copy link
Member Author

Choose a reason for hiding this comment

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

NB: I moved this logic to the Action of the offline flag in aa0a734, but I've not addressed this discussion.

Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO let's keep this simple for now and go with @michaelkedar 's approach.

--experimental-offline should just only be set when somebody wants to turn everything off, and can't be overriden. There's already individual flags to control behaviour (after this PR) for the independent bits.

Re taking a slice of strings instead, we went with that for --call-analysis to take in a list of languages, but I think full list of languages would be much larger than the list of functionality where we can control online/offline. (i.e. we'd have --call-analysis-rust, --call-analysis-go, --call-analysis-python, --call-analysis-{language}, ...)

And since this is all experimental, we can change this later :)

disableTransitive := context.Bool("experimental-no-resolve")
if context.Bool("experimental-offline") {
// Set the corresponding offline flags, unless they were already set explicitly.
if !context.IsSet("experimental-offline-vulnerabilities") {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I may understand the use case a bit here: someone wants to disable all network requests but not the ones for vulnerabilities.
Also as Michael mentioned below, CompareOffline also controls others things for example license scanning, maybe we should change it to a struct with a list of booleans? Each boolean field corresponds to one type of request requiring network.
Even further, can we change experimental-offline to be a list of strings taking all or vulnerability,license and all takes precedence over all other.

@michaelkedar michaelkedar merged commit 0c43a0e into google:main Oct 24, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants