Skip to content

Commit

Permalink
fix(scalability): only checking current cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Kurz committed Mar 3, 2023
1 parent 7a9e94a commit 9bde5ca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
24 changes: 14 additions & 10 deletions hardeneks/cluster_wide/scalability/control_plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,21 @@ def check_EKS_version(resources: Resources):
# if any cluster does not have setting, it returns False
def check_kubectl_compression(resources: Resources):
kubeconfig = helpers.get_kube_config()
isSetCorrectly = True
isSetCorrectly = False
for cluster in kubeconfig.get("clusters", []):
clusterName = cluster.get("name", "NoName")
if cluster.get("cluster", {}).get("disable-compression", False) != True:
isSetCorrectly = False
console.print(
Panel(
f"[red]DisableCompression in Cluster {clusterName} should equal True",
subtitle="[link=https://aws.github.io/aws-eks-best-practices/scalability/docs/control-plane/#disable-kubectl-compression]Click to see the guide[/link]",
clusterName = cluster.get("name", None)
if (clusterName == resources.cluster):
if cluster.get("cluster", {}).get("disable-compression", False) != True:
console.print(
Panel(
f"[red]`disable-compression` in Cluster {clusterName} should equal True",
subtitle="[link=https://aws.github.io/aws-eks-best-practices/scalability/docs/control-plane/#disable-kubectl-compression]Click to see the guide[/link]",
)
)
)
console.print()
console.print()
else:
isSetCorrectly = True
break


return isSetCorrectly
1 change: 1 addition & 0 deletions hardeneks/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ rules:
scalability:
control_plane:
- check_EKS_version
- check_kubectl_compression
namespace_based:
security:
iam:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_scalability_control_plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ def test_check_EKS_version(mocked_client):
@patch(helpers.__name__ + ".get_kube_config")
def test_check_kubectl_compression(mocked_helpers):
namespaced_resources = Resources(
"some_region", "some_context", "some_cluster", []
"some_region", "some_context", "foobarcluster", []
)
mocked_helpers.return_value = {'clusters': [{'cluster': {'server': 'testtest', 'disable-compression': True}, 'name': 'foobarcluster'}]}
assert check_kubectl_compression(namespaced_resources)
mocked_helpers.return_value = {'clusters': [{'cluster': {'server': 'testtest', 'disable-compression': True}, 'name': 'foobarcluster6'},{'cluster': {'server': 'testtest', 'disable-compression': True}, 'name': 'foobarcluster2'}]}
mocked_helpers.return_value = {'clusters': [{'cluster': {'server': 'testtest', 'disable-compression': True}, 'name': 'foobarcluster'}, {'cluster': {'server': 'testtest', 'disable-compression': False}, 'name': 'foobarcluster2'}]}
assert check_kubectl_compression(namespaced_resources)
mocked_helpers.return_value = {'clusters': [{'cluster': {'server': 'testtest', 'disable-compression': True}, 'name': 'foobarcluster3'}, {'cluster': {'server': 'testtest', 'disable-compression': False}, 'name': 'foobarcluster4'}]}
mocked_helpers.return_value = {'clusters': [{'cluster': {'server': 'testtest', 'disable-compression': False}, 'name': 'foobarcluster'}, {'cluster': {'server': 'testtest', 'disable-compression': False}, 'name': 'foobarcluster4'}]}
assert not check_kubectl_compression(namespaced_resources)
mocked_helpers.return_value = {'clusters': [{'cluster': {'test': 'user'}, 'name': 'foobarcluster7'}]}
assert not check_kubectl_compression(namespaced_resources)
mocked_helpers.return_value = {'clusters': [{}]}
assert not check_kubectl_compression(namespaced_resources)
mocked_helpers.return_value = {}
assert check_kubectl_compression(namespaced_resources)
assert not check_kubectl_compression(namespaced_resources)

0 comments on commit 9bde5ca

Please sign in to comment.