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

kustomize fails on empty kustomization.yaml file without meaningful message #5128

Closed
marekiwaniak opened this issue May 23, 2023 · 1 comment · Fixed by #5131
Closed

kustomize fails on empty kustomization.yaml file without meaningful message #5128

marekiwaniak opened this issue May 23, 2023 · 1 comment · Fixed by #5131

Comments

@marekiwaniak
Copy link

After applying checkov -d . --framework kustomize onto existing project I got generic error.

2023-05-23 14:08:01,563 [MainThread  ] [ERROR]  Exception traceback:
Traceback (most recent call last):
  File "/home/marek/.local/lib/python3.10/site-packages/checkov/main.py", line 463, in run
    self.scan_reports = runner_registry.run(
  File "/home/marek/.local/lib/python3.10/site-packages/checkov/common/runners/runner_registry.py", line 102, in run
    self.runners[0].run(root_folder, external_checks_dir=external_checks_dir, files=files,
  File "/home/marek/.local/lib/python3.10/site-packages/checkov/kustomize/runner.py", line 557, in run
    self.run_kustomize_to_k8s(root_folder, files, runner_filter)
  File "/home/marek/.local/lib/python3.10/site-packages/checkov/kustomize/runner.py", line 498, in run_kustomize_to_k8s
    self.kustomizeProcessedFolderAndMeta[kustomize_dir] = self._parseKustomization(kustomize_dir)
  File "/home/marek/.local/lib/python3.10/site-packages/checkov/kustomize/runner.py", line 271, in _parseKustomization
    if 'resources' in fileContent:
TypeError: argument of type 'NoneType' is not iterable
Traceback (most recent call last):
  File "/home/marek/.local/bin/checkov", line 9, in <module>
    sys.exit(Checkov().run())
  File "/home/marek/.local/lib/python3.10/site-packages/checkov/main.py", line 463, in run
    self.scan_reports = runner_registry.run(
  File "/home/marek/.local/lib/python3.10/site-packages/checkov/common/runners/runner_registry.py", line 102, in run
    self.runners[0].run(root_folder, external_checks_dir=external_checks_dir, files=files,
  File "/home/marek/.local/lib/python3.10/site-packages/checkov/kustomize/runner.py", line 557, in run
    self.run_kustomize_to_k8s(root_folder, files, runner_filter)
  File "/home/marek/.local/lib/python3.10/site-packages/checkov/kustomize/runner.py", line 498, in run_kustomize_to_k8s
    self.kustomizeProcessedFolderAndMeta[kustomize_dir] = self._parseKustomization(kustomize_dir)
  File "/home/marek/.local/lib/python3.10/site-packages/checkov/kustomize/runner.py", line 271, in _parseKustomization
    if 'resources' in fileContent:
TypeError: argument of type 'NoneType' is not iterable

After some digging inside _parseKustomization at kustomize/runner.py:247 and applying try block loop body I found out file that was causing me the issue. I had following folders in kubernetess directory: base, prod,stage,dev. But dev contained totally empty kustomization.yaml file. Filling this file with yaml content solves the issue.

However maybe its worth to add some checks on fileContent object before we attempt to examine it for its contents.

checkov -v
2.3.234
@marekiwaniak marekiwaniak changed the title kustomize fails on empty kustomizatio.yaml file without meaningful message kustomize fails on empty kustomization.yaml file without meaningful message May 23, 2023
@robinsmidsrod
Copy link

Alternatively, this could be turned into a failing policy saying that an empty kustomization file is confusing/undefined behavior/something else and should be avoided. Either case, it shouldn't crash the scanner.

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 a pull request may close this issue.

2 participants