@@ -110,6 +110,10 @@ const (
110
110
"\n To use this feature, you would need to purchase a license." +
111
111
"\n Please contact our support team for assistance if you believe you have already purchased a license." +
112
112
"\n Licensed packages: %s"
113
+ engineScsNotAllowed = "You are trying to run a scan with the \" scs\" scan type. This requires either the \" repository‑health\" or the \" secret‑detection\" package license, depending on which scanner you are running." +
114
+ "\n To use this feature, you need to purchase the appropriate license." +
115
+ "\n If you think that you have already purchased the relevant license, please contact our support team for assistance." +
116
+ "\n Licensed packages: %s"
113
117
containerResolutionFileName = "containers-resolution.json"
114
118
directoryCreationPrefix = "cx-"
115
119
ScsScoreCardType = "scorecard"
@@ -986,7 +990,9 @@ func setupScanTypeProjectAndConfig(
986
990
configArr = append (configArr , containersConfig )
987
991
}
988
992
989
- var SCSConfig , scsErr = addSCSScan (cmd , resubmitConfig , userAllowedEngines [commonParams .EnterpriseSecretsType ])
993
+ scsLicensingV2Flag , _ := wrappers .GetSpecificFeatureFlag (featureFlagsWrapper , wrappers .ScsLicensingV2Enabled )
994
+ var SCSConfig , scsErr = addSCSScan (cmd , resubmitConfig , scsLicensingV2Flag .Status , userAllowedEngines [commonParams .RepositoryHealthType ],
995
+ userAllowedEngines [commonParams .SecretDetectionType ], userAllowedEngines [commonParams .EnterpriseSecretsType ])
990
996
if scsErr != nil {
991
997
return scsErr
992
998
} else if SCSConfig != nil {
@@ -1267,17 +1273,18 @@ func addAPISecScan(cmd *cobra.Command) map[string]interface{} {
1267
1273
return nil
1268
1274
}
1269
1275
1270
- func createResubmitConfig (resubmitConfig []wrappers.Config , scsRepoToken , scsRepoURL string , hasEnterpriseSecretsLicense bool ) wrappers.SCSConfig {
1276
+ func createResubmitConfig (resubmitConfig []wrappers.Config , scsRepoToken , scsRepoURL string , isScsSecretDetectionAllowed ,
1277
+ isScsScorecardAllowed bool ) wrappers.SCSConfig {
1271
1278
scsConfig := wrappers.SCSConfig {}
1272
1279
for _ , config := range resubmitConfig {
1273
1280
resubmitTwoms := config .Value [configTwoms ]
1274
- if resubmitTwoms != nil && hasEnterpriseSecretsLicense {
1281
+ if resubmitTwoms != nil && isScsSecretDetectionAllowed {
1275
1282
scsConfig .Twoms = resubmitTwoms .(string )
1276
1283
}
1277
1284
scsConfig .RepoURL = scsRepoURL
1278
1285
scsConfig .RepoToken = scsRepoToken
1279
1286
resubmitScoreCard := config .Value [ScsScoreCardType ]
1280
- if resubmitScoreCard == trueString && scsRepoToken != "" && scsRepoURL != "" {
1287
+ if resubmitScoreCard == trueString && scsRepoToken != "" && scsRepoURL != "" && isScsScorecardAllowed {
1281
1288
scsConfig .Scorecard = trueString
1282
1289
} else {
1283
1290
scsConfig .Scorecard = falseString
@@ -1330,8 +1337,12 @@ func isScorecardRunnable(isScsEnginesFlagSet, scsScorecardSelected bool, scsRepo
1330
1337
return isURLSupportedByScorecard (scsRepoURL ), nil
1331
1338
}
1332
1339
1333
- func addSCSScan (cmd * cobra.Command , resubmitConfig []wrappers.Config , hasEnterpriseSecretsLicense bool ) (map [string ]interface {}, error ) {
1334
- if ! scanTypeEnabled (commonParams .ScsType ) && ! scanTypeEnabled (commonParams .MicroEnginesType ) {
1340
+ func addSCSScan (cmd * cobra.Command , resubmitConfig []wrappers.Config , scsLicensingV2 , hasRepositoryHealthLicense ,
1341
+ hasSecretDetectionLicense , hasEnterpriseSecretsLicense bool ) (map [string ]interface {}, error ) {
1342
+ scsEnabled := scanTypeEnabled (commonParams .ScsType )
1343
+ scsScorecardAllowed := isScsScorecardAllowed (scsLicensingV2 , hasRepositoryHealthLicense , scsEnabled )
1344
+ scsSecretDetectionAllowed := isScsSecretDetectionAllowed (scsLicensingV2 , hasSecretDetectionLicense , hasEnterpriseSecretsLicense , scsEnabled )
1345
+ if ! scsScorecardAllowed && ! scsSecretDetectionAllowed {
1335
1346
return nil , nil
1336
1347
}
1337
1348
scsConfig := wrappers.SCSConfig {}
@@ -1352,20 +1363,20 @@ func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config, hasEnterpr
1352
1363
scsEngines , _ := cmd .Flags ().GetString (commonParams .SCSEnginesFlag )
1353
1364
1354
1365
if resubmitConfig != nil {
1355
- scsConfig = createResubmitConfig (resubmitConfig , scsRepoToken , scsRepoURL , hasEnterpriseSecretsLicense )
1366
+ scsConfig = createResubmitConfig (resubmitConfig , scsRepoToken , scsRepoURL , scsSecretDetectionAllowed , scsScorecardAllowed )
1356
1367
scsMapConfig [resultsMapValue ] = & scsConfig
1357
1368
return scsMapConfig , nil
1358
1369
}
1359
1370
1360
1371
scsScoreCardSelected , scsSecretDetectionSelected := getSCSEnginesSelected (scsEngines ) // secret-detection or scorecard
1361
1372
1362
- if scsSecretDetectionSelected && hasEnterpriseSecretsLicense {
1373
+ if scsSecretDetectionSelected && scsSecretDetectionAllowed {
1363
1374
scsConfig .Twoms = trueString
1364
1375
}
1365
1376
1366
1377
isScsEnginesFlagSet := scsEngines != ""
1367
1378
1368
- if scsScoreCardSelected {
1379
+ if scsScoreCardSelected && scsScorecardAllowed {
1369
1380
canRunScorecard , err := isScorecardRunnable (isScsEnginesFlagSet , scsScoreCardSelected , scsRepoToken , scsRepoURL , userScanTypes )
1370
1381
if err != nil {
1371
1382
return nil , err
@@ -1386,25 +1397,39 @@ func addSCSScan(cmd *cobra.Command, resubmitConfig []wrappers.Config, hasEnterpr
1386
1397
return scsMapConfig , nil
1387
1398
}
1388
1399
1400
+ func isScsScorecardAllowed (scsLicensingV2 , hasRepositoryHealthLicense , hasScsLicense bool ) bool {
1401
+ if scsLicensingV2 {
1402
+ return hasRepositoryHealthLicense
1403
+ }
1404
+ return hasScsLicense
1405
+ }
1406
+
1407
+ func isScsSecretDetectionAllowed (scsLicensingV2 , hasSecretDetectionLicense , hasEnterpriseSecretsLicense , hasScsLicense bool ) bool {
1408
+ if scsLicensingV2 {
1409
+ return hasSecretDetectionLicense
1410
+ }
1411
+ return hasScsLicense && hasEnterpriseSecretsLicense
1412
+ }
1413
+
1389
1414
func validateScanTypes (cmd * cobra.Command , jwtWrapper wrappers.JWTWrapper , featureFlagsWrapper wrappers.FeatureFlagsWrapper ) error {
1390
1415
var scanTypes []string
1391
- var SCSScanTypes []string
1392
1416
1393
- isSbomScan , _ := cmd . PersistentFlags (). GetBool ( commonParams . SbomFlag )
1417
+ scsLicensingV2Flag , _ := wrappers . GetSpecificFeatureFlag ( featureFlagsWrapper , wrappers . ScsLicensingV2Enabled )
1394
1418
1395
1419
allowedEngines , err := jwtWrapper .GetAllowedEngines (featureFlagsWrapper )
1420
+
1421
+ isSbomScan , _ := cmd .PersistentFlags ().GetBool (commonParams .SbomFlag )
1422
+
1396
1423
if err != nil {
1397
1424
err = errors .Errorf ("Error validating scan types: %v" , err )
1398
1425
return err
1399
1426
}
1400
1427
1401
1428
userScanTypes , _ := cmd .Flags ().GetString (commonParams .ScanTypes )
1402
- userSCSScanTypes , _ := cmd .Flags ().GetString (commonParams .SCSEnginesFlag )
1403
1429
if len (userScanTypes ) > 0 {
1404
1430
userScanTypes = strings .ReplaceAll (strings .ToLower (userScanTypes ), " " , "" )
1405
1431
userScanTypes = strings .Replace (strings .ToLower (userScanTypes ), commonParams .KicsType , commonParams .IacType , 1 )
1406
1432
userScanTypes = strings .Replace (strings .ToLower (userScanTypes ), commonParams .ContainersTypeFlag , commonParams .ContainersType , 1 )
1407
- userSCSScanTypes = strings .Replace (strings .ToLower (userSCSScanTypes ), commonParams .SCSEnginesFlag , commonParams .ScsType , 1 )
1408
1433
1409
1434
scanTypes = strings .Split (userScanTypes , "," )
1410
1435
@@ -1422,18 +1447,26 @@ func validateScanTypes(cmd *cobra.Command, jwtWrapper wrappers.JWTWrapper, featu
1422
1447
}
1423
1448
1424
1449
for _ , scanType := range scanTypes {
1450
+ if scanType == commonParams .ScsType && scsLicensingV2Flag .Status {
1451
+ // the SCS scan type is a special case because it contains two engines.
1452
+ // Before the new licensing model, the main license was named "scs".
1453
+ // Licenses are now separated for each engine, so this validation no longer makes sense.
1454
+ // See validateSCSEngines.
1455
+ continue
1456
+ }
1425
1457
if ! allowedEngines [scanType ] {
1426
1458
keys := reflect .ValueOf (allowedEngines ).MapKeys ()
1427
1459
err = errors .Errorf (engineNotAllowed , scanType , scanType , keys )
1428
1460
return err
1429
1461
}
1430
1462
}
1431
1463
1432
- SCSScanTypes = strings .Split (userSCSScanTypes , "," )
1433
- if slices .Contains (SCSScanTypes , ScsSecretDetectionType ) && ! allowedEngines [commonParams .EnterpriseSecretsType ] {
1434
- keys := reflect .ValueOf (allowedEngines ).MapKeys ()
1435
- err = errors .Errorf (engineNotAllowed , ScsSecretDetectionType , ScsSecretDetectionType , keys )
1436
- return err
1464
+ userSCSScanTypes , _ := cmd .Flags ().GetString (commonParams .SCSEnginesFlag )
1465
+ if slices .Contains (scanTypes , commonParams .ScsType ) {
1466
+ err = validateSCSEngines (allowedEngines , userSCSScanTypes , scsLicensingV2Flag .Status )
1467
+ if err != nil {
1468
+ return err
1469
+ }
1437
1470
}
1438
1471
} else {
1439
1472
if isSbomScan {
@@ -1455,6 +1488,25 @@ func validateScanTypes(cmd *cobra.Command, jwtWrapper wrappers.JWTWrapper, featu
1455
1488
return nil
1456
1489
}
1457
1490
1491
+ func validateSCSEngines (allowedEngines map [string ]bool , userSCSScanTypes string , scsLicensingV2 bool ) error {
1492
+ licensesAvailable := reflect .ValueOf (allowedEngines ).MapKeys ()
1493
+ scsScanTypes := strings .Split (userSCSScanTypes , "," )
1494
+ if scsLicensingV2 {
1495
+ secretDetectionAllowed := allowedEngines [commonParams .SecretDetectionType ]
1496
+ repositoryHeatlhAllowed := allowedEngines [commonParams .RepositoryHealthType ]
1497
+ if userSCSScanTypes == "" && ! secretDetectionAllowed && ! repositoryHeatlhAllowed {
1498
+ return errors .Errorf (engineScsNotAllowed , licensesAvailable )
1499
+ } else if slices .Contains (scsScanTypes , ScsSecretDetectionType ) && ! secretDetectionAllowed {
1500
+ return errors .Errorf (engineNotAllowed , commonParams .SecretDetectionType , commonParams .SecretDetectionType , licensesAvailable )
1501
+ } else if slices .Contains (scsScanTypes , ScsScoreCardType ) && ! repositoryHeatlhAllowed {
1502
+ return errors .Errorf (engineNotAllowed , commonParams .RepositoryHealthType , commonParams .RepositoryHealthType , licensesAvailable )
1503
+ }
1504
+ } else if slices .Contains (scsScanTypes , ScsSecretDetectionType ) && ! allowedEngines [commonParams .EnterpriseSecretsType ] {
1505
+ return errors .Errorf (engineNotAllowed , ScsSecretDetectionType , ScsSecretDetectionType , licensesAvailable )
1506
+ }
1507
+ return nil
1508
+ }
1509
+
1458
1510
func scanTypeEnabled (scanType string ) bool {
1459
1511
scanTypes := strings .Split (actualScanTypes , "," )
1460
1512
for _ , a := range scanTypes {
0 commit comments