Skip to content

Conversation

@cx-alex-cohen
Copy link
Contributor

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

Describe the purpose of this PR along with any background information and the impacts of the proposed change.

References

Include supporting link to GitHub Issue/PR number

Testing

Describe how this change was tested. Be specific about anything not tested and reasons why. If this solution has unit and/or integration testing, tests should be added for new functionality and existing tests should complete without errors.

Please include any manual steps for testing end-to-end or functionality not covered by unit/integration tests.

Checklist

  • I have added documentation for new/changed functionality in this PR (if applicable).
  • I have updated the CLI help for new/changed functionality in this PR (if applicable).
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used

@github-actions
Copy link

github-actions bot commented Jan 29, 2025

Logo
Checkmarx One – Scan Summary & Detailsfdb8c4b1-fc66-4376-8482-3a3ffe7023b2

Great job, no security vulnerabilities found in this Pull Request

clearFlags()
clearFlags()
mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.ContainerEngineCLIEnabled, Status: true}
execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "json")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider validating the --scan-id flag to ensure that it is not empty and has a proper format before executing the command.

clearFlags()
mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.ContainerEngineCLIEnabled, Status: true}
execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "json")
assertTypePresentJSON(t, params.ContainersType, 1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear what assertTypePresentJSON does. Ensure that the function checks for the presence of container scan results in the output as expected by the PR title.

execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "json")
assertTypePresentJSON(t, params.ContainersType, 1)
// Remove generated json file
removeFileBySuffix(t, printer.FormatJSON)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of the generated file should be done in a defer statement immediately after the file creation to ensure it's cleaned up even if the test fails or panics.

fmt.Sprintf("Parameters to use in SCA resolver (requires --%s).", commonParams.ScaResolverFlag),
)
createScanCmd.PersistentFlags().String(commonParams.ContainerImagesFlag, "", "List of container images to scan, ex: manuelbcd/vulnapp:latest,debian:10. (Not supported yet)")
createScanCmd.PersistentFlags().String(commonParams.ContainerResolveLocallyFlag, "", "Execute container resolver locally.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flag commonParams.ContainerResolveLocallyFlag should have a more descriptive help message explaining what it means to execute the container resolver locally and the implications of using this flag.

)
createScanCmd.PersistentFlags().String(commonParams.ContainerImagesFlag, "", "List of container images to scan, ex: manuelbcd/vulnapp:latest,debian:10. (Not supported yet)")
createScanCmd.PersistentFlags().String(commonParams.ContainerResolveLocallyFlag, "", "Execute container resolver locally.")
createScanCmd.PersistentFlags().String(commonParams.ContainerImagesFlag, "", "List of container images to scan, ex: manuelbcd/vulnapp:latest,debian:10.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help message for commonParams.ContainerImagesFlag should mention the new default behavior of scanning containers in the cloud if not specified otherwise.

if err != nil {
return err
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of the containerEngineCLIEnabled check might cause unintended behavior if the feature flag is still relevant for other parts of the code. Ensure that the removal of this feature flag check does not affect other functionalities that depend on it.

configArr = append(configArr, apiSecConfig)
}
var containersConfig = addContainersScan(containerEngineCLIEnabled.Status)
var containersConfig = addContainersScan()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of the containerEngineCLIEnabled.Status parameter from addContainersScan() call might lead to unintended behavior if the function relies on this status check to determine whether to perform a containers scan. Ensure that the addContainersScan function is updated to handle the default behavior correctly without requiring this parameter.


func addContainersScan(containerEngineCLIEnabled bool) map[string]interface{} {
if !scanTypeEnabled(commonParams.ContainersType) || !containerEngineCLIEnabled {
func addContainersScan() map[string]interface{} {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of the containerEngineCLIEnabled parameter could lead to unintended behavior if the function relies on this flag to determine whether to add container scanning. Ensure that the removal of this parameter aligns with the intended logic and that any necessary checks are still performed elsewhere.


if isSingleContainerScanTriggered() && containerResolveLocally {
logger.PrintIfVerbose("Single container scan triggered: compressing only the container resolution file")
containerResolutionFilePath := filepath.Join(directoryPath, containerResolutionFileName)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable containerResolutionFileName is used but not defined in the diff. Ensure that it is properly declared and initialized before use.

if isSingleContainerScanTriggered() && containerResolveLocally {
logger.PrintIfVerbose("Single container scan triggered: compressing only the container resolution file")
containerResolutionFilePath := filepath.Join(directoryPath, containerResolutionFileName)
zipFilePath, dirPathErr = util.CompressFile(containerResolutionFilePath, containerResolutionFileName, directoryCreationPrefix)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error handling for util.CompressFile is missing. Ensure that any errors returned by this function are properly handled.

}

func runContainerResolver(cmd *cobra.Command, directoryPath string) error {
func runContainerResolver(cmd *cobra.Command, directoryPath string, containerResolveLocally bool) error {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new parameter containerResolveLocally is added to the function signature but not used within the function body. Ensure that the parameter is utilized as intended or remove it if it's unnecessary.

containerResolverError := runContainerResolver(cmd, directoryPath)
if containerResolverError != nil {
return containerResolverError
if containerResolveLocally || len(containerImagesList) > 0 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable containerResolveLocally is not defined in the provided diff. Ensure that it is properly declared and initialized before use.

}

imageParts := strings.Split(containerImage, ":")
if len(imageParts) != 2 || imageParts[0] == "" || imageParts[1] == "" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation logic for the container image format only checks for the presence of a colon and non-empty parts before and after the colon. However, it does not validate the actual format of the image name and tag. Consider adding more robust validation to ensure the image name and tag conform to the expected patterns.

@cx-alex-cohen cx-alex-cohen deleted the alex-containers-default-cloud branch January 30, 2025 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant