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

Exclude JAS Scan Flag #836

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

Conversation

orto17
Copy link
Contributor

@orto17 orto17 commented Jun 25, 2023

  • All tests passed. If this feature is not already covered by the tests, I added new tests.
  • All static analysis checks passed.
  • This pull request is on the dev branch.
  • I used gofmt for formatting the code before submitting the pull request.

This PR contains the following:

  • A new flag for the audit command hat will allow the user to force a skip on a certain Jas scan.
  • Each scan that will appear in the flag will be skipped, and analyzer manager will not be executed for this scan.
  • The user will be able to include more than one scanner to skip, for example: -exclude-scan=contextual_analysis;secrets

Copy link
Member

@yahavi yahavi left a comment

Choose a reason for hiding this comment

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

Looks good @orto17!
Please consider my inline comments.

@@ -48,6 +48,9 @@ func getIacScanResults(serverDetails *config.ServerDetails, analyzerManager util
err = errors.Join(err, cleanupFunc())
}
}()
if utils.ExcludeScan(scannersToExclude, iacScanCommand) {
return nil, false, nil
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a debug level log that the IaC scan is skipped

Comment on lines 19 to +21
analyzerManagerExecuter utils.AnalyzerManagerInterface = &utils.AnalyzerManager{}
skippedDirs = []string{"**/*test*/**", "**/*venv*/**", "**/*node_modules*/**", "**/*target*/**"}
scannersToExclude = []string{}
Copy link
Member

Choose a reason for hiding this comment

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

This comment is not related to this PR, but is more general -
Please prefer not to use global variables. Instead, the recommended way is to use a new JasManager struct.

One design pattern is to pass a pointer of the struct when needed to each one of the scanners.
Another design pattern is to use inheritance/decoration, whereby every scanner contains the JasManager struct.

@@ -39,6 +41,7 @@ func GetExtendedScanResults(xrayResults []services.ScanResponse, dependencyTrees
if err = utils.CreateAnalyzerManagerLogDir(); err != nil {
return nil, err
}
scannersToExclude = strings.Split(excludeScan, ";")
Copy link
Member

Choose a reason for hiding this comment

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

Let's also trim strings to allow for example: --exclude-scan=contextual_analysis; secrets

@@ -49,6 +50,9 @@ func getSecretsScanResults(serverDetails *config.ServerDetails, analyzerManager
err = errors.Join(err, cleanupFunc())
}
}()
if utils.ExcludeScan(scannersToExclude, secretsFeatureName) {
return nil, false, nil
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a debug level log that the secret scan is skipped

Comment on lines +248 to +253
for _, s := range scansToBeExcluded {
if s == scan {
return true
}
}
return false
Copy link
Member

Choose a reason for hiding this comment

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

Can be inlined:

Suggested change
for _, s := range scansToBeExcluded {
if s == scan {
return true
}
}
return false
return slices.Contains(scansToBeExcluded, scan)

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.

2 participants