-
Notifications
You must be signed in to change notification settings - Fork 48
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
Changes from all commits
caa5747
5cb28e0
decd729
7b0821f
a33b809
98013c4
c971fe4
4cd04d3
ea6b4c6
100c961
4bfc5a6
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 |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package services | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
| "time" | ||
|
|
||
| jfrogappsconfig "github.com/jfrog/jfrog-apps-config/go" | ||
| "github.com/jfrog/jfrog-cli-security/jas" | ||
| "github.com/jfrog/jfrog-cli-security/utils" | ||
| "github.com/jfrog/jfrog-cli-security/utils/formats/sarifutils" | ||
| "github.com/jfrog/jfrog-cli-security/utils/jasutils" | ||
| "github.com/jfrog/jfrog-client-go/utils/log" | ||
| "github.com/owenrumney/go-sarif/v3/pkg/report/v210/sarif" | ||
| ) | ||
|
|
||
| const ( | ||
| servicesScannerType = "services-scan" | ||
| servicesScanCommand = "svc" | ||
| servicesDocsUrlSuffix = "services-scans" | ||
|
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 such URL as (i.e |
||
| ) | ||
|
|
||
| type ServicesScanManager struct { | ||
| scanner *jas.JasScanner | ||
|
|
||
| resultsToCompareFileName string | ||
| configFileName string | ||
| resultsFileName string | ||
| } | ||
|
Comment on lines
+22
to
+28
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. Adjust the file to have 2 ways to run (similar to the other scanners)
see |
||
|
|
||
| func RunServicesScan(scanner *jas.JasScanner, module jfrogappsconfig.Module, targetCount, threadId int, resultsToCompare ...*sarif.Run) (vulnerabilitiesResults []*sarif.Run, violationsResults []*sarif.Run, err error) { | ||
| var scannerTempDir string | ||
| if scannerTempDir, err = jas.CreateScannerTempDirectory(scanner, jasutils.Services.String(), threadId); err != nil { | ||
| return | ||
| } | ||
| servicesScanManager, err := newServicesScanManager(scanner, scannerTempDir, resultsToCompare...) | ||
| if err != nil { | ||
| return | ||
| } | ||
| startTime := time.Now() | ||
| log.Info(jas.GetStartJasScanLog(utils.ServicesScan, threadId, &module, targetCount)) | ||
| if vulnerabilitiesResults, violationsResults, err = servicesScanManager.scanner.Run(servicesScanManager, results.ScanTarget{Module: &module}); err != nil { | ||
|
Check failure on line 41 in jas/services/servicesscanner.go
|
||
| return | ||
| } | ||
| log.Info(utils.GetScanFindingsLog(utils.ServicesScan, sarifutils.GetResultsLocationCount(vulnerabilitiesResults...), startTime, threadId)) | ||
| return | ||
| } | ||
|
|
||
| func newServicesScanManager(scanner *jas.JasScanner, scannerTempDir string, resultsToCompare ...*sarif.Run) (manager *ServicesScanManager, err error) { | ||
| manager = &ServicesScanManager{ | ||
| scanner: scanner, | ||
| configFileName: filepath.Join(scannerTempDir, "config.yaml"), | ||
| resultsFileName: filepath.Join(scannerTempDir, "results.sarif"), | ||
| } | ||
| if len(resultsToCompare) == 0 { | ||
| return | ||
| } | ||
| log.Debug("Diff mode - Services results to compare provided") | ||
| manager.resultsToCompareFileName = filepath.Join(scannerTempDir, "target.sarif") | ||
| if err = jas.SaveScanResultsToCompareAsReport(manager.resultsToCompareFileName, resultsToCompare...); err != nil { | ||
| return | ||
| } | ||
|
Comment on lines
+57
to
+61
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. Make sure Diff logic is implemented in the AM (so Frogbot Scan PR can show only added issues for services). |
||
| return | ||
| } | ||
|
|
||
| func (ssm *ServicesScanManager) Run(module jfrogappsconfig.Module) (vulnerabilitiesSarifRuns []*sarif.Run, violationsSarifRuns []*sarif.Run, err error) { | ||
| if err = ssm.createConfigFile(module, ssm.scanner.ScannersExclusions.ServicesExcludePatterns, ssm.scanner.Exclusions...); err != nil { | ||
|
Check failure on line 66 in jas/services/servicesscanner.go
|
||
| return | ||
| } | ||
| if err = ssm.runAnalyzerManager(); err != nil { | ||
| return | ||
| } | ||
| return jas.ReadJasScanRunsFromFile(ssm.resultsFileName, module.SourceRoot, servicesDocsUrlSuffix, ssm.scanner.MinSeverity) | ||
|
Check failure on line 72 in jas/services/servicesscanner.go
|
||
| } | ||
|
|
||
| type servicesScanConfig struct { | ||
| Scans []servicesScanConfiguration `yaml:"scans"` | ||
| } | ||
|
|
||
| type servicesScanConfiguration struct { | ||
| Roots []string `yaml:"roots"` | ||
| Output string `yaml:"output"` | ||
| PathToResultsToCompare string `yaml:"target-result-file,omitempty"` | ||
| Type string `yaml:"type"` | ||
| SkippedDirs []string `yaml:"skipped-folders"` | ||
| } | ||
|
|
||
| func (ssm *ServicesScanManager) createConfigFile(module jfrogappsconfig.Module, centralConfigExclusions []string, exclusions ...string) error { | ||
| roots, err := jas.GetSourceRoots(module, nil) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| configFileContent := servicesScanConfig{ | ||
| Scans: []servicesScanConfiguration{ | ||
| { | ||
| Roots: roots, | ||
| Output: ssm.resultsFileName, | ||
| PathToResultsToCompare: ssm.resultsToCompareFileName, | ||
| Type: servicesScannerType, | ||
| SkippedDirs: jas.GetExcludePatterns(module, nil, centralConfigExclusions, exclusions...), | ||
|
Check failure on line 99 in jas/services/servicesscanner.go
|
||
| }, | ||
| }, | ||
| } | ||
| return jas.CreateScannersConfigFile(ssm.configFileName, configFileContent, jasutils.Services) | ||
| } | ||
|
|
||
| func (ssm *ServicesScanManager) runAnalyzerManager() error { | ||
| return ssm.scanner.AnalyzerManager.Exec(ssm.configFileName, servicesScanCommand, filepath.Dir(ssm.scanner.AnalyzerManager.AnalyzerManagerFullPath), ssm.scanner.ServerDetails, ssm.scanner.EnvVars) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -148,7 +148,8 @@ func dumpViolationsResponseToFileIfNeeded(generatedViolations *services.Violatio | |
| func convertToViolations(cmdResults *results.SecurityCommandResults, generatedViolations []services.XrayViolation) (convertedViolations violationutils.Violations, err error) { | ||
| convertedViolations = violationutils.Violations{} | ||
| for _, violation := range generatedViolations { | ||
| switch getViolationType(violation) { | ||
| violationScanType := getViolationType(violation) | ||
|
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. you should adjust: to detect the actual type between Secrets scan and Services scan results returning from Xray API |
||
| switch violationScanType { | ||
| case utils.ScaScan: | ||
| switch violation.Type { | ||
| case xrayUtils.SecurityViolation: | ||
|
|
@@ -164,9 +165,13 @@ func convertToViolations(cmdResults *results.SecurityCommandResults, generatedVi | |
| if sastViolation := convertToJasViolation(cmdResults, jasutils.Sast, violation); sastViolation != nil { | ||
| convertedViolations.Sast = append(convertedViolations.Sast, *sastViolation) | ||
| } | ||
| case utils.SecretsScan: | ||
| if secretsViolation := convertToJasViolation(cmdResults, jasutils.Secrets, violation); secretsViolation != nil { | ||
| convertedViolations.Secrets = append(convertedViolations.Secrets, *secretsViolation) | ||
| case utils.SecretsScan, utils.ServicesScan: | ||
| if exposuresViolation := convertToExposuresViolation(cmdResults, violationScanType, violation); exposuresViolation != nil { | ||
| if violationScanType == utils.SecretsScan { | ||
| convertedViolations.Secrets = append(convertedViolations.Secrets, *exposuresViolation) | ||
| } else { | ||
| convertedViolations.Services = append(convertedViolations.Services, *exposuresViolation) | ||
| } | ||
| } | ||
| default: | ||
| log.Warn(fmt.Sprintf("Skipping violation with unknown scan type for violation ID %s", violation.Id)) | ||
|
|
@@ -253,6 +258,8 @@ func getJasViolationType(jasType jasutils.JasScanType) violationutils.ViolationI | |
| return violationutils.SastViolationType | ||
| case jasutils.Secrets: | ||
| return violationutils.SecretsViolationType | ||
| case jasutils.Services: | ||
| return violationutils.ServicesViolationType | ||
| case jasutils.IaC: | ||
| return violationutils.IacViolationType | ||
| default: | ||
|
|
@@ -334,6 +341,10 @@ func locateBomVulnerabilityInfo(cmdResults *results.SecurityCommandResults, issu | |
| return | ||
| } | ||
|
|
||
| func convertToExposuresViolation(cmdResults *results.SecurityCommandResults, scanType utils.SubScanType, violation services.XrayViolation) *violationutils.JasViolation { | ||
| return convertToJasViolation(cmdResults, jasutils.SubScanTypeToJasScanType(scanType), violation) | ||
| } | ||
|
|
||
|
Comment on lines
+344
to
+347
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. why do we need this one line func? |
||
| func convertToJasViolation(cmdResults *results.SecurityCommandResults, jasType jasutils.JasScanType, violation services.XrayViolation) (jasViolations *violationutils.JasViolation) { | ||
| match := locateJasVulnerabilityInfo(cmdResults, jasType, violation) | ||
| if match.rule == nil || match.result == nil || match.location == nil { | ||
|
|
||
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.
how is Sbom related?