@@ -53,50 +53,54 @@ const (
5353 notExploitable = "NOT_EXPLOITABLE"
5454 ignored = "IGNORED"
5555
56- git = "git"
57- invalidSSHSource = "provided source does not need a key. Make sure you are defining the right source or remove the flag --ssh-key"
58- errorUnzippingFile = "an error occurred while unzipping file. Reason: "
59- containerRun = "run"
60- containerVolumeFlag = "-v"
61- containerNameFlag = "--name"
62- containerRemove = "--rm"
63- containerImage = "checkmarx/kics:v2.1.3"
64- containerScan = "scan"
65- containerScanPathFlag = "-p"
66- containerScanPath = "/path"
67- containerScanOutputFlag = "-o"
68- containerScanOutput = "/path"
69- containerScanFormatFlag = "--report-formats"
70- containerScanFormatOutput = "json"
71- containerStarting = "Starting kics container"
72- containerFormatInfo = "The report format and output path cannot be overridden."
73- containerFolderRemoving = "Removing folder in temp"
74- containerCreateFolderError = "Error creating temporary directory"
75- containerWriteFolderError = " Error writing file to temporary directory"
76- containerFileSourceMissing = "--file is required for kics-realtime command"
77- containerFileSourceIncompatible = ". Provided file is not supported by kics"
78- containerFileSourceError = " Error reading file"
79- containerResultsFileFormat = "%s/results.json"
80- containerVolumeFormat = "%s:/path"
81- containerTempDirPattern = "kics"
82- kicsContainerPrefixName = "cli-kics-realtime-"
83- cleanupMaxRetries = 3
84- cleanupRetryWaitSeconds = 15
85- DanglingSymlinkError = "Skipping dangling symbolic link"
86- configFilterKey = "filter"
87- configFilterPlatforms = "platforms"
88- configIncremental = "incremental"
89- configFastScan = "fastScanMode"
90- configPresetName = "presetName"
91- configEngineVerbose = "engineVerbose"
92- configLanguageMode = "languageMode"
93- resultsMapValue = "value"
94- resultsMapType = "type"
95- trueString = "true"
96- configTwoms = "2ms"
97- falseString = "false"
98- maxPollingWaitTime = 60
99- engineNotAllowed = "It looks like the \" %s\" scan type does not exist or you are trying to run a scan without the \" %s\" package license." +
56+ git = "git"
57+ invalidSSHSource = "provided source does not need a key. Make sure you are defining the right source or remove the flag --ssh-key"
58+ errorUnzippingFile = "an error occurred while unzipping file. Reason: "
59+ containerRun = "run"
60+ containerVolumeFlag = "-v"
61+ containerNameFlag = "--name"
62+ containerRemove = "--rm"
63+ containerImage = "checkmarx/kics:v2.1.3"
64+ containerScan = "scan"
65+ containerScanPathFlag = "-p"
66+ containerScanPath = "/path"
67+ containerScanOutputFlag = "-o"
68+ containerScanOutput = "/path"
69+ containerScanFormatFlag = "--report-formats"
70+ containerScanFormatOutput = "json"
71+ containerStarting = "Starting kics container"
72+ containerFormatInfo = "The report format and output path cannot be overridden."
73+ containerFolderRemoving = "Removing folder in temp"
74+ containerCreateFolderError = "Error creating temporary directory"
75+ containerWriteFolderError = " Error writing file to temporary directory"
76+ containerFileSourceMissing = "--file is required for kics-realtime command"
77+ containerFileSourceIncompatible = ". Provided file is not supported by kics"
78+ containerFileSourceError = " Error reading file"
79+ containerResultsFileFormat = "%s/results.json"
80+ containerVolumeFormat = "%s:/path"
81+ containerTempDirPattern = "kics"
82+ kicsContainerPrefixName = "cli-kics-realtime-"
83+ cleanupMaxRetries = 3
84+ cleanupRetryWaitSeconds = 15
85+ DanglingSymlinkError = "Skipping dangling symbolic link"
86+ configFilterKey = "filter"
87+ configFilterPlatforms = "platforms"
88+ configIncremental = "incremental"
89+ configFastScan = "fastScanMode"
90+ configPresetName = "presetName"
91+ configEngineVerbose = "engineVerbose"
92+ configLanguageMode = "languageMode"
93+ ConfigContainersFilesFilterKey = "filesFilter"
94+ ConfigContainersImagesFilterKey = "imagesFilter"
95+ ConfigContainersPackagesFilterKey = "packagesFilter"
96+ ConfigContainersNonFinalStagesFilterKey = "nonFinalStagesFilter"
97+ resultsMapValue = "value"
98+ resultsMapType = "type"
99+ trueString = "true"
100+ configTwoms = "2ms"
101+ falseString = "false"
102+ maxPollingWaitTime = 60
103+ engineNotAllowed = "It looks like the \" %s\" scan type does not exist or you are trying to run a scan without the \" %s\" package license." +
100104 "\n To use this feature, you would need to purchase a license." +
101105 "\n Please contact our support team for assistance if you believe you have already purchased a license." +
102106 "\n Licensed packages: %s"
@@ -657,6 +661,12 @@ func scanCreateSubCommand(
657661 createScanCmd .PersistentFlags ().String (commonParams .SCSEnginesFlag , "" , "Specify which scs engines will run (default: all licensed engines)" )
658662 createScanCmd .PersistentFlags ().Bool (commonParams .ScaHideDevAndTestDepFlag , false , scaHideDevAndTestDepFlagDescription )
659663
664+ // Container config flags
665+ createScanCmd .PersistentFlags ().String (commonParams .ContainersFileFolderFilterFlag , "" , "Specify files and folders to be included or excluded from scans, ex: \" !*.log\" " )
666+ createScanCmd .PersistentFlags ().String (commonParams .ContainersPackageFilterFlag , "" , "Exclude packages by package name or file path using regex, ex: \" ^internal-.*\" " )
667+ createScanCmd .PersistentFlags ().Bool (commonParams .ContainersExcludeNonFinalStagesFlag , false , "Scan only the final deployable image" )
668+ createScanCmd .PersistentFlags ().String (commonParams .ContainersImageTagFilterFlag , "" , "Exclude images by image name and/or tag, ex: \" *dev\" " )
669+
660670 return createScanCmd
661671}
662672
@@ -764,7 +774,7 @@ func setupScanTypeProjectAndConfig(
764774 if apiSecConfig != nil {
765775 configArr = append (configArr , apiSecConfig )
766776 }
767- var containersConfig = addContainersScan (containerEngineCLIEnabled .Status )
777+ var containersConfig = addContainersScan (cmd , resubmitConfig , containerEngineCLIEnabled .Status )
768778 if containersConfig != nil {
769779 configArr = append (configArr , containersConfig )
770780 }
@@ -935,19 +945,61 @@ func addScaScan(cmd *cobra.Command, resubmitConfig []wrappers.Config, hasContain
935945 return nil
936946}
937947
938- func addContainersScan (containerEngineCLIEnabled bool ) map [string ]interface {} {
948+ func addContainersScan (cmd * cobra. Command , resubmitConfig []wrappers. Config , containerEngineCLIEnabled bool ) map [string ]interface {} {
939949 if ! scanTypeEnabled (commonParams .ContainersType ) || ! containerEngineCLIEnabled {
940950 return nil
941951 }
942952 containerMapConfig := make (map [string ]interface {})
943953 containerMapConfig [resultsMapType ] = commonParams .ContainersType
944-
945954 containerConfig := wrappers.ContainerConfig {}
946955
956+ initializeContainersConfigWithResubmitValues (resubmitConfig , & containerConfig )
957+
958+ fileFolderFilter , _ := cmd .PersistentFlags ().GetString (commonParams .ContainersFileFolderFilterFlag )
959+ if fileFolderFilter != "" {
960+ containerConfig .FilesFilter = fileFolderFilter
961+ }
962+ packageFilter , _ := cmd .PersistentFlags ().GetString (commonParams .ContainersPackageFilterFlag )
963+ if packageFilter != "" {
964+ containerConfig .PackagesFilter = packageFilter
965+ }
966+ excludeNonFinalStages , _ := cmd .PersistentFlags ().GetBool (commonParams .ContainersExcludeNonFinalStagesFlag )
967+ if cmd .PersistentFlags ().Changed (commonParams .ContainersExcludeNonFinalStagesFlag ) {
968+ containerConfig .NonFinalStagesFilter = strconv .FormatBool (excludeNonFinalStages )
969+ }
970+ imageTagFilter , _ := cmd .Flags ().GetString (commonParams .ContainersImageTagFilterFlag )
971+ if imageTagFilter != "" {
972+ containerConfig .ImagesFilter = imageTagFilter
973+ }
974+
947975 containerMapConfig [resultsMapValue ] = & containerConfig
948976 return containerMapConfig
949977}
950978
979+ func initializeContainersConfigWithResubmitValues (resubmitConfig []wrappers.Config , containerConfig * wrappers.ContainerConfig ) {
980+ for _ , config := range resubmitConfig {
981+ if config .Type != commonParams .ContainersType {
982+ continue
983+ }
984+ resubmitFilesFilter := config .Value [ConfigContainersFilesFilterKey ]
985+ if resubmitFilesFilter != nil && resubmitFilesFilter != "" {
986+ containerConfig .FilesFilter = resubmitFilesFilter .(string )
987+ }
988+ resubmitPackagesFilter := config .Value [ConfigContainersPackagesFilterKey ]
989+ if resubmitPackagesFilter != nil && resubmitPackagesFilter != "" {
990+ containerConfig .PackagesFilter = resubmitPackagesFilter .(string )
991+ }
992+ resubmitNonFinalStagesFilter := config .Value [ConfigContainersNonFinalStagesFilterKey ]
993+ if resubmitNonFinalStagesFilter != nil && resubmitNonFinalStagesFilter != "" {
994+ containerConfig .NonFinalStagesFilter = resubmitNonFinalStagesFilter .(string )
995+ }
996+ resubmitImagesFilter := config .Value [ConfigContainersImagesFilterKey ]
997+ if resubmitImagesFilter != nil && resubmitImagesFilter != "" {
998+ containerConfig .ImagesFilter = resubmitImagesFilter .(string )
999+ }
1000+ }
1001+ }
1002+
9511003func addAPISecScan (cmd * cobra.Command ) map [string ]interface {} {
9521004 if scanTypeEnabled (commonParams .APISecurityType ) {
9531005 apiSecMapConfig := make (map [string ]interface {})
0 commit comments