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
NetworkPolicy
objects, such as the OpenShift SDN network provider withmode: NetworkPolicy
set. 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
admin
privileges.
Procedure
Create the following
NetworkPolicy
objects:A policy named
allow-from-openshift-ingress
.重要For the OVN-Kubernetes network provider plug-in, when the Ingress Controller is configured to use the
HostNetwork
endpoint 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
default
Ingress Controller configuration has thespec.endpointPublishingStrategy: HostNetwork
value set, you must apply a label to thedefault
OpenShift Container Platform namespace to allow network traffic between the Ingress Controller and the project:Determine if your
default
Ingress Controller uses theHostNetwork
endpoint 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 thedefault
namespace: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
NetworkPolicy
object exists in your current project by running the following command:oc get networkpolicy <policy-name> -o yaml
$ oc get networkpolicy <policy-name> -o yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the following example, the
allow-from-openshift-ingress
NetworkPolicy
object is displayed:oc get -n project1 networkpolicy allow-from-openshift-ingress -o yaml
$ oc get -n project1 networkpolicy allow-from-openshift-ingress -o yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow