-
Notifications
You must be signed in to change notification settings - Fork 257
Description
Component (Azure NPM or Azure CNI):
Azure CNI
Describe in detail the feature/behavior/change you'd like to see:
Add support for specifying the endPort
field in a NetworkPolicy to open a range of ports https://kubernetes.io/docs/concepts/services-networking/network-policies/#targeting-a-range-of-ports
Context:
Numerous Azure services require a large range of ports for communication (on the order of thousands). To isolate pods with NetworkPolicy, a default-deny NetworkPolicy is enforced with a k8s policy management solution, then only the required connections are whitelisted with principal of least privilege.
Problem:
To allow a connection to an azure service outside the k8s cluster that requires a large range of ports to be open, a port entry needs to be defined for every port in the range, resulting in extremely long resource definitions. Especially when these NetworkPolicies are enforced with k8s policy management, there is an insane amount of load put on the kube-apiserver possibly resulting in an unintended denial-of-service on the entire cluster.
Current workarounds:
-
Currently, all ports need to be opened for the destination CIDRs of the Azure service(s) via not specifying ports in the NetworkPolicy, which does not follow principal of least privilege and is not as secure.
-
Create the long NetworkPolicies with a port entry for every port, but don't enforce it with k8s policy management. This might still result in excessive load to the kube-apiserver (untested). This is not secure because the NetworkPolicy can be deleted or modified advertently or inadvertently, bypassing pod isolation.
Orchestrator(e.g. Kubernetes, Docker):
Kubernetes
Operating System (Linux/Windows):
Linux
Anything else you would like to add:
[Miscellaneous information that will assist in solving the issue.]
What's noted in https://kubernetes.io/docs/concepts/services-networking/network-policies/ is the behavior we see when endPort
is specified in a NetworkPolicy:
"Note: Your cluster must be using a CNI plugin that supports the endPort field in NetworkPolicy specifications. If your network plugin does not support the endPort field and you specify a NetworkPolicy with that, the policy will be applied only for the single port field."
The resulting NetworkPolicy resource applied only has the single port
field applied instead of port
and endPort
.