Skip to content

Commit

Permalink
fix(kubernetes): Handle non-sting params in command (#6768)
Browse files Browse the repository at this point in the history
* handle a case where we have a non-sting in the command

* fix mypy

* fixed mypy

* fixed test
  • Loading branch information
rotemavni authored Oct 14, 2024
1 parent 4ed33c4 commit 3ac3fe1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions checkov/kubernetes/checks/resource/k8s/k8s_check_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ def extract_commands(conf: dict[str, Any]) -> tuple[list[str], list[str]]:
for cmd in commands:
if cmd is None:
continue
if "=" in cmd:
if isinstance(cmd, str) and "=" in cmd:
key, value = cmd.split("=", maxsplit=1)
keys.append(key)
values.append(value)
else:
keys.append(cmd)
values.append(None)
values.append('')
return keys, values
17 changes: 17 additions & 0 deletions tests/kubernetes/checks/test_k8s_check_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from checkov.kubernetes.checks.resource.k8s.k8s_check_utils import extract_commands


def test_non_int_extract_commands() -> None:
conf = {'command': ['kube-apiserver', '--encryption-provider-config=config.file']}

keys, values = extract_commands(conf)
assert keys == ['kube-apiserver', '--encryption-provider-config']
assert values == ['', 'config.file']


def test_int_extract_commands() -> None:
conf = {'command': ['kube-apiserver', '--encryption-provider-config=config.file', '-p', 9082]}

keys, values = extract_commands(conf)
assert keys == ['kube-apiserver', '--encryption-provider-config', '-p', 9082]
assert values == ['', 'config.file', '', '']

0 comments on commit 3ac3fe1

Please sign in to comment.