-
Notifications
You must be signed in to change notification settings - Fork 25
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
CLI | Support Container Engine Scan (AST-36237, AST-36236, AST-36238) #672
Conversation
Policy Management Violations
New Issues
|
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.
Great work!
internal/commands/scan.go
Outdated
@@ -185,6 +189,7 @@ func NewScanCommand( | |||
kicsRealtimeCmd := scanRealtimeSubCommand() | |||
|
|||
scaRealtimeCmd := scarealtime.NewScaRealtimeCommand(scaRealTimeWrapper) | |||
containerResolver = containerResolverWrapper |
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.
move it to the start of the method
internal/commands/scan.go
Outdated
@@ -502,7 +509,8 @@ func scanCreateSubCommand( | |||
"", | |||
fmt.Sprintf("Parameters to use in SCA resolver (requires --%s).", commonParams.ScaResolverFlag), | |||
) | |||
createScanCmd.PersistentFlags().String(commonParams.ScanTypes, "", "Scan types, ex: (sast,iac-security,sca,api-security)") | |||
createScanCmd.PersistentFlags().String(commonParams.ContainerImagesFlag, "", "List of container images to scan, ex: manuelbcd/vulnapp:latest,debian:10") |
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.
the flag suppose to be under FF (in help too)
internal/commands/scan.go
Outdated
scanTypes, _ := cmd.Flags().GetString(commonParams.ScanTypes) | ||
var scanTypeList []string | ||
if len(scanTypes) > 0 { | ||
scanTypeList = strings.Split(scanTypes, ",") |
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.
trim
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.
if possible to add space *
internal/commands/scan.go
Outdated
return true | ||
} | ||
//check if user license supports only container scanning | ||
actualScanTypeList := strings.Split(actualScanTypes, ",") |
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.
change the name form actual to permissions / licenses (if it's not too complex)
containerImagesList = strings.Split(strings.TrimSpace(containerImages), ",") | ||
for _, containerImageName := range containerImagesList { | ||
if containerImagesErr := validateContainerImageFormat(containerImageName); containerImagesErr != nil { | ||
return containerImagesErr |
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.
add log error in validate when error
} | ||
containerResolverERR := containerResolver.Resolve(directoryPath, directoryPath, containerImagesList, debug) | ||
if containerResolverERR != nil { | ||
return containerResolverERR |
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.
add log error for container resolver
@@ -2474,6 +2554,14 @@ func validateCreateScanFlags(cmd *cobra.Command) error { | |||
return nil | |||
} | |||
|
|||
func validateContainerImageFormat(containerImage string) error { | |||
imageParts := strings.Split(containerImage, ":") |
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.
you can add trim
internal/commands/scan_test.go
Outdated
execCmdNilAssertion(t, append(baseArgs, "-s", blankSpace+"."+blankSpace)...) | ||
} | ||
|
||
func TestCreateScan_ContainerImagesFlagWithoutValue_FailCreatingScan(t *testing.T) { |
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.
is single container type with license
err := execCmdNotNilAssertion(t, "scan", "create", "--project-name", "MOCK", "-s", dummyRepo, "-b", "dummy_branch", "--container-images") | ||
assert.Assert(t, err.Error() == "flag needs an argument: --container-images") | ||
} | ||
|
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.
add zip case for unit without flags / filters + flags/ filters
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.
I reviewed up to utils_test.go
internal/commands/scan.go
Outdated
@@ -502,7 +509,18 @@ func scanCreateSubCommand( | |||
"", | |||
fmt.Sprintf("Parameters to use in SCA resolver (requires --%s).", commonParams.ScaResolverFlag), | |||
) | |||
createScanCmd.PersistentFlags().String(commonParams.ScanTypes, "", "Scan types, ex: (sast,iac-security,sca,api-security)") | |||
if len(wrappers.FeatureFlags) == 0 { |
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.
why do you need this condition?
if FF is not received you have to know it before (when you call the FF service) and fail the command if FF is necessary
but maybe you have to ignore containers when FF was not received
@@ -1000,6 +1022,7 @@ func addScaScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) map[string | |||
scaConfig.Filter, _ = cmd.Flags().GetString(commonParams.ScaFilterFlag) | |||
scaConfig.LastSastScanTime, _ = cmd.Flags().GetString(commonParams.LastSastScanTime) | |||
scaConfig.PrivatePackageVersion, _ = cmd.Flags().GetString(commonParams.ScaPrivatePackageVersionFlag) | |||
scaConfig.EnableContainersScan = !(wrappers.FeatureFlags[wrappers.ContainerEngineCLIEnabled] && userAllowedEngines[commonParams.ContainersType]) |
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.
scaConfig.EnableContainersScan = !(wrappers.FeatureFlags[wrappers.ContainerEngineCLIEnabled] && userAllowedEngines[commonParams.ContainersType]) | |
scaConfig.EnableContainersScan = (wrappers.FeatureFlags[wrappers.ContainerEngineCLIEnabled] && userAllowedEngines[commonParams.ContainersType]) |
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.
It should be - not the condition
@@ -1106,6 +1143,11 @@ func compressFolder(sourceDir, filter, userIncludeFilter, scaResolver string) (s | |||
return outputFile.Name(), err | |||
} | |||
|
|||
func isSingleContainerScanTriggered() bool { | |||
scanTypeList := strings.Split(actualScanTypes, ",") |
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.
actualScanTypes could include spaces?
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.
No :)
internal/wrappers/feature-flags.go
Outdated
@@ -21,6 +21,10 @@ var FeatureFlagsBaseMap = []CommandFlags{ | |||
Name: MinioEnabled, | |||
Default: true, | |||
}, | |||
{ |
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.
remove !!
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.
Should it be closed? all merged to other branch?
If so please close and delete the branch
|
||
var defaultEngines = map[string]bool{ | ||
"sast": true, | ||
"sca": true, | ||
"api-security": true, | ||
"iac-security": true, | ||
"containers": true, |
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.
what is the bool here?
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.
if this engines is allowed, I deleted the containers engine if the FF is off
@@ -138,6 +138,9 @@ type ScaConfig struct { | |||
ExploitablePath string `json:"ExploitablePath,omitempty"` | |||
LastSastScanTime string `json:"LastSastScanTime,omitempty"` | |||
PrivatePackageVersion string `json:"privatePackageVersion,omitempty"` | |||
EnableContainersScan bool `json:"enableContainersScan,omitempty"` | |||
} | |||
type ContainerConfig struct { |
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.
why do you need it if it empty
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.
In the future if we will required to pass some information there.
This is the same configuration handling we do in all of our engines, I thought it will be a good idea to do with container engine the same.
By submitting a PR to this repository, you agree to the terms within the Checkmarx Code of Conduct. Please see the contributing guidelines for how to create and submit a high-quality PR for this repo.
Description
Start Container Scan - Trigger Container Resolver For Containers and Scans.
Support Containers as New Scan Type With Realted Flags.
References
https://checkmarx.atlassian.net/jira/software/c/projects/AST/boards/471?assignee=712020%3A8b115cb9-1cab-4fd5-9878-130ce7842e3f&selectedIssue=AST-36237
https://checkmarx.atlassian.net/jira/software/c/projects/AST/boards/471?assignee=712020%3A8b115cb9-1cab-4fd5-9878-130ce7842e3f&selectedIssue=AST-36236
Testing
Added unit and integration tests.
Checklist