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.04k stars 1.11k forks source link

Getting AttributeError: 'NoneType' object has no attribute 'get' #5422

Open cbugneac-nex opened 1 year ago

cbugneac-nex commented 1 year ago

Describe the issue

Running on GitHub Actions using pip install:

      - name: Install Python
        uses: actions/setup-python@v4
        with:
          python-version: 3.11
          cache: pip

      - name: Install Checkov
        run: pip install -r requirements.txt

      - name: Execute Checkov
        run: |
          checkov -d ./path \
          --config-file .checkov.yml \
          --output cli --output sarif \
          --output-file-path console,results.sarif

requirements.txt:

checkov==2.3.359

Examples See above.

Exception Trace Getting the below trace:

Error: -09 08:07:18,565 [MainThread  ] [ERROR]  Failed to invoke function /opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/checkov/common/runners/runner_registry._parallel_run with <checkov.terraform.runner.Runner object at 0x7fd9aa6f1c50>
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/checkov/common/parallelizer/parallel_runner.py", line 39, in func_wrapper
    result = original_func(item)
             ^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/checkov/common/runners/runner_registry.py", line 1[27](https://github.com/******/********/actions/runs/5806479021/job/15739452082#step:5:28), in _parallel_run
    report = runner.run(
             ^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/checkov/terraform/runner.py", line 174, in run
    self.check_tf_definition(report, root_folder, runner_filter, collect_skip_comments)
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/checkov/terraform/runner.py", line 370, in check_tf_definition
    self.push_skipped_checks_down_from_modules(self.context)
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/checkov/terraform/runner.py", line 645, in push_skipped_checks_down_from_modules
    self.push_skipped_checks_down(definition_context, skipped_checks, resolved_paths)
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/checkov/terraform/runner.py", line 668, in push_skipped_checks_down
    module_context = next(m for m in self.definitions.get(resolved_paths[ind]).get(block_type) if module_name in m)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get'
kubernetes scan results:

Passed checks: 598, Failed checks: 0, Skipped checks: 32

helm scan results:

Passed checks: 86, Failed checks: 0, Skipped checks: 1

Desktop (please complete the following information):

Additional context None

gruebel commented 1 year ago

hey @cbugneac-nex thanks for reaching out.

But sadly we need much more information to better investigate the issue. I can tell it comes from adding skip comments on a module block. How deep is it nested?

cbugneac-nex commented 1 year ago

Hi @gruebel this is a snippet when run with DEBUG logging (full one is pretty long). Is it of any help ?

...
2023-08-09 08:20:31,697 [MainThread  ] [DEBUG]  done evaluate_non_rendered_values
2023-08-09 08:20:31,729 [MainThread  ] [INFO ]  Building cross variable edges
2023-08-09 08:20:31,821 [MainThread  ] [DEBUG]  Rendering was skipped for a 14266-character-long string. If you wish to have it evaluated, please set the environment variable CHECKOV_RENDER_MAX_LEN to 14267 or to 0 to allow rendering of any length
2023-08-09 08:20:31,821 [MainThread  ] [DEBUG]  Rendering was skipped for a 14363-character-long string. If you wish to have it evaluated, please set the environment variable CHECKOV_RENDER_MAX_LEN to 14364 or to 0 to allow rendering of any length
2023-08-09 08:20:31,821 [MainThread  ] [DEBUG]  Rendering was skipped for a 14376-character-long string. If you wish to have it evaluated, please set the environment variable CHECKOV_RENDER_MAX_LEN to 14377 or to 0 to allow rendering of any length
2023-08-09 08:20:31,821 [MainThread  ] [DEBUG]  Rendering was skipped for a 14363-character-long string. If you wish to have it evaluated, please set the environment variable CHECKOV_RENDER_MAX_LEN to 14364 or to 0 to allow rendering of any length
2023-08-09 08:20:31,822 [MainThread  ] [DEBUG]  Rendering was skipped for a 14266-character-long string. If you wish to have it evaluated, please set the environment variable CHECKOV_RENDER_MAX_LEN to 14267 or to 0 to allow rendering of any length
2023-08-09 08:20:31,822 [MainThread  ] [DEBUG]  Rendering was skipped for a 14266-character-long string. If you wish to have it evaluated, please set the environment variable CHECKOV_RENDER_MAX_LEN to 14267 or to 0 to allow rendering of any length
2023-08-09 08:20:31,822 [MainThread  ] [DEBUG]  Rendering was skipped for a 14266-character-long string. If you wish to have it evaluated, please set the environment variable CHECKOV_RENDER_MAX_LEN to 14267 or to 0 to allow rendering of any length
2023-08-09 08:20:31,822 [MainThread  ] [DEBUG]  Rendering was skipped for a 14266-character-long string. If you wish to have it evaluated, please set the environment variable CHECKOV_RENDER_MAX_LEN to 14267 or to 0 to allow rendering of any length
2023-08-09 08:20:31,846 [MainThread  ] [INFO ]  Found 10 cross variable edges
2023-08-09 08:20:32,347 [MainThread  ] [DEBUG]  Created definitions context
Error: -09 08:20:32,348 [MainThread  ] [ERROR]  Failed to invoke function /opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/checkov/common/runners/runner_registry._parallel_run with <checkov.terraform.runner.Runner object at 0x7f9ae944fa90>
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/checkov/common/parallelizer/parallel_runner.py", line 39, in func_wrapper
    result = original_func(item)
             ^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/checkov/common/runners/runner_registry.py", line 127, in _parallel_run
    report = runner.run(
             ^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/checkov/terraform/runner.py", line 174, in run
    self.check_tf_definition(report, root_folder, runner_filter, collect_skip_comments)
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/checkov/terraform/runner.py", line 370, in check_tf_definition
    self.push_skipped_checks_down_from_modules(self.context)
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/checkov/terraform/runner.py", line 645, in push_skipped_checks_down_from_modules
    self.push_skipped_checks_down(definition_context, skipped_checks, resolved_paths)
  File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/checkov/terraform/runner.py", line 668, in push_skipped_checks_down
    module_context = next(m for m in self.definitions.get(resolved_paths[ind]).get(block_type) if module_name in m)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get'
2023-08-09 08:20:32,379 [MainThread  ] [DEBUG]  Getting exit code for report cloudformation
2023-08-09 08:20:32,379 [MainThread  ] [DEBUG]  Soft fail severity threshold: None
2023-08-09 08:20:32,379 [MainThread  ] [DEBUG]  Soft fail checks: []
2023-08-09 08:20:32,379 [MainThread  ] [DEBUG]  Hard fail severity threshold: None
2023-08-09 08:20:32,379 [MainThread  ] [DEBUG]  Hard fail checks: []
2023-08-09 08:20:32,379 [MainThread  ] [DEBUG]  Use enforcement rules is FALSE
2023-08-09 08:20:32,379 [MainThread  ] [DEBUG]  In get_exit_code; exit code thresholds: {'soft_fail': False, 'soft_fail_checks': [], 'soft_fail_threshold': None, 'hard_fail_checks': [], 'hard_fail_threshold': None}, hard_fail_on_parsing_errors: False
2023-08-09 08:20:32,379 [MainThread  ] [DEBUG]  No failed checks in this report - returning 0
2023-08-09 08:20:32,379 [MainThread  ] [DEBUG]  Getting exit code for report kubernetes
2023-08-09 08:20:32,379 [MainThread  ] [DEBUG]  Soft fail severity threshold: None
2023-08-09 08:20:32,379 [MainThread  ] [DEBUG]  Soft fail checks: []
2023-08-09 08:20:32,379 [MainThread  ] [DEBUG]  Hard fail severity threshold: None
2023-08-09 08:20:32,379 [MainThread  ] [DEBUG]  Hard fail checks: []
2023-08-09 08:20:32,379 [MainThread  ] [DEBUG]  Use enforcement rules is FALSE
2023-08-09 08:20:32,379 [MainThread  ] [DEBUG]  In get_exit_code; exit code thresholds: {'soft_fail': False, 'soft_fail_checks': [], 'soft_fail_threshold': None, 'hard_fail_checks': [], 'hard_fail_threshold': None}, hard_fail_on_parsing_errors: False
2023-08-09 08:20:32,379 [MainThread  ] [DEBUG]  No failed checks in this report - returning 0
2023-08-09 08:20:32,379 [MainThread  ] [DEBUG]  Getting exit code for report serverless
2023-08-09 08:20:32,379 [MainThread  ] [DEBUG]  Soft fail severity threshold: None
2023-08-09 08:20:32,379 [MainThread  ] [DEBUG]  Soft fail checks: []
2023-08-09 08:20:32,380 [MainThread  ] [DEBUG]  Hard fail severity threshold: None
2023-08-09 08:20:32,380 [MainThread  ] [DEBUG]  Hard fail checks: []
kubernetes scan results:

Passed checks: 598, Failed checks: 0, Skipped checks: 32

helm scan results:

Passed checks: 86, Failed checks: 0, Skipped checks: 1

2023-08-09 08:20:32,380 [MainThread  ] [DEBUG]  Use enforcement rules is FALSE
2023-08-09 08:20:32,380 [MainThread  ] [DEBUG]  In get_exit_code; exit code thresholds: {'soft_fail': False, 'soft_fail_checks': [], 'soft_fail_threshold': None, 'hard_fail_checks': [], 'hard_fail_threshold': None}, hard_fail_on_parsing_errors: False
2023-08-09 08:20:32,380 [MainThread  ] [DEBUG]  No failed checks in this report - returning 0
2023-08-09 08:20:32,380 [MainThread  ] [DEBUG]  Getting exit code for report arm
2023-08-09 08:20:32,380 [MainThread  ] [DEBUG]  Soft fail severity threshold: None
2023-08-09 08:20:32,380 [MainThread  ] [DEBUG]  Soft fail checks: []
...
stale[bot] commented 8 months ago

Thanks for contributing to Checkov! We've automatically marked this issue as stale to keep our issues list tidy, because it has not had any activity for 6 months. It will be closed in 14 days if no further activity occurs. Commenting on this issue will remove the stale tag. If you want to talk through the issue or help us understand the priority and context, feel free to add a comment or join us in the Checkov slack channel at codifiedsecurity.slack.com Thanks!

cbugneac-nex commented 8 months ago

remove the stale tag

Saarett commented 3 months ago

Hi @cbugneac-nex, could you please share the specific file that causes this issue? You could possibly run Checkov separately and not as part of an action, which would make it easier. Without a specific file or a way to reproduce the issue, we are limited in our ability to assist.