-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(kubernetes): Add to nested resources on k8s graph inherit namespa…
…ce (#6912) Add to nested resources on k8s graph inherit namespace
- Loading branch information
Showing
7 changed files
with
156 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
tests/kubernetes/checks/example_NoDefaultNamespace/Dev-PASSED.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: dev | ||
|
||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: nginx-deployment | ||
namespace: dev | ||
spec: | ||
replicas: 3 | ||
selector: | ||
matchLabels: | ||
app: nginx | ||
template: | ||
metadata: | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx:latest | ||
ports: | ||
- containerPort: 80 | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: nginx-service | ||
namespace: dev | ||
spec: | ||
selector: | ||
app: nginx | ||
ports: | ||
- protocol: TCP | ||
port: 80 | ||
targetPort: 80 | ||
type: LoadBalancer |
4 changes: 2 additions & 2 deletions
4
tests/kubernetes/graph/checks/resources/AllowPrivilegeEscalation/expected.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
pass: | ||
- 'Pod.default.nginx-ingress-controller-2.app.kubernetes.io/name-ingress-nginx.app.kubernetes.io/part-of-ingress-nginx' | ||
- 'Pod.example-ns.nginx-ingress-controller-2.app.kubernetes.io/name-ingress-nginx.app.kubernetes.io/part-of-ingress-nginx' | ||
fail: | ||
- 'Pod.default.nginx-ingress-controller.app.kubernetes.io/name-ingress-nginx.app.kubernetes.io/part-of-ingress-nginx' | ||
- 'Pod.example-ns.nginx-ingress-controller.app.kubernetes.io/name-ingress-nginx.app.kubernetes.io/part-of-ingress-nginx' |
4 changes: 4 additions & 0 deletions
4
tests/kubernetes/graph/checks/resources/NoDefaultNamespace/expected.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pass: | ||
- 'Pod.dev.nginx-deployment.app-nginx' | ||
- 'Deployment.dev.nginx-deployment' | ||
- 'Service.dev.nginx-service' |
40 changes: 40 additions & 0 deletions
40
tests/kubernetes/graph/checks/resources/NoDefaultNamespace/template.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: dev | ||
|
||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: nginx-deployment | ||
namespace: dev | ||
spec: | ||
replicas: 3 | ||
selector: | ||
matchLabels: | ||
app: nginx | ||
template: | ||
metadata: | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx:latest | ||
ports: | ||
- containerPort: 80 | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: nginx-service | ||
namespace: dev | ||
spec: | ||
selector: | ||
app: nginx | ||
ports: | ||
- protocol: TCP | ||
port: 80 | ||
targetPort: 80 | ||
type: LoadBalancer |
61 changes: 61 additions & 0 deletions
61
tests/kubernetes/graph/checks/test_checks/NoDefaultNamespace.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
metadata: | ||
id: "CKV_K8S_160" | ||
name: "Ensure resources in k8s not in default namespace" | ||
category: "KUBERNETES" | ||
definition: | ||
and: | ||
- cond_type: "attribute" | ||
resource_types: | ||
- "Deployment" | ||
- "StatefulSet" | ||
- "DaemonSet" | ||
- "Job" | ||
- "CronJob" | ||
- "Pod" | ||
- "Service" | ||
- "ConfigMap" | ||
- "Secret" | ||
attribute: "metadata.namespace" | ||
operator: "exists" | ||
- cond_type: "attribute" | ||
resource_types: | ||
- "Deployment" | ||
- "StatefulSet" | ||
- "DaemonSet" | ||
- "Job" | ||
- "CronJob" | ||
- "Pod" | ||
- "Service" | ||
- "ConfigMap" | ||
- "Secret" | ||
attribute: "metadata.namespace" | ||
operator: "not_equals" | ||
value: "default" | ||
- cond_type: "attribute" | ||
resource_types: | ||
- "Deployment" | ||
- "StatefulSet" | ||
- "DaemonSet" | ||
- "Job" | ||
- "CronJob" | ||
- "Pod" | ||
- "Service" | ||
- "ConfigMap" | ||
- "Secret" | ||
attribute: "metadata.namespace" | ||
operator: "not_equals" | ||
value: "kube-system" | ||
- cond_type: "attribute" | ||
resource_types: | ||
- "Deployment" | ||
- "StatefulSet" | ||
- "DaemonSet" | ||
- "Job" | ||
- "CronJob" | ||
- "Pod" | ||
- "Service" | ||
- "ConfigMap" | ||
- "Secret" | ||
attribute: "metadata.namespace" | ||
operator: "not_regex_match" | ||
value: "^kube-.*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters