bridgecrewio / checkov

Prevent cloud misconfigurations and find vulnerabilities during build-time in infrastructure as code, container images and open source packages with Checkov by Bridgecrew.
https://www.checkov.io/
Apache License 2.0
7.17k stars 1.12k forks source link

feat(cloudformation): Support Fn::Sub in cases of using a pseudo parameter #6835

Closed bo156 closed 2 weeks ago

bo156 commented 2 weeks ago

User description

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

[//]: # "

PR Title

We use the title to create changelog automatically and therefore only allow specific prefixes
- break:    to indicate a breaking change, this supersedes any of the other types
- feat:     to indicate new features or checks
- fix:      to indicate a bugfix or handling of edge cases of existing checks
- docs:     to indicate an update to our documentation
- chore:    to indicate adjustments to workflow files or dependency updates
- platform: to indicate a change needed for the platform
Each prefix should be accompanied by a scope that specifies the targeted framework. If uncertain, use 'general'.
#    
Allowed prefixs:
ansible|argo|arm|azure|bicep|bitbucket|circleci|cloudformation|dockerfile|github|gha|gitlab|helm|kubernetes|kustomize|openapi|sast|sca|secrets|serverless|terraform|general|graph|terraform_plan|terraform_json
#
ex.
feat(terraform): add CKV_AWS_123 to ensure that VPC Endpoint Service is configured for Manual Acceptance

"

Description

Pseudo Parameter in CFN is a parameter which is dynamically available (see reference). As we do not render it on buildtime, we want to handle this case by keeping the reference itself without the value, so we can at least build a semi-full resource.

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/pseudo-parameter-reference.html

Checklist:


Generated description

Below is a concise technical summary of the changes proposed in this PR:

Introduce support for handling Fn::Sub with pseudo parameters in AWS CloudFormation templates. The CloudformationVariableRenderer class now includes a method _handle_sub_with_pseudo_param to manage these cases by retaining the reference without the value, ensuring a semi-complete resource build. The PseudoParameters enum is added to cfn_keywords.py to define available pseudo parameters. Test cases in test_render.py and new JSON/YAML resources validate the changes, ensuring that pseudo parameters are correctly processed and that the Fn::Sub function behaves as expected.

<table><tr><th>Topic</th><th>Details</th><tr><td><a href=https://baz.co/changes/bridgecrewio/checkov/6835?tool=ast&topic=New+Test+Resources>New Test Resources</a>
    </td><td>Introduce new JSON/YAML resources and test cases to validate the <code>Fn::Sub</code> function and pseudo parameter handling in CloudFormation templates.<details><summary>Modified files (5)</summary><ul><li>tests/cloudformation/graph/graph_runner/test_running_graph_checks.py</li>
  • tests/cloudformation/graph/graph_runner/external_graph_checks/jsonpath_policy.yaml
  • tests/cloudformation/graph/graph_runner/resources/jsonpath_policy/pass_str.json
  • tests/cloudformation/graph/graph_runner/resources/jsonpath_policy/fail_dict.json
  • tests/cloudformation/graph/graph_runner/resources/jsonpath_policy/fail_str.json
  • Latest Contributors(2)
    UserCommitDate
    nimrodkor@gmail.comMove-test-yamls-for-k8...January 24, 2022
    @gruebeladd-pre-commit-flake8December 12, 2021
    PseudoParameters Enum Add PseudoParameters enum to define available pseudo parameters in CloudFormation templates.
    Modified files (1)
    • checkov/cloudformation/parser/cfn_keywords.py
    Latest Contributors(2)
    UserCommitDate
    @gruebeladd-AWS-SAM-support-2013November 30, 2021
    @Saarettchanged-a-few-enms-to-...August 17, 2021
    Renderer Enhancement Enhance the CloudformationVariableRenderer to handle Fn::Sub with pseudo parameters, ensuring references are maintained without values for semi-complete resource builds.
    Modified files (1)
    • checkov/cloudformation/graph_builder/variable_rendering/renderer.py
    Latest Contributors(2)
    UserCommitDate
    @gruebelbreak-general-remove-P...October 04, 2023
    maxam@post.bgu.ac.iladd-exception-for-dict...June 09, 2022
    Test Updates Update test cases to validate the handling of Fn::Sub with pseudo parameters, ensuring correct processing and expected behavior.
    Modified files (3)
    • tests/cloudformation/graph/graph_builder/test_render.py
    • tests/cloudformation/graph/graph_builder/resources/variable_rendering/render_sub/yaml/test.yaml
    • tests/cloudformation/graph/graph_builder/resources/variable_rendering/render_sub/json/test.json
    Latest Contributors(2)
    UserCommitDate
    @gruebelchore-use-mock.patch-f...January 17, 2023
    @SaarettCFN-Func-is-not-evalua...October 07, 2021
    This pull request is reviewed by Baz. Join @bo156 and the rest of your team on (Baz).