Restrict network traffic with NetworkPolicies

Restrict which traffic can reach the Kueue components

This page shows how to restrict network traffic to the Kueue components using Kubernetes NetworkPolicies, addressing the OWASP Kubernetes Top Ten entry K05: Missing Network Segmentation Controls.

The page is intended for a batch administrator.

Before you begin

Make sure the following conditions are met:

  • A Kubernetes cluster is running.
  • The kubectl command-line tool has communication with your cluster.
  • Kueue is installed.
  • Your cluster uses a CNI plugin that enforces NetworkPolicy, such as Calico or Cilium. NetworkPolicy objects are accepted by every cluster, but a plugin that does not implement them silently ignores them.

What the policies allow

Selecting a pod with a NetworkPolicy isolates it, so ingress is denied unless a rule allows it. The rules below therefore leave every port not listed unreachable, while each listed port stays reachable from any source.

Two limits are worth knowing. Enforcement is entirely up to your CNI plugin, and Kubernetes allows traffic whose source is the pod’s own node regardless of any policy, so these rules cannot isolate a port from something running on the same node. Use node-level controls if you need that.

ComponentPortPurposePeer
ControllerManager9443Admission webhookskube-apiserver
ControllerManager8082Aggregated visibility APIkube-apiserver
ControllerManager8443MetricsPrometheus
ControllerManager8081Health and readiness probeskubelet
KueueViz backend8080Dashboard API and websocketIngress controller
KueueViz frontend8080Dashboard assetsIngress controller

These rules are scoped by port rather than by peer. The kube-apiserver and the kubelet normally run on the host network, so their traffic cannot be matched by a pod or namespace selector, and the address of the Prometheus scraper or the ingress controller depends on your cluster. If you need a port restricted to particular peers as well, see Restricting a port to specific peers.

Ports that are blocked

One port Kueue can serve is deliberately not allowed: the ControllerManager’s pprof endpoint. It is disabled by default and only listens when pprofBindAddress is set in the ControllerManager configuration. If you enable pprof, reach it with kubectl port-forward rather than by opening the port to the cluster, since profiling data may be sensitive.

The KueueViz backend also starts a pprof listener on localhost:6060 when it runs outside release mode, but that is bound to loopback and is not reachable from other pods either way.

Apart from those, Kueue serves no port that these policies block.

Before you enable the policies

The policies are not installed by default. Kueue is a privileged controller with broad watch permissions that also sits in the admission path, so limiting its reachable surface is worthwhile on shared or multi-tenant clusters.

Check these settings as well:

  • You run the ControllerManager with hostNetwork: true. Helm skips its policy because enforcement depends on the CNI plugin; see Limitations.
  • You have changed Kueue’s ports through managerConfig, for example by setting a different metrics.bindAddress. Helm derives allowed ports from that configuration. With the release manifest or Kustomize, update the policy ports alongside your configuration.
  • Your CNI plugin does not enforce NetworkPolicy. The objects will be created and accepted by the API server but have no effect, which can give a false sense of protection.

Enabling the policies

Release manifest

Each release ships the policies as a separate manifest. Apply the one matching your Kueue version:

kubectl apply --server-side -f https://github.com/kubernetes-sigs/kueue/releases/download/v0.21.0/network-policies.yaml

To remove them, delete the same manifest.

Helm

Set networkPolicy.enabled:

helm upgrade --install kueue oci://registry.k8s.io/kueue/charts/kueue \
  --namespace kueue-system \
  --create-namespace \
  --set networkPolicy.enabled=true

Or set the same value in your own values file:

networkPolicy:
  enabled: true

Kustomize

Add the networkpolicy overlay from a checkout of the Kueue release you are running to your own kustomization, or apply it directly:

kubectl apply --server-side -k config/networkpolicy

Allowing extra traffic

networkPolicy.extraIngress appends rules to the ControllerManager’s policy. Use it to permit traffic the built-in rules do not cover, for example a scraper that needs a port which is not in the table above.

networkPolicy:
  enabled: true
  extraIngress:
    - from:
        - namespaceSelector:
            matchLabels:
              kubernetes.io/metadata.name: monitoring
      ports:
        - protocol: TCP
          port: 9090

Restricting a port to specific peers

The chart does not expose the built-in rules for editing, so narrowing one means replacing it. With Kustomize, write a patch and apply it over the overlay from your own kustomization:

# kustomization.yaml
resources:
  - <your Kueue checkout>/config/networkpolicy
patches:
  - path: metrics-peers-patch.yaml
# metrics-peers-patch.yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: kueue-controller-manager-ingress
  namespace: kueue-system
spec:
  ingress:
    - ports:
        - protocol: TCP
          port: 9443
        - protocol: TCP
          port: 8082
    - ports:
        - protocol: TCP
          port: 8081
    # metrics, now limited to the monitoring namespace
    - from:
        - namespaceSelector:
            matchLabels:
              kubernetes.io/metadata.name: monitoring
      ports:
        - protocol: TCP
          port: 8443

Because a patch on spec.ingress replaces the whole list, every rule you still want has to be repeated. With Helm, apply the same replacement through a post-renderer.

Take care when narrowing 9443 and 8082. Those are reached by the kube-apiserver, which usually runs on the host network, so a pod or namespace selector will not match it and you need an ipBlock covering your control-plane node addresses. Getting it wrong makes the admission webhook unreachable and stops Job creation across the cluster. 8443 is the safer one to narrow, since a mistake only breaks metrics scraping.

Limitations

  • hostNetwork enforcement depends on the CNI plugin. Kubernetes leaves the behaviour of NetworkPolicy for pods on the host network undefined, and most CNI plugins do not apply policies to them, so the policy would likely have no effect. Helm skips the ControllerManager policy when controllerManager.hostNetwork is enabled. With the release manifest or Kustomize, leave out that policy when enabling host networking. Use node firewall rules where your CNI does not enforce policies for host-network pods.
  • The policies restrict ingress only; traffic leaving the Kueue pods is not restricted.
  • The KueueViz policies are inert unless the KueueViz components are also deployed.