This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.9.7. Configuring multitenant isolation with network policy
As a cluster administrator, you can configure your network policies to provide multitenant network isolation.
If you are using the OpenShift SDN cluster network provider, configuring network policies as described in this section provides network isolation similar to multitenant mode but with network policy mode set.
You can configure your project to isolate it from pods and services in other project namespaces.
Prerequisites
-
Your cluster uses a cluster network provider that supports
NetworkPolicyobjects, such as the OpenShift SDN network provider withmode: NetworkPolicyset. This mode is the default for OpenShift SDN. -
You installed the OpenShift CLI (
oc). -
You are logged in to the cluster with a user with
adminprivileges.
Procedure
Create the following
NetworkPolicyobjects:A policy named
allow-from-openshift-ingress.重要For the OVN-Kubernetes network provider plug-in, when the Ingress Controller is configured to use the
HostNetworkendpoint publishing strategy, there is no supported way to apply network policy so that ingress traffic is allowed and all other traffic is denied.Copy to Clipboard Copied! Toggle word wrap Toggle overflow A policy named
allow-from-openshift-monitoring:Copy to Clipboard Copied! Toggle word wrap Toggle overflow A policy named
allow-same-namespace:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
If the
defaultIngress Controller configuration has thespec.endpointPublishingStrategy: HostNetworkvalue set, you must apply a label to thedefaultOpenShift Container Platform namespace to allow network traffic between the Ingress Controller and the project:Determine if your
defaultIngress Controller uses theHostNetworkendpoint publishing strategy:oc get --namespace openshift-ingress-operator ingresscontrollers/default \ --output jsonpath='{.status.endpointPublishingStrategy.type}'$ oc get --namespace openshift-ingress-operator ingresscontrollers/default \ --output jsonpath='{.status.endpointPublishingStrategy.type}'Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the previous command reports the endpoint publishing strategy as
HostNetwork, set a label on thedefaultnamespace:oc label namespace default 'network.openshift.io/policy-group=ingress'
$ oc label namespace default 'network.openshift.io/policy-group=ingress'Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Confirm that the
NetworkPolicyobject exists in your current project by running the following command:oc get networkpolicy <policy-name> -o yaml
$ oc get networkpolicy <policy-name> -o yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow In the following example, the
allow-from-openshift-ingressNetworkPolicyobject is displayed:oc get -n project1 networkpolicy allow-from-openshift-ingress -o yaml
$ oc get -n project1 networkpolicy allow-from-openshift-ingress -o yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow