-
Notifications
You must be signed in to change notification settings - Fork 23
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
Apply allow-partial-results to JAS scans #223
Changes from all commits
6ff9826
65bc60f
f5fb950
011bf46
ddffb14
32597c7
c5f03d3
175c603
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,30 +181,30 @@ func RunAudit(auditParams *AuditParams) (cmdResults *results.SecurityCommandResu | |
} | ||
jfrogAppsConfig, err := jas.CreateJFrogAppsConfig(cmdResults.GetTargetsPaths()) | ||
if err != nil { | ||
return cmdResults.AddGeneralError(fmt.Errorf("failed to create JFrogAppsConfig: %s", err.Error())) | ||
return cmdResults.AddGeneralError(fmt.Errorf("failed to create JFrogAppsConfig: %s", err.Error()), false) | ||
} | ||
// Initialize the parallel runner | ||
auditParallelRunner := utils.CreateSecurityParallelRunner(auditParams.threads) | ||
// Add the JAS scans to the parallel runner | ||
var jasScanner *jas.JasScanner | ||
var generalJasScanErr error | ||
if jasScanner, generalJasScanErr = RunJasScans(auditParallelRunner, auditParams, cmdResults, jfrogAppsConfig); generalJasScanErr != nil { | ||
cmdResults.AddGeneralError(fmt.Errorf("An error has occurred during JAS scan process. JAS scan is skipped for the following directories: %s\n%s", strings.Join(cmdResults.GetTargetsPaths(), ","), generalJasScanErr.Error())) | ||
cmdResults.AddGeneralError(fmt.Errorf("An error has occurred during JAS scan process. JAS scan is skipped for the following directories: %s\n%s", strings.Join(cmdResults.GetTargetsPaths(), ","), generalJasScanErr.Error()), auditParams.AllowPartialResults()) | ||
} | ||
if auditParams.Progress() != nil { | ||
auditParams.Progress().SetHeadlineMsg("Scanning for issues") | ||
} | ||
// The sca scan doesn't require the analyzer manager, so it can run separately from the analyzer manager download routine. | ||
if generalScaScanError := buildDepTreeAndRunScaScan(auditParallelRunner, auditParams, cmdResults); generalScaScanError != nil { | ||
cmdResults.AddGeneralError(fmt.Errorf("An error has occurred during SCA scan process. SCA scan is skipped for the following directories: %s\n%s", strings.Join(cmdResults.GetTargetsPaths(), ","), generalScaScanError.Error())) | ||
cmdResults.AddGeneralError(fmt.Errorf("An error has occurred during SCA scan process. SCA scan is skipped for the following directories: %s\n%s", strings.Join(cmdResults.GetTargetsPaths(), ","), generalScaScanError.Error()), auditParams.AllowPartialResults()) | ||
} | ||
go func() { | ||
auditParallelRunner.ScaScansWg.Wait() | ||
auditParallelRunner.JasWg.Wait() | ||
// Wait for all jas scanners to complete before cleaning up scanners temp dir | ||
auditParallelRunner.JasScannersWg.Wait() | ||
if jasScanner != nil && jasScanner.ScannerDirCleanupFunc != nil { | ||
cmdResults.AddGeneralError(jasScanner.ScannerDirCleanupFunc()) | ||
cmdResults.AddGeneralError(jasScanner.ScannerDirCleanupFunc(), false) | ||
} | ||
auditParallelRunner.Runner.Done() | ||
}() | ||
|
@@ -242,7 +242,7 @@ func RunJasScans(auditParallelRunner *utils.SecurityParallelRunner, auditParams | |
} | ||
auditParallelRunner.JasWg.Add(1) | ||
if _, jasErr := auditParallelRunner.Runner.AddTaskWithError(createJasScansTasks(auditParallelRunner, scanResults, serverDetails, auditParams, jasScanner, jfrogAppsConfig), func(taskErr error) { | ||
generalError = errors.Join(generalError, fmt.Errorf("failed while adding JAS scan tasks: %s", taskErr.Error())) | ||
scanResults.AddGeneralError(fmt.Errorf("failed while adding JAS scan tasks: %s", taskErr.Error()), auditParams.AllowPartialResults()) | ||
}); jasErr != nil { | ||
generalError = fmt.Errorf("failed to create JAS task: %s", jasErr.Error()) | ||
} | ||
|
@@ -281,9 +281,12 @@ func createJasScansTasks(auditParallelRunner *utils.SecurityParallelRunner, scan | |
SignedDescriptions: auditParams.OutputFormat() == format.Sarif, | ||
ScanResults: targetResult, | ||
TargetOutputDir: auditParams.scanResultsOutputDir, | ||
AllowPartialResults: auditParams.AllowPartialResults(), | ||
} | ||
if generalError := runner.AddJasScannersTasks(params); generalError != nil { | ||
if generalError = runner.AddJasScannersTasks(params); generalError != nil { | ||
_ = targetResult.AddTargetError(fmt.Errorf("%s failed to add JAS scan tasks: %s", logPrefix, generalError.Error()), auditParams.AllowPartialResults()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bug fix. |
||
// We assign nil to 'generalError' after handling it to prevent it to propagate further, so it will not be captured twice - once here, and once in the error handling function of createJasScansTasks | ||
generalError = nil | ||
} | ||
} | ||
return | ||
|
@@ -295,20 +298,20 @@ func initAuditCmdResults(params *AuditParams) (cmdResults *results.SecurityComma | |
// Initialize general information | ||
serverDetails, err := params.ServerDetails() | ||
if err != nil { | ||
return cmdResults.AddGeneralError(err) | ||
return cmdResults.AddGeneralError(err, false) | ||
} | ||
var xrayManager *xray.XrayServicesManager | ||
if xrayManager, params.xrayVersion, err = xrayutils.CreateXrayServiceManagerAndGetVersion(serverDetails); err != nil { | ||
return cmdResults.AddGeneralError(err) | ||
return cmdResults.AddGeneralError(err, false) | ||
} else { | ||
cmdResults.SetXrayVersion(params.xrayVersion) | ||
} | ||
if err = clientutils.ValidateMinimumVersion(clientutils.Xray, params.xrayVersion, scangraph.GraphScanMinXrayVersion); err != nil { | ||
return cmdResults.AddGeneralError(err) | ||
return cmdResults.AddGeneralError(err, false) | ||
} | ||
entitledForJas, err := isEntitledForJas(xrayManager, params) | ||
if err != nil { | ||
return cmdResults.AddGeneralError(err) | ||
return cmdResults.AddGeneralError(err, false) | ||
} else { | ||
cmdResults.SetEntitledForJas(entitledForJas) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is a bug fix.
We missed capturing errors coming from the threads and tried to propagate them up the stack, where they "got lost" in the process or got override. This fix ensure we add the to the GeneralError so it will be examined later on in the process