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: improve reliability around call graph generation #1276

Merged

Conversation

muscar
Copy link
Contributor

@muscar muscar commented Jul 17, 2020

  • Ready for review
  • Follows CONTRIBUTING rules
  • Reviewed by Snyk internal team

What does this PR do?

This is meant to improve the experience around reachable vulns by:

  • giving control to the CLI on how long the call graph generator can run;
  • running the user command (e.g. monitor, test) even if the call graph generation failed;
  • allowing for better error messages is the call graph generation fails.

Merge after snyk/snyk-cli-interface#36 and snyk/snyk-mvn-plugin#73, and after updating the dependencies to the appropriate versions.

What are the relevant tickets?

https://snyksec.atlassian.net/browse/FLOW-336

Screenshots

Running with a timeout:

step1

Running with a timeout and passing -d:

step2

@muscar muscar requested a review from darmalovan July 17, 2020 11:23
src/lib/types.ts Outdated
@@ -91,6 +92,7 @@ export interface MonitorOptions {
// Used with the Docker plugin only. Allows application scanning.
'app-vulns'?: boolean;
reachableVulns?: boolean;
callGraphBuilderTimeout?: number;

Choose a reason for hiding this comment

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

Nice!

@darmalovan
Copy link

@muscar nice! how should the usage of the timeout from the user perspective should look like?

@muscar muscar force-pushed the fix/flow-336-call-graph-generation-reliability-improvements branch from 7fb307a to 34f53d4 Compare July 20, 2020 13:53
@muscar muscar marked this pull request as ready for review July 20, 2020 13:53
@muscar muscar requested review from a team as code owners July 20, 2020 13:53
@ghost ghost requested review from MegaBean and orsagie July 20, 2020 13:53
@muscar muscar force-pushed the fix/flow-336-call-graph-generation-reliability-improvements branch from 34f53d4 to 081577a Compare July 20, 2020 13:56
src/lib/types.ts Outdated Show resolved Hide resolved
@darmalovan
Copy link

@muscar can you add screenshot on the pr description?

@muscar muscar force-pushed the fix/flow-336-call-graph-generation-reliability-improvements branch from 081577a to e1768aa Compare July 20, 2020 14:58
@muscar muscar requested a review from darmalovan July 20, 2020 15:00
help/help.txt Outdated Show resolved Hide resolved
help/help.txt Outdated Show resolved Hide resolved
help/help.txt Outdated Show resolved Hide resolved
@@ -213,7 +218,17 @@ async function monitorDepTree(
depTree = dropEmptyDeps(depTree);

let callGraphPayload;
if (scannedProject.callGraph) {
if (options.reachableVulns && scannedProject.callGraph?.innerError) {
const err = scannedProject.callGraph as CallGraphError;

Choose a reason for hiding this comment

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

I think the as as CallGraphError is not needed now, but maybe help in reading?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you elaborate on the different kinds of errors? If it's a timeout error, a permissions error, or something else. Each one will have a different action the user can take before contacting us

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@orsagie We don't have enough context in the CLI right now to elaborate--because we only have a generic CallGraphError with a generic string message, and an inner error. Since string messages can change, I don't think inspecting those to glean more info is a good idea, because it leads to brittle code.

I do agree with your point that it's good to provide users with a more detailed reason for the failure so they can provide that info to support.

I see two ways of achieving this:

  1. Change the error message to tell them to re-run the command with -d, and provide the output in their support query; or
  2. Change the error message in the maven plugin to something less generic, and more error specific.

I would personally prefer the first approach as the code in the plugin doesn't have to change as new error cases appear, and we'll be getting almost the same info anyway. What do you think?

Copy link
Contributor

@orsagie orsagie Jul 21, 2020

Choose a reason for hiding this comment

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

Just noticed I didn't comment in the right place, this comment's place is after the request to registry has been made, and regards how we handle those responses.

This error handling is specifically for after a call to the plugins, and in that case I agree with point 1. I think the error from maven plugin already asks to run with -d, can you double check? might not need to change anything here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The maven plugin doesn't print the -d advice, but I will open a PR to make it do so.

@muscar muscar force-pushed the fix/flow-336-call-graph-generation-reliability-improvements branch 2 times, most recently from e9fdab8 to d64ac7f Compare July 20, 2020 15:52
help/help.txt Outdated
@@ -90,6 +90,13 @@ Maven options:
--scan-all-unmanaged
Auto detects maven jars and wars in given directory.
Individual testing can be done with --file=<jar-file-name>
--reachable-vulns Try to analyze the application in order to find which of

Choose a reason for hiding this comment

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

I see other flags have a new line after the flag

Choose a reason for hiding this comment

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

Also, can add like others
(test and monitor command only)

Choose a reason for hiding this comment

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

Can you write that is only available for paid users?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am a little uneasy about adding a flag for paid users only. In the past we have checked against feature flags, but eventually released to all. Maybe instead display an error saying something like This feature is not available for this org, please contact us if you wish to use it?

Choose a reason for hiding this comment

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

This is static text - rather not to share this info in the help text?

Copy link
Contributor

Choose a reason for hiding this comment

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

Then do it in both places. They might not be targeting the correct org?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought the plan is to roll this to free users at some point, right? And we already have a feature flag which we check for, and show a message. We could change the feature flag message slightly to say that this is a paid feature only (for now)?

cc/ @orsagie @darmalovan

help/help.txt Outdated
--reachable-vulns Try to analyze the application in order to find which of
the vulnerabe functions and packages are actually called
by client code.
--reachable-vulns-timeout The amount of time (in seconds) to wait for the

Choose a reason for hiding this comment

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

--reachable-vulns-timeout=<number> ? (and new line)

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a case where users want different timeouts for different cases? Consider allowing to set a longer default in the config? (maybe not for now, but in future)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@orsagie I don't know. I think this is highly project specific, so the users are in the best position to tweak it as needed. We provide a default just because we don't want it to block their flows for too long.

@@ -218,10 +221,15 @@ export function args(rawArgv: string[]): Args {
}
}

if (argv.reachableVulnsTimeout === undefined) {
argv.reachableVulnsTimeout = REACHABLE_VULNS_TIMEOUT.toString();

Choose a reason for hiding this comment

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

Why toString btw?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@darmalovan Because WebStorm (and typescript) complains that the value can't be a number.

@muscar muscar force-pushed the fix/flow-336-call-graph-generation-reliability-improvements branch from d64ac7f to d47e4b0 Compare July 21, 2020 09:27
@CLAassistant
Copy link

CLAassistant commented Jul 21, 2020

CLA assistant check
All committers have signed the CLA.

@muscar muscar force-pushed the fix/flow-336-call-graph-generation-reliability-improvements branch from d47e4b0 to 8bb2c7b Compare July 21, 2020 09:30
@muscar muscar force-pushed the fix/flow-336-call-graph-generation-reliability-improvements branch 2 times, most recently from 3d5c805 to 8e17159 Compare July 21, 2020 10:27
help/help.txt Outdated Show resolved Hide resolved
@muscar muscar force-pushed the fix/flow-336-call-graph-generation-reliability-improvements branch from 8e17159 to 97c6817 Compare July 21, 2020 11:56
Copy link
Contributor

@orsagie orsagie left a comment

Choose a reason for hiding this comment

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

small typo, but otherwise the changes LGTM now.

@muscar muscar force-pushed the fix/flow-336-call-graph-generation-reliability-improvements branch from 97c6817 to 907a9f7 Compare July 21, 2020 12:29
@muscar muscar force-pushed the fix/flow-336-call-graph-generation-reliability-improvements branch 2 times, most recently from 0b4eb38 to 495e096 Compare July 21, 2020 16:01
@muscar muscar force-pushed the fix/flow-336-call-graph-generation-reliability-improvements branch from 495e096 to 44fc1e8 Compare July 21, 2020 16:07
@github-actions
Copy link
Contributor

github-actions bot commented Jul 21, 2020

Expected release notes (by @muscar)

fixes:
improve reliability around call graph generation (44fc1e8)

  • I hereby acknowledge these release notes are 🥙 AWESOME 🥙

@muscar muscar merged commit c70c657 into master Jul 22, 2020
@muscar muscar deleted the fix/flow-336-call-graph-generation-reliability-improvements branch July 22, 2020 07:43
@snyksec
Copy link

snyksec commented Jul 22, 2020

🎉 This PR is included in version 1.364.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

6 participants