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

feat(kubernetes): added CKV2_K8S_EXAMPLE_1 only in tests as an example for k8s graph check for pod which is publicly accessible #4060

Merged
merged 2 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Pod
metadata:
app: nginx-pod
labels:
app: nginx-pod
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: nginx-pod
ports:
- protocol: TCP
port: 80
targetPort: 9376
clusterIP: 10.0.171.239
type: LoadBalancer
status:
loadBalancer:
ingress:
- ip: 192.0.2.127
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Pod
metadata:
app: nginx-pod
labels:
app: no-service-attached
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
name: not-attached-to-any-pod
spec:
selector:
app: not-exist
ports:
- protocol: TCP
port: 80
targetPort: 9376
clusterIP: 10.0.171.239
type: LoadBalancer
status:
loadBalancer:
ingress:
- ip: 192.0.2.127
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pass:
- Pod.default.app-no-service-attached
fail:
- Pod.default.app-nginx-pod
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
metadata:
id: "CKV2_K8S_EXAMPLE_1"
name: "Pod is publicly accessible"
category: "KUBERNETES"
definition:
and:
- cond_type: filter
value:
- Pod
operator: within
attribute: kind
- or:
- cond_type: connection
operator: not_exists
resource_types:
- Pod
connected_resource_types:
- Service
- and:
- cond_type: connection
operator: exists
resource_types:
- Pod
connected_resource_types:
- Service
- cond_type: attribute
attribute: 'spec.type'
operator: not_within
value:
- 'LoadBalancer'
- 'NodePort'
resource_types:
- Service
4 changes: 4 additions & 0 deletions tests/kubernetes/graph/checks/test_yaml_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def test_ModifyServicesStatus(self) -> None:
def test_ReadAllSecrets(self) -> None:
self.go('ReadAllSecrets')

@with_k8s_graph_flags()
def test_PodIsPubliclyAccessibleExample(self) -> None:
self.go('PodIsPubliclyAccessibleExample')

def create_report_from_graph_checks_results(self, checks_results, check):
report = Report("kubernetes")
first_results_key = list(checks_results.keys())[0]
Expand Down