Skip to content
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

Fix panic exit when containers ff could not be fetched (AST-86767) #1069

Merged
merged 13 commits into from
Mar 23, 2025

Conversation

greensd4
Copy link
Collaborator

@greensd4 greensd4 commented Mar 19, 2025

By submitting this pull request, you agree to the terms within the Checkmarx Code of Conduct. Please review the contributing guidelines for guidance on creating high-quality pull requests.

Description

Please provide a summary of the changes and the related issue. Include relevant motivation and context.
When creating a scan we check if the containers engine FF is enabled or not. if the FF could not be fetched the object that cli hold is nil. when trying to access containerEngineCLIEnabled.Status we get a panic error and the cli fails.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Related Issues

Link any related issues or tickets.

Checklist

  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules
  • 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

Screenshots (if applicable)

image

Additional Notes

Add any other relevant information.

Sorry, something went wrong.

@github-actions github-actions bot added the bug Something isn't working label Mar 19, 2025
Copy link

github-actions bot commented Mar 19, 2025

Logo
Checkmarx One – Scan Summary & Detailsb5dd5908-3f43-47d8-83bd-5f4c02b68ec6

Great job, no security vulnerabilities found in this Pull Request

elchananarb
elchananarb previously approved these changes Mar 20, 2025
@@ -1169,6 +1169,19 @@ func validateScanTypes(cmd *cobra.Command, jwtWrapper wrappers.JWTWrapper, featu
return nil
}

func isContainersEngineEnabled(featureFlagsWrapper wrappers.FeatureFlagsWrapper) bool {
runContainerEngineCLI := true
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this value necessary if it will be overwritten later anyway, whether there's an error or not?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i need to define the var outside the if/else scope. but you are right we can initialize it as nil.

containerEngineCLIEnabled, err := featureFlagsWrapper.GetSpecificFlag(wrappers.ContainerEngineCLIEnabled)
if err != nil {
logger.PrintfIfVerbose("could not get CONTAINER_ENGINE_CLI_ENABLED FF. defaulting to `false` error: %s", err)
runContainerEngineCLI = false
Copy link
Contributor

Choose a reason for hiding this comment

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

If retrieving the Feature Flag fails (e.g., due to a network issue), the function defaults to false, which could mistakenly disable container scanning.

Should the default be true or false? Defining it clearly would avoid confusion.

or maybe, return an error and let the user decide...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if we can not determine a FF i would like it to default to false. we also add a log here so the user can understand what happen. do u think it should be defaulted to true?

Copy link
Contributor

Choose a reason for hiding this comment

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

Defaulting to false with clear logging makes the most sense. When we can't get the feature flag, we should turn scanning off and tell the user what happened. This way they know scanning is off and why.

We should check if false is really the safer default,
but good logs to user is good idea

elchananarb
elchananarb previously approved these changes Mar 20, 2025
@greensd4 greensd4 merged commit de3f5af into main Mar 23, 2025
9 of 10 checks passed
@greensd4 greensd4 deleted the bug/fix-ff-panic branch March 23, 2025 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants