-
Notifications
You must be signed in to change notification settings - Fork 46
Services Scan Support #772
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
base: dev
Are you sure you want to change the base?
Changes from all commits
caa5747
5cb28e0
decd729
7b0821f
a33b809
98013c4
c971fe4
4cd04d3
ea6b4c6
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 |
|---|---|---|
|
|
@@ -98,12 +98,17 @@ func GitAuditCmd(c *components.Context) error { | |
| if err != nil { | ||
| return err | ||
| } | ||
| includeServicesDetection, err := validateServicesDetection(c) | ||
|
Collaborator
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. should be adjusted/set with |
||
| if err != nil { | ||
| return err | ||
| } | ||
| gitAuditCmd.SetSbomGenerator(sbomGenerator).SetScaScanStrategy(scaScanStrategy) | ||
| gitAuditCmd.SetViolationGenerator(violationGenerator) | ||
| gitAuditCmd.SetUploadCdxResults(uploadResults).SetRtResultRepository(c.GetStringFlagValue(flags.UploadRtRepoPath)) | ||
| gitAuditCmd.SetCustomBomGenBinaryPath(c.GetStringFlagValue(flags.XrayLibPluginBinaryCustomPath)) | ||
| gitAuditCmd.SetCustomAnalyzerManagerBinaryPath(c.GetStringFlagValue(flags.AnalyzerManagerCustomPath)) | ||
| gitAuditCmd.SetIncludeSnippetDetection(includeSnippetDetection) | ||
| gitAuditCmd.SetIncludeServicesDetection(includeServicesDetection) | ||
| // Run the command with progress bar if needed, Reporting error if Xsc service is enabled | ||
| err = reportErrorIfExists(xrayVersion, xscVersion, serverDetails, gitAuditCmd.GetProjectKey(), progressbar.ExecWithProgress(gitAuditCmd)) | ||
| return err | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -555,6 +555,10 @@ func CreateAuditCmd(c *components.Context) (string, string, *coreConfig.ServerDe | |
| if err != nil { | ||
| return "", "", nil, nil, err | ||
| } | ||
| includeServicesDetection, err := validateServicesDetection(c) | ||
|
Collaborator
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. should be adjusted/set with |
||
| if err != nil { | ||
| return "", "", nil, nil, err | ||
| } | ||
| auditCmd.SetBomGenerator(sbomGenerator).SetCustomBomGenBinaryPath(c.GetStringFlagValue(flags.XrayLibPluginBinaryCustomPath)) | ||
| auditCmd.SetScaScanStrategy(scaScanStrategy) | ||
| auditCmd.SetViolationGenerator(violationGenerator) | ||
|
|
@@ -565,6 +569,7 @@ func CreateAuditCmd(c *components.Context) (string, string, *coreConfig.ServerDe | |
| SetIncludeLicenses(c.GetBoolFlagValue(flags.Licenses)). | ||
| SetIncludeSbom(shouldIncludeSbom(c, format)). | ||
| SetIncludeSnippetDetection(includeSnippetDetection). | ||
| SetIncludeServicesDetection(includeServicesDetection). | ||
| SetFail(c.GetBoolFlagValue(flags.Fail)). | ||
| SetPrintExtendedTable(c.GetBoolFlagValue(flags.ExtendedTable)). | ||
| SetMinSeverityFilter(minSeverity). | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,6 +155,17 @@ func validateSnippetDetection(c *components.Context) (bool, error) { | |
| return true, nil | ||
| } | ||
|
|
||
| func isServicesDetectionEnabled(c *components.Context) bool { | ||
| if !c.IsFlagSet(flags.Services) { | ||
| return false | ||
| } | ||
| return c.GetBoolFlagValue(flags.Services) | ||
| } | ||
|
Comment on lines
+158
to
+163
Collaborator
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 flag for the scanner that produced issues, should be set/fetch value in getSubScansToPreform |
||
|
|
||
| func validateServicesDetection(c *components.Context) (bool, error) { | ||
| return isServicesDetectionEnabled(c), nil | ||
| } | ||
|
Comment on lines
+165
to
+167
Collaborator
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. do we need this func? don't see the point here |
||
|
|
||
| func getSubScansToPreform(c *components.Context) (subScans []utils.SubScanType, err error) { | ||
| if c.GetBoolFlagValue(flags.WithoutCA) && !c.GetBoolFlagValue(flags.Sca) { | ||
| // No CA flag provided but sca flag is not provided, error | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,17 +49,18 @@ import ( | |
| ) | ||
|
|
||
| type AuditCommand struct { | ||
| watches []string | ||
| gitRepoHttpsCloneUrl string | ||
| projectKey string | ||
| targetRepoPath string | ||
| IncludeVulnerabilities bool | ||
| IncludeLicenses bool | ||
| IncludeSbom bool | ||
| IncludeSnippetDetection bool | ||
| Fail bool | ||
| PrintExtendedTable bool | ||
| Threads int | ||
| watches []string | ||
| gitRepoHttpsCloneUrl string | ||
| projectKey string | ||
| targetRepoPath string | ||
| IncludeVulnerabilities bool | ||
| IncludeLicenses bool | ||
| IncludeSbom bool | ||
| IncludeSnippetDetection bool | ||
| IncludeServicesDetection bool | ||
|
Collaborator
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. no need for specific attribute, you have |
||
| Fail bool | ||
| PrintExtendedTable bool | ||
| Threads int | ||
| AuditParams | ||
| } | ||
|
|
||
|
|
@@ -111,6 +112,11 @@ func (auditCmd *AuditCommand) SetIncludeSnippetDetection(include bool) *AuditCom | |
| return auditCmd | ||
| } | ||
|
|
||
| func (auditCmd *AuditCommand) SetIncludeServicesDetection(include bool) *AuditCommand { | ||
| auditCmd.IncludeServicesDetection = include | ||
| return auditCmd | ||
| } | ||
|
|
||
| func (auditCmd *AuditCommand) SetFail(fail bool) *AuditCommand { | ||
| auditCmd.Fail = fail | ||
| return auditCmd | ||
|
|
@@ -127,15 +133,16 @@ func (auditCmd *AuditCommand) SetThreads(threads int) *AuditCommand { | |
| } | ||
|
|
||
| // Create a results context based on the provided parameters. resolves conflicts between the parameters based on the retrieved platform watches. | ||
| func CreateAuditResultsContext(serverDetails *config.ServerDetails, xrayVersion string, watches []string, artifactoryRepoPath, projectKey, gitRepoHttpsCloneUrl string, includeVulnerabilities, includeLicenses, includeSbom, includeSnippetDetection bool) (context results.ResultContext) { | ||
| func CreateAuditResultsContext(serverDetails *config.ServerDetails, xrayVersion string, watches []string, artifactoryRepoPath, projectKey, gitRepoHttpsCloneUrl string, includeVulnerabilities, includeLicenses, includeSbom, includeSnippetDetection, includeServicesDetection bool) (context results.ResultContext) { | ||
| context = results.ResultContext{ | ||
| RepoPath: artifactoryRepoPath, | ||
| Watches: watches, | ||
| ProjectKey: projectKey, | ||
| IncludeVulnerabilities: shouldIncludeVulnerabilities(includeVulnerabilities, watches, artifactoryRepoPath, projectKey, ""), | ||
| IncludeLicenses: includeLicenses, | ||
| IncludeSbom: includeSbom, | ||
| IncludeSnippetDetection: includeSnippetDetection, | ||
| RepoPath: artifactoryRepoPath, | ||
| Watches: watches, | ||
| ProjectKey: projectKey, | ||
| IncludeVulnerabilities: shouldIncludeVulnerabilities(includeVulnerabilities, watches, artifactoryRepoPath, projectKey, ""), | ||
| IncludeLicenses: includeLicenses, | ||
| IncludeSbom: includeSbom, | ||
| IncludeSnippetDetection: includeSnippetDetection, | ||
| IncludeServicesDetection: includeServicesDetection, | ||
| } | ||
| if err := clientutils.ValidateMinimumVersion(clientutils.Xray, xrayVersion, services.MinXrayVersionGitRepoKey); err != nil { | ||
| // Git repo key is not supported by the Xray version. | ||
|
|
@@ -187,6 +194,29 @@ func shouldIncludeSnippetDetection(params *AuditParams) bool { | |
| return strings.ToLower(os.Getenv(plugin.SnippetDetectionEnvVariable)) == "true" | ||
| } | ||
|
|
||
| func configProfileEnablesServicesScan(profile *xscservices.ConfigProfile) bool { | ||
| if profile == nil { | ||
| return false | ||
| } | ||
| for _, module := range profile.Modules { | ||
| if module.ScanConfig.ServicesScannerConfig.EnableServicesScan { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| func shouldIncludeServicesDetection(params *AuditParams) bool { | ||
| if profile := params.GetConfigProfile(); profile != nil { | ||
| for _, module := range profile.Modules { | ||
| if module.ScanConfig.ServicesScannerConfig.EnableServicesScan { | ||
| return true | ||
| } | ||
| } | ||
| } | ||
| return params.resultsContext.IncludeServicesDetection | ||
| } | ||
|
|
||
|
Comment on lines
+197
to
+219
Collaborator
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. not needed, see and adjust: (at utils/results/results.go) |
||
| func logScanPaths(workingDirs []string, isRecursiveScan bool) { | ||
| if len(workingDirs) == 0 { | ||
| return | ||
|
|
@@ -263,6 +293,7 @@ func (auditCmd *AuditCommand) Run() (err error) { | |
| auditCmd.IncludeLicenses, | ||
| auditCmd.IncludeSbom, | ||
| auditCmd.IncludeSnippetDetection, | ||
| auditCmd.IncludeServicesDetection, | ||
| )). | ||
| SetGitContext(auditCmd.GitContext()). | ||
| SetThirdPartyApplicabilityScan(auditCmd.thirdPartyApplicabilityScan). | ||
|
|
@@ -444,6 +475,12 @@ func initAuditCmdResults(params *AuditParams) (cmdResults *results.SecurityComma | |
| } | ||
| cmdResults.SetEntitledForSnippetDetection(entitledForSnippetDetection) | ||
| } | ||
| if shouldIncludeServicesDetection(params) { | ||
| if !entitledForJas { | ||
| return cmdResults.AddGeneralError(fmt.Errorf("services detection is requested but the JFrog instance is not entitled for it"), false) | ||
| } | ||
| cmdResults.SetEntitledForServicesDetection(true) | ||
| } | ||
|
Comment on lines
+478
to
+483
Collaborator
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. Not needed if the only requirements are |
||
| return | ||
| } | ||
|
|
||
|
|
@@ -485,6 +522,7 @@ func populateScanTargets(cmdResults *results.SecurityCommandResults, params *Aud | |
| bom.GenerateSbomForTarget(params.BomGenerator().WithOptions( | ||
| buildinfo.WithDescriptors(targetResult.GetDescriptors()), | ||
| xrayplugin.WithSnippetDetection(shouldIncludeSnippetDetection(params)), | ||
| xrayplugin.WithServicesDetection(shouldIncludeServicesDetection(params)), | ||
| ), | ||
| bom.SbomGeneratorParams{ | ||
| Target: targetResult, | ||
|
|
@@ -503,6 +541,9 @@ func shouldGenerateSbom(params *AuditParams) bool { | |
| if params.resultsContext.IncludeSbom { | ||
| return true | ||
| } | ||
| if shouldIncludeServicesDetection(params) { | ||
| return true | ||
| } | ||
|
Collaborator
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. how services scan related to SBOM?? |
||
| scansToPerform := params.ScansToPerform() | ||
| if slices.Contains(scansToPerform, utils.ScaScan) { | ||
| return true | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -309,6 +309,32 @@ func TestShouldGenerateSbom(t *testing.T) { | |
| }(), | ||
| expectSbom: false, | ||
| }, | ||
| { | ||
| name: "services detection only", | ||
| params: func() *AuditParams { | ||
| params := NewAuditParams().SetResultsContext(results.ResultContext{IncludeServicesDetection: true}) | ||
| params.SetScansToPerform([]utils.SubScanType{utils.SastScan}) | ||
| return params | ||
| }(), | ||
| expectSbom: true, | ||
|
Collaborator
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. how is Sbom related? |
||
| }, | ||
| { | ||
| name: "services enabled in config profile without sca", | ||
| params: func() *AuditParams { | ||
| params := NewAuditParams().SetResultsContext(results.ResultContext{}) | ||
| params.SetScansToPerform([]utils.SubScanType{utils.SastScan}) | ||
| params.SetConfigProfile(&services.ConfigProfile{ | ||
| Modules: []services.Module{{ | ||
| ScanConfig: services.ScanConfig{ | ||
| ScaScannerConfig: services.ScaScannerConfig{EnableScaScan: false}, | ||
| ServicesScannerConfig: services.ServicesScannerConfig{EnableServicesScan: true}, | ||
| }, | ||
| }}, | ||
| }) | ||
| return params | ||
| }(), | ||
| expectSbom: true, | ||
|
Collaborator
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. how is Sbom related? |
||
| }, | ||
| } | ||
|
|
||
| for _, testCase := range testCases { | ||
|
|
@@ -939,23 +965,25 @@ func TestCreateResultsContext(t *testing.T) { | |
| testCases := []struct { | ||
| name string | ||
|
|
||
| artifactoryRepoPath string | ||
| httpCloneUrl string | ||
| watches []string | ||
| jfrogProjectKey string | ||
| includeVulnerabilities bool | ||
| includeLicenses bool | ||
| includeSbom bool | ||
| includeSnippetDetection bool | ||
| artifactoryRepoPath string | ||
| httpCloneUrl string | ||
| watches []string | ||
| jfrogProjectKey string | ||
| includeVulnerabilities bool | ||
| includeLicenses bool | ||
| includeSbom bool | ||
| includeSnippetDetection bool | ||
| includeServicesDetection bool | ||
|
|
||
| expectedArtifactoryRepoPath string | ||
| expectedHttpCloneUrl string | ||
| expectedWatches []string | ||
| expectedJfrogProjectKey string | ||
| expectedIncludeVulnerabilities bool | ||
| expectedIncludeLicenses bool | ||
| expectedIncludeSbom bool | ||
| expectedIncludeSnippetDetection bool | ||
| expectedArtifactoryRepoPath string | ||
| expectedHttpCloneUrl string | ||
| expectedWatches []string | ||
| expectedJfrogProjectKey string | ||
| expectedIncludeVulnerabilities bool | ||
| expectedIncludeLicenses bool | ||
| expectedIncludeSbom bool | ||
| expectedIncludeSnippetDetection bool | ||
| expectedIncludeServicesDetection bool | ||
| }{ | ||
| { | ||
| name: "Only Vulnerabilities", | ||
|
|
@@ -995,6 +1023,12 @@ func TestCreateResultsContext(t *testing.T) { | |
| expectedIncludeVulnerabilities: true, | ||
| expectedIncludeSnippetDetection: true, | ||
| }, | ||
| { | ||
| name: "Services Detection - no violation context", | ||
| includeServicesDetection: true, | ||
| expectedIncludeVulnerabilities: true, | ||
| expectedIncludeServicesDetection: true, | ||
| }, | ||
| { | ||
| name: "All", | ||
| httpCloneUrl: validations.TestMockGitInfo.Source.GitRepoHttpsCloneUrl, | ||
|
|
@@ -1018,7 +1052,7 @@ func TestCreateResultsContext(t *testing.T) { | |
| t.Run(fmt.Sprintf("%s - %s", test.name, testCase.name), func(t *testing.T) { | ||
| mockServer, serverDetails, _ := validations.XrayServer(t, validations.MockServerParams{XrayVersion: test.xrayVersion, ReturnMockPlatformWatches: test.expectedPlatformWatches}) | ||
| defer mockServer.Close() | ||
| context := CreateAuditResultsContext(serverDetails, test.xrayVersion, testCase.watches, testCase.artifactoryRepoPath, testCase.jfrogProjectKey, testCase.httpCloneUrl, testCase.includeVulnerabilities, testCase.includeLicenses, testCase.includeSbom, testCase.includeSnippetDetection) | ||
| context := CreateAuditResultsContext(serverDetails, test.xrayVersion, testCase.watches, testCase.artifactoryRepoPath, testCase.jfrogProjectKey, testCase.httpCloneUrl, testCase.includeVulnerabilities, testCase.includeLicenses, testCase.includeSbom, testCase.includeSnippetDetection, testCase.includeServicesDetection) | ||
| assert.Equal(t, testCase.expectedArtifactoryRepoPath, context.RepoPath) | ||
| assert.Equal(t, testCase.expectedHttpCloneUrl, context.GitRepoHttpsCloneUrl) | ||
| assert.Equal(t, testCase.expectedWatches, context.Watches) | ||
|
|
@@ -1027,6 +1061,7 @@ func TestCreateResultsContext(t *testing.T) { | |
| assert.Equal(t, testCase.expectedIncludeLicenses, context.IncludeLicenses) | ||
| assert.Equal(t, testCase.expectedIncludeSbom, context.IncludeSbom) | ||
| assert.Equal(t, testCase.expectedIncludeSnippetDetection, context.IncludeSnippetDetection) | ||
| assert.Equal(t, testCase.expectedIncludeServicesDetection, context.IncludeServicesDetection) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,7 @@ func toAuditParams(params GitAuditParams) *sourceAudit.AuditParams { | |
| params.resultsContext.IncludeLicenses, | ||
| params.includeSbom, | ||
| params.resultsContext.IncludeSnippetDetection, | ||
| params.resultsContext.IncludeServicesDetection, | ||
|
Collaborator
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. Same comments as for audit, not needed for |
||
| ) | ||
| auditParams.SetResultsContext(resultContext) | ||
| log.Debug(fmt.Sprintf("Results context: %+v", resultContext)) | ||
|
|
||
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.
Do we want this to be similar to
--sbom/--license/--snippetflags? or grouped with--secrets/--sca/--iac... kind of flags?.right now seems similar to the first group but PR shows like the other type...
make sure description is approbed by tech writer, see similar flags for template