Configure network policies
Configure network policies to restrict Pod-to-Pod traffic for the Che components and for each workspace. The Che Operator can manage the NetworkPolicy resources for the Che components automatically, and the DevWorkspace Operator provisions a NetworkPolicy for each workspace. Both network policy features are disabled by default.
Network policies
By default, all Pods in a Kubernetes cluster can communicate with each other across namespaces. In Che, this allows a workspace Pod in one user namespace to send traffic to workspace Pods in other user namespaces.
Network policies restrict network traffic to only the flows required by Che components and workspaces.
Custom rules for workspace network policies
The ingress and egress fields of the spec.devEnvironments.networking.networkPolicy CheCluster field accept standard Kubernetes NetworkPolicy rules and behave as follows:
-
When
ingressis not specified, the default ingress rules of the DevWorkspace Operator apply, and the Che Operator adds one rule allowing traffic from the Che components. On OpenShift, the default rules allow traffic from the DevWorkspace Operator namespace and from the OpenShift monitoring, ingress, host-network, and console namespaces. On Kubernetes, the default allows all ingress because the DevWorkspace Operator cannot identify the namespace of the cluster ingress controller; define customingressrules to restrict ingress. -
When
ingressis specified as an empty list, all ingress traffic to the workspace Pods is denied. -
When
ingressis specified as a non-empty list, exactly those rules apply: the default rules are replaced, and the rule allowing traffic from the Che components is not added automatically. If the Che components must communicate with the workspaces, include a corresponding ingress rule.
The egress field behaves the same way.
When it is not specified, the default egress rule of the DevWorkspace Operator applies, which allows all egress traffic.
When it is specified as an empty list, all egress traffic from the workspace Pods is denied.
When it is specified as a non-empty list, exactly those rules apply.
Enable Operator-managed network policies
Enable Operator-managed network policies to restrict ingress traffic to the Che components, such as the gateway, server, dashboard, and registries.
The Che Operator creates and manages the NetworkPolicy resources automatically.
This feature is controlled by the spec.networking.networkPolicy.enabled CheCluster field and is disabled by default.
The NetworkPolicies are created in the Che namespace and apply only to the Pods labeled with app.kubernetes.io/part-of=che.eclipse.org.
When this field is set to false, the NetworkPolicies previously created by the Operator are removed.
|
This setting also drives network isolation for workspaces: when |
-
An active
kubectlsession with administrative permissions to the destination Kubernetes cluster. See Overview of kubectl.
-
Enable Operator-managed network policies:
kubectl patch checluster/eclipse-che \ --namespace eclipse-che \ --type merge \ --patch '{"spec":{"networking":{"networkPolicy":{"enabled":true}}}}' -
Optional: To protect the Che components without isolating the workspaces, disable network isolation for workspaces:
kubectl patch checluster/eclipse-che \ --namespace eclipse-che \ --type merge \ --patch '{"spec":{"devEnvironments":{"networking":{"networkPolicy":{"enabled":false}}}}}'
-
Verify that the NetworkPolicy resources are created in the Che namespace:
kubectl get networkpolicies -n eclipse-che -
Start a workspace and verify that a NetworkPolicy resource is created for it in the user namespace:
kubectl get networkpolicies -n <user_namespace>
After enabling, the Operator creates the following resources:
| Name | Description |
|---|---|
|
Allows ingress traffic between Che Pods in the same namespace. |
|
Allows ingress traffic from user workspace namespaces. |
|
Allows ingress traffic from the OpenShift ingress namespace. |
|
Allows ingress traffic from Pods that use the host network, for example the OpenShift router. |
|
Allows ingress traffic from the OpenShift monitoring namespace. |
|
Allows ingress traffic from the Operator Pod to Che components. |
|
Allows all egress traffic from Che Pods. |
On Kubernetes, the Operator creates only the allow-all-ingress and allow-all-egress NetworkPolicies, which allow all ingress and egress traffic.
The namespace of the cluster ingress controller is not known to the Operator.
Enabling this setting on Kubernetes does not restrict any traffic by itself: you must provision the NetworkPolicy resources for your cluster manually.
When network isolation for workspaces is enabled, the DevWorkspace Operator creates a <workspace_id>-networkpolicy NetworkPolicy resource in the user namespace for each workspace.
See Configure network policies.
Configure network policies for workspaces
Configure network policies for workspaces to restrict the traffic to and from workspace Pods.
The DevWorkspace Operator provisions one NetworkPolicy for each workspace, controlled by the spec.devEnvironments.networking.networkPolicy CheCluster field.
Workspace network policies are disabled by default.
-
An active
kubectlsession with administrative permissions to the destination Kubernetes cluster. See Overview of kubectl.
-
Enable network policies for workspaces:
kubectl patch checluster/eclipse-che \ --namespace eclipse-che \ --type merge \ --patch '{"spec":{"devEnvironments":{"networking":{"networkPolicy":{"enabled":true}}}}}' -
Optional: Define custom
ingressandegressrules in thespec.devEnvironments.networking.networkPolicyfield to restrict the traffic that is allowed for the workspace Pods. A non-emptyingresslist replaces the default rules, so include rules for the traffic that must still be allowed, for example traffic from the Che components:spec: devEnvironments: networking: networkPolicy: enabled: true ingress: - from: - namespaceSelector: matchLabels: kubernetes.io/metadata.name: <peer_namespace>In this example, the workspace accepts ingress traffic from Pods in the
<peer_namespace>namespace.For how the
ingressandegressfields behave when they are not specified, empty, or non-empty, see Custom rules for workspace network policies.
-
Start a workspace and verify that the NetworkPolicy resource is created for it in the user namespace:
kubectl get networkpolicies -n <user_namespace>
|
The new configuration is applied to a workspace the next time that workspace is reconciled, for example when it is started or stopped. |