Skip to content

Commit 35dd086

Browse files
authored
Merge branch 'dev' into use-included-builds
2 parents cd96fe2 + 30c2fe0 commit 35dd086

File tree

17 files changed

+385
-238
lines changed

17 files changed

+385
-238
lines changed

cli/docs/flags.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ const (
5858
Secrets = "secrets"
5959
WithoutCA = "without-contextual-analysis"
6060

61+
auditSca = auditPrefix + Sca
62+
auditIac = auditPrefix + Iac
63+
auditSast = auditPrefix + Sast
64+
auditSecrets = auditPrefix + Secrets
65+
auditWithoutCA = auditPrefix + WithoutCA
66+
binarySca = scanPrefix + Sca
67+
binarySecrets = scanPrefix + Secrets
68+
binaryWithoutCA = scanPrefix + WithoutCA
69+
6170
// Sast related flags
6271
AddSastRules = "add-sast-rules"
6372
)
@@ -163,6 +172,7 @@ var commandFlags = map[string][]string{
163172
XrScan: {
164173
Url, user, password, accessToken, ServerId, SpecFlag, Threads, scanRecursive, scanRegexp, scanAnt,
165174
scanProjectKey, Watches, RepoPath, Licenses, Sbom, OutputFormat, Fail, ExtendedTable, BypassArchiveLimits, MinSeverity, FixableOnly, ScanVuln, InsecureTls,
175+
binarySca, binarySecrets, binaryWithoutCA, SecretValidation,
166176
},
167177
Enrich: {
168178
Url, user, password, accessToken, ServerId, Threads, InsecureTls,
@@ -171,13 +181,14 @@ var commandFlags = map[string][]string{
171181
Url, user, password, accessToken, ServerId, scanProjectKey, BuildVuln, OutputFormat, Fail, ExtendedTable, Rescan, InsecureTls, TriggerScanRetries,
172182
},
173183
DockerScan: {
174-
Url, XrayUrl, user, password, accessToken, ServerId, scanProjectKey, Watches, RepoPath, Licenses, Sbom, OutputFormat, Fail, ExtendedTable, BypassArchiveLimits, MinSeverity, FixableOnly, ScanVuln, SecretValidation, InsecureTls,
184+
Url, XrayUrl, user, password, accessToken, ServerId, scanProjectKey, Watches, RepoPath, Licenses, Sbom, OutputFormat, Fail, ExtendedTable, BypassArchiveLimits, MinSeverity, FixableOnly, ScanVuln, InsecureTls,
185+
binarySca, binarySecrets, binaryWithoutCA, SecretValidation,
175186
},
176187
Audit: {
177188
Url, XrayUrl, user, password, accessToken, ServerId, InsecureTls, scanProjectKey, Watches, RepoPath, Sbom, Licenses, OutputFormat, ExcludeTestDeps,
178189
useWrapperAudit, DepType, RequirementsFile, Fail, ExtendedTable, WorkingDirs, ExclusionsAudit, Mvn, Gradle, Npm,
179190
Pnpm, Yarn, Go, Swift, Cocoapods, Nuget, Pip, Pipenv, Poetry, MinSeverity, FixableOnly, ThirdPartyContextualAnalysis, Threads,
180-
Sca, Iac, Sast, Secrets, WithoutCA, ScanVuln, SecretValidation, OutputDir, SkipAutoInstall, AllowPartialResults, MaxTreeDepth,
191+
auditSca, auditIac, auditSast, auditSecrets, auditWithoutCA, SecretValidation, ScanVuln, OutputDir, SkipAutoInstall, AllowPartialResults, MaxTreeDepth,
181192
StaticSca, XrayLibPluginBinaryCustomPath, AnalyzerManagerCustomPath, UploadRtRepoPath,
182193
},
183194
UploadCdx: {
@@ -190,7 +201,7 @@ var commandFlags = map[string][]string{
190201
scanProjectKey, Watches, ScanVuln, Fail,
191202
// Scan params
192203
Threads, ExclusionsAudit,
193-
Sca, Iac, Sast, Secrets, WithoutCA, SecretValidation, Sbom,
204+
auditSca, auditIac, auditSast, auditSecrets, auditWithoutCA, SecretValidation, Sbom,
194205
// Output params
195206
Licenses, OutputFormat, ExtendedTable, OutputDir, UploadRtRepoPath,
196207
// Scan Logic params
@@ -314,11 +325,14 @@ var flagsMap = map[string]components.Flag{
314325
StaticSca: components.NewBoolFlag(StaticSca, "Set to true to use the new SCA engine which is based on lock files.", components.SetHiddenBoolFlag()),
315326
CurationOutput: components.NewStringFlag(OutputFormat, "Defines the output format of the command. Acceptable values are: table, json.", components.WithStrDefaultValue("table")),
316327
SolutionPath: components.NewStringFlag(SolutionPath, "Path to the .NET solution file (.sln) to use when multiple solution files are present in the directory."),
317-
Sca: components.NewBoolFlag(Sca, fmt.Sprintf("Selective scanners mode: Execute SCA (Software Composition Analysis) sub-scan. Use --%s to run both SCA and Contextual Analysis. Use --%s --%s to to run SCA. Can be combined with --%s, --%s, --%s.", Sca, Sca, WithoutCA, Secrets, Sast, Iac)),
318-
Iac: components.NewBoolFlag(Iac, fmt.Sprintf("Selective scanners mode: Execute IaC sub-scan. Can be combined with --%s, --%s and --%s.", Sca, Secrets, Sast)),
319-
Sast: components.NewBoolFlag(Sast, fmt.Sprintf("Selective scanners mode: Execute SAST sub-scan. Can be combined with --%s, --%s and --%s.", Sca, Secrets, Iac)),
320-
Secrets: components.NewBoolFlag(Secrets, fmt.Sprintf("Selective scanners mode: Execute Secrets sub-scan. Can be combined with --%s, --%s and --%s.", Sca, Sast, Iac)),
321-
WithoutCA: components.NewBoolFlag(WithoutCA, fmt.Sprintf("Selective scanners mode: Disable Contextual Analysis scanner after SCA. Relevant only with --%s flag.", Sca)),
328+
binarySca: components.NewBoolFlag(Sca, fmt.Sprintf("Selective scanners mode: Execute SCA (Software Composition Analysis) sub-scan. Use --%s to run both SCA and Contextual Analysis. Use --%s --%s to to run SCA. Can be combined with --%s.", Sca, Sca, WithoutCA, Secrets)),
329+
binarySecrets: components.NewBoolFlag(Secrets, fmt.Sprintf("Selective scanners mode: Execute Secrets sub-scan. Can be combined with --%s.", Sca)),
330+
binaryWithoutCA: components.NewBoolFlag(WithoutCA, fmt.Sprintf("Selective scanners mode: Disable Contextual Analysis scanner after SCA. Relevant only with --%s flag.", Sca)),
331+
auditSca: components.NewBoolFlag(Sca, fmt.Sprintf("Selective scanners mode: Execute SCA (Software Composition Analysis) sub-scan. Use --%s to run both SCA and Contextual Analysis. Use --%s --%s to to run SCA. Can be combined with --%s, --%s, --%s.", Sca, Sca, WithoutCA, Secrets, Sast, Iac)),
332+
auditIac: components.NewBoolFlag(Iac, fmt.Sprintf("Selective scanners mode: Execute IaC sub-scan. Can be combined with --%s, --%s and --%s.", Sca, Secrets, Sast)),
333+
auditSast: components.NewBoolFlag(Sast, fmt.Sprintf("Selective scanners mode: Execute SAST sub-scan. Can be combined with --%s, --%s and --%s.", Sca, Secrets, Iac)),
334+
auditSecrets: components.NewBoolFlag(Secrets, fmt.Sprintf("Selective scanners mode: Execute Secrets sub-scan. Can be combined with --%s, --%s and --%s.", Sca, Sast, Iac)),
335+
auditWithoutCA: components.NewBoolFlag(WithoutCA, fmt.Sprintf("Selective scanners mode: Disable Contextual Analysis scanner after SCA. Relevant only with --%s flag.", Sca)),
322336
SecretValidation: components.NewBoolFlag(SecretValidation, fmt.Sprintf("Selective scanners mode: Triggers token validation on found secrets. Relevant only with --%s flag.", Secrets)),
323337

324338
AddSastRules: components.NewStringFlag(AddSastRules, "Incorporate any additional SAST rules (in JSON format, with absolute path) into this local scan."),

cli/scancommands.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ func ScanCmd(c *components.Context) error {
297297
if c.IsFlagSet(flags.Watches) {
298298
scanCmd.SetWatches(splitByCommaAndTrim(c.GetStringFlagValue(flags.Watches)))
299299
}
300+
// Check sub-scans to perform
301+
if subScans, err := getSubScansToPreform(c); err != nil {
302+
return err
303+
} else if len(subScans) > 0 {
304+
scanCmd.SetScansToPerform(subScans)
305+
}
300306
return commandsCommon.Exec(scanCmd)
301307
}
302308

@@ -708,6 +714,12 @@ func DockerScan(c *components.Context, image string) error {
708714
return err
709715
}
710716
containerScanCommand := scan.NewDockerScanCommand()
717+
// Check sub-scans to perform
718+
if subScans, err := getSubScansToPreform(c); err != nil {
719+
return err
720+
} else if len(subScans) > 0 {
721+
containerScanCommand.SetScansToPerform(subScans)
722+
}
711723
containerScanCommand.
712724
SetImageTag(image).
713725
SetBomGenerator(indexer.NewIndexerBomGenerator()).

commands/audit/audit.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,11 @@ func prepareToScan(params *AuditParams) (cmdResults *results.SecurityCommandResu
315315
if err != nil {
316316
return cmdResults.AddGeneralError(fmt.Errorf("failed to get scan logic options: %s", err.Error()), params.AllowPartialResults())
317317
}
318-
// Initialize the BOM generator
319-
if err = params.bomGenerator.WithOptions(bomGenOptions...).PrepareGenerator(); err != nil {
320-
return cmdResults.AddGeneralError(fmt.Errorf("failed to prepare the BOM generator: %s", err.Error()), params.AllowPartialResults())
318+
// Initialize the BOM generator if needed
319+
if params.resultsContext.IncludeSbom || utils.IsScanRequested(cmdResults.CmdType, utils.ScaScan, params.scansToPerform...) {
320+
if err = params.bomGenerator.WithOptions(bomGenOptions...).PrepareGenerator(); err != nil {
321+
return cmdResults.AddGeneralError(fmt.Errorf("failed to prepare the BOM generator: %s", err.Error()), params.AllowPartialResults())
322+
}
321323
}
322324
populateScanTargets(cmdResults, params)
323325
// Initialize the SCA scan strategy

commands/audit/audit_test.go

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,7 @@ func TestAuditWithConfigProfile(t *testing.T) {
326326
}},
327327
IsDefault: false,
328328
},
329-
expectedCaApplicable: 3,
330-
expectedCaUndetermined: 6,
331-
expectedCaNotCovered: 4,
332-
expectedCaNotApplicable: 2,
329+
expectedCaNotCovered: 15,
333330
},
334331
// TODO Add testcase for Sca and Applicability with exclusions after resolving the Glob patterns issues
335332
{
@@ -550,13 +547,10 @@ func TestAuditWithConfigProfile(t *testing.T) {
550547
}},
551548
IsDefault: false,
552549
},
553-
expectedSastIssues: 4,
554-
expectedSecretsIssues: 16,
555-
expectedIacIssues: 9,
556-
expectedCaApplicable: 3,
557-
expectedCaUndetermined: 6,
558-
expectedCaNotCovered: 4,
559-
expectedCaNotApplicable: 2,
550+
expectedSastIssues: 4,
551+
expectedSecretsIssues: 16,
552+
expectedIacIssues: 9,
553+
expectedCaNotCovered: 15,
560554
},
561555
{
562556
name: "All scanners enabled but some with exclude patterns",
@@ -589,13 +583,10 @@ func TestAuditWithConfigProfile(t *testing.T) {
589583
}},
590584
IsDefault: false,
591585
},
592-
expectedSastIssues: 0,
593-
expectedSecretsIssues: 7,
594-
expectedIacIssues: 9,
595-
expectedCaApplicable: 3,
596-
expectedCaUndetermined: 6,
597-
expectedCaNotCovered: 4,
598-
expectedCaNotApplicable: 2,
586+
expectedSastIssues: 0,
587+
expectedSecretsIssues: 7,
588+
expectedIacIssues: 9,
589+
expectedCaNotCovered: 15,
599590
},
600591
}
601592
assert.NoError(t, securityTestUtils.PrepareAnalyzerManagerResource())

0 commit comments

Comments
 (0)