forked from Checkmarx/kics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(query): CNI Plugin Does Not Support Network Policies for Kuberne…
…tes (Checkmarx#5370) * + CNI Plugin Does Not Support Network Policies * change description * update
- Loading branch information
1 parent
1a4c2c3
commit c283b2d
Showing
8 changed files
with
200 additions
and
1 deletion.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
assets/queries/k8s/cni_plugin_does_not_support_network_policies/metadata.json
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,10 @@ | ||
{ | ||
"id": "03aabc8c-35d6-481e-9c85-20139cf72d23", | ||
"queryName": "CNI Plugin Does Not Support Network Policies", | ||
"severity": "MEDIUM", | ||
"category": "Networking and Firewall", | ||
"descriptionText": "Ensure the use of CNI Plugin that support Network Policies. If the CNI Plugin in use does not support Network Policies it may not be possible to effectively restrict traffic in the cluster", | ||
"descriptionUrl": "https://kubernetes.io/docs/concepts/extend-kubernetes/compute-storage-net/network-plugins/", | ||
"platform": "Kubernetes", | ||
"descriptionID": "0e8d122c" | ||
} |
40 changes: 40 additions & 0 deletions
40
assets/queries/k8s/cni_plugin_does_not_support_network_policies/query.rego
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 @@ | ||
package Cx | ||
|
||
import data.generic.k8s as k8sLib | ||
import data.generic.common as common_lib | ||
|
||
CxPolicy[result] { | ||
document := input.document[i] | ||
|
||
common_lib.valid_key(document, "cniVersion") | ||
plugin := document.plugins[j] | ||
plugin.type == "flannel" | ||
|
||
result := { | ||
"documentId": document.id, | ||
"searchKey": sprintf("plugins", []), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "Plugins should not contain a plugin that does not support Network Policies", | ||
"keyActualValue": "Plugins contains a plugin that does not support Network Policies", | ||
"searchLine": common_lib.build_search_line(["plugins", j, "type"], []), | ||
} | ||
} | ||
|
||
CxPolicy[result] { | ||
document := input.document[i] | ||
document.kind == "ConfigMap" | ||
|
||
cni:= json.unmarshal(document.data["cni-conf.json"]) | ||
plugin := cni.plugins[j] | ||
plugin.type == "flannel" | ||
|
||
result := { | ||
"documentId": document.id, | ||
"searchKey": sprintf("data.cni-conf.json", []), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "Plugins should not contain a plugin that does not support Network Policies", | ||
"keyActualValue": "Plugins contains a plugin that does not support Network Policies", | ||
"searchLine": common_lib.build_search_line(["data", "cni-conf.json"], []), | ||
} | ||
} | ||
|
26 changes: 26 additions & 0 deletions
26
assets/queries/k8s/cni_plugin_does_not_support_network_policies/test/negative.json
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,26 @@ | ||
{ | ||
"name": "k8s-pod-network", | ||
"cniVersion": "0.3.0", | ||
"plugins": [ | ||
{ | ||
"type": "calico", | ||
"log_level": "info", | ||
"datastore_type": "kubernetes", | ||
"nodename": "127.0.0.1", | ||
"ipam": { | ||
"type": "host-local", | ||
"subnet": "usePodCidr" | ||
}, | ||
"policy": { | ||
"type": "k8s" | ||
}, | ||
"kubernetes": { | ||
"kubeconfig": "/etc/cni/net.d/calico-kubeconfig" | ||
} | ||
}, | ||
{ | ||
"type": "portmap", | ||
"capabilities": {"portMappings": true} | ||
} | ||
] | ||
} |
35 changes: 35 additions & 0 deletions
35
assets/queries/k8s/cni_plugin_does_not_support_network_policies/test/negative2.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,35 @@ | ||
kind: ConfigMap | ||
apiVersion: v1 | ||
metadata: | ||
name: kube-flannel-cfg | ||
namespace: kube-system | ||
labels: | ||
tier: node | ||
app: calico | ||
data: | ||
cni-conf.json: | | ||
{ | ||
"name": "cbr0", | ||
"plugins": [ | ||
{ | ||
"type": "calico", | ||
"delegate": { | ||
"hairpinMode": true, | ||
"isDefaultGateway": true | ||
} | ||
}, | ||
{ | ||
"type": "portmap", | ||
"capabilities": { | ||
"portMappings": true | ||
} | ||
} | ||
] | ||
} | ||
net-conf.json: | | ||
{ | ||
"Network": "10.244.0.0/16", | ||
"Backend": { | ||
"Type": "vxlan" | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
assets/queries/k8s/cni_plugin_does_not_support_network_policies/test/positive.json
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,26 @@ | ||
{ | ||
"name": "k8s-pod-network", | ||
"cniVersion": "0.3.0", | ||
"plugins": [ | ||
{ | ||
"type": "flannel", | ||
"log_level": "info", | ||
"datastore_type": "kubernetes", | ||
"nodename": "127.0.0.1", | ||
"ipam": { | ||
"type": "host-local", | ||
"subnet": "usePodCidr" | ||
}, | ||
"policy": { | ||
"type": "k8s" | ||
}, | ||
"kubernetes": { | ||
"kubeconfig": "/etc/cni/net.d/flannel-kubeconfig" | ||
} | ||
}, | ||
{ | ||
"type": "portmap", | ||
"capabilities": {"portMappings": true} | ||
} | ||
] | ||
} |
35 changes: 35 additions & 0 deletions
35
assets/queries/k8s/cni_plugin_does_not_support_network_policies/test/positive2.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,35 @@ | ||
kind: ConfigMap | ||
apiVersion: v1 | ||
metadata: | ||
name: kube-flannel-cfg | ||
namespace: kube-system | ||
labels: | ||
tier: node | ||
app: flannel | ||
data: | ||
cni-conf.json: | | ||
{ | ||
"name": "cbr0", | ||
"plugins": [ | ||
{ | ||
"type": "flannel", | ||
"delegate": { | ||
"hairpinMode": true, | ||
"isDefaultGateway": true | ||
} | ||
}, | ||
{ | ||
"type": "portmap", | ||
"capabilities": { | ||
"portMappings": true | ||
} | ||
} | ||
] | ||
} | ||
net-conf.json: | | ||
{ | ||
"Network": "10.244.0.0/16", | ||
"Backend": { | ||
"Type": "vxlan" | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...eries/k8s/cni_plugin_does_not_support_network_policies/test/positive_expected_result.json
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,14 @@ | ||
[ | ||
{ | ||
"queryName": "CNI Plugin Does Not Support Network Policies", | ||
"severity": "MEDIUM", | ||
"line": 6, | ||
"fileName": "positive.json" | ||
}, | ||
{ | ||
"queryName": "CNI Plugin Does Not Support Network Policies", | ||
"severity": "MEDIUM", | ||
"line": 10, | ||
"fileName": "positive2.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