Skip to content

Commit 4851fc9

Browse files
author
Steven Smith
committed
Adds egress netpol docs
1 parent 1de0f04 commit 4851fc9

8 files changed

+274
-0
lines changed

_topic_maps/_topic_map.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,8 @@ Topics:
14791479
File: default-network-policy
14801480
- Name: Configuring multitenant isolation with network policy
14811481
File: multitenant-network-policy
1482+
- Name: Configuring full multitenant isolation with network policy using ingress and egress
1483+
File: nw-networkpolicy-full-multitenant-isolation
14821484
- Name: Audit logging for network security
14831485
File: logging-network-security
14841486
- Name: Egress Firewall
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * networking/network_security/network_policy/nw-networkpolicy-full-multitenant-isolation.adoc
4+
5+
:_mod-docs-content-type: PROCEDURE
6+
[id="nw-networkpolicy-allow-internet_{context}"]
7+
= Creating an allow internet access network policy
8+
9+
With the `deny-by-default` network policy in place, no pods can talk to each other or receive traffic from the internet. As a result, you should allow some pods to receive traffic from outside sources. To do this, you can create designated labels that are applied to the pods that you want to allow access from the internet, and then create network policies that target those labels.
10+
11+
The following procedure shows you how to create an internet access network policy that uses the `networking/allow-internet-access=true` label so that labeled pods receive traffic from outside sources.
12+
13+
.Prerequisites
14+
15+
* You have created the `deny-by-default` network policy and applied it to the necessary namespaces.
16+
17+
.Procedure
18+
19+
. Create the following `internet-access` network policy to allow pods with the `networking/allow-internet-access` label to receive traffic from outside sources. Save the YAML in the `internet-access.yaml` file:
20+
+
21+
[source,yaml]
22+
----
23+
apiVersion: networking.k8s.io/v1
24+
kind: NetworkPolicy
25+
metadata:
26+
name: internet-access
27+
spec:
28+
podSelector:
29+
matchLabels:
30+
networking/allow-internet-access: "true" <1>
31+
policyTypes:
32+
- Ingress
33+
ingress:
34+
- {}
35+
----
36+
<1> Apply this label to pods to enable the pod to receive traffic from outside sources.
37+
38+
. Apply the network policy by entering the following command:
39+
+
40+
[source,terminal]
41+
----
42+
$ oc apply -f internet-access.yaml -n <namespace>
43+
----
44+
+
45+
.Example output
46+
+
47+
[source,terminal]
48+
----
49+
networkpolicy.networking.k8s.io/internet-access created
50+
----
51+
52+
. Repeat step two for all necessary namespaces.

modules/nw-networkpolicy-deny-all-allowed.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// * networking/multiple_networks/configuring-multi-network-policy.adoc
44
// * networking/network_security/network_policy/creating-network-policy.adoc
55
// * microshift_networking/microshift-creating-network-policy.adoc
6+
// * networking/network_security/network_policy/nw-networkpolicy-full-multitenant-isolation.adoc
67

78
:name: network
89
:role: admin
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * networking/network_security/network_policy/multitenant-network-policy.adoc
4+
5+
:_mod-docs-content-type: PROCEDURE
6+
[id="nw-networkpolicy-multitenant-isolation-egress_{context}"]
7+
= Configuring full multitenant isolation by using network policy
8+
9+
By default, if no egress network policy is applied to a pod, the pod is not isolated for egress traffic. When a pod is not isolated for egress, it can send traffic freely to any destination.
10+
11+
With an egress multitenant isolation network policy, cluster administrators can control outbound traffic from pods. When an egress network policy is applied to a pod, that pod becomes _isolated_ for egress, meaning that egress traffic is allowed only if it is permitted by at least one matching egress rule.
12+
13+
Egress network policies help ensure that only authorized outbound traffic, such as communication with external services or specific namespaces, is allowed, depending on the configuration.
14+
15+
[IMPORTANT]
16+
====
17+
* Before configuring an egress network policy, cluster administrators should first configure ingress network policies. Attempting to configure both at the same time can make it difficult to determine which network policy is blocking traffic.
18+
19+
* Egress network policies are harder to effectively implement than ingress network policies. Restricting outbound traffic might lead to unexpected issues.
20+
====
21+
22+
.Prerequisites
23+
24+
* Your cluster uses a network plugin that supports `NetworkPolicy` objects, such as the OVN-Kubernetes network plugin, with `mode: NetworkPolicy` set.
25+
* You installed the OpenShift CLI (`oc`).
26+
* You are logged in to the cluster as a user with `admin` privileges.
27+
* You have configured an ingress network policy. The procedure in this section shows you how to create a complementary egress network policy that mirrors the following ingress network policy. This network policy allows pod-to-pod communication.
28+
+
29+
.Ingress pod-to-pod network policy
30+
[source,yaml]
31+
----
32+
apiVersion: networking.k8s.io/v1
33+
kind: NetworkPolicy
34+
metadata:
35+
name: allow-n1-a-to-n2-b
36+
namespace: <namespace_b>
37+
spec:
38+
podSelector:
39+
matchLabels:
40+
app: test # this is the label on test-pod-tenant-b
41+
policyTypes:
42+
- Ingress
43+
ingress:
44+
- from:
45+
- namespaceSelector:
46+
matchLabels:
47+
networking/namespace: n1 # label on namespace tenant-a
48+
podSelector:
49+
matchLabels:
50+
app: test-pod # this is the label on test-pod in tenant-a
51+
----
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * networking/network_security/network_policy/creating-network-policy.adoc
4+
5+
:_mod-docs-content-type: CONCEPT
6+
[id="nw-networkpolicy-multitenant-isolation-ingress_{context}"]
7+
= Multitenant ingress network policies
8+
9+
The following example shows you how to set up a multitenant ingress network policy. Configuring ingress network policies can help improve the security of your deployment by isolating pods from unauthorized incoming traffic.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * networking/network_security/network_policy/nw-networkpolicy-full-multitenant-isolation.adoc
4+
5+
:_mod-docs-content-type: REFERENCE
6+
[id="nw-networkpolicy-pod-pod-communication_{context}"]
7+
= Creating a pod-to-pod communication network policy
8+
9+
After you have created the `deny-by-default` and `internet-access` network policies, you can create a network policy that allows pods to communicate with each other.
10+
11+
The following chapters provides three different examples of network policies that allow for pod-to-pod communication. Choose the network policy that best suits your needs.
12+
13+
.Prerequisites
14+
15+
* You have created the `deny-by-default` network policy and applied it to all necessary namespaces.
16+
* You have created an `internet-access` network policy and applied it to all necessary namespaces.
17+
18+
.Procedure
19+
20+
. Depending on your needs, create one of the following network policies to enable pod-to-pod communication:
21+
+
22+
* Use the following `allow-same-namespace` YAML to allow all pods in the same namespace the ability to communicate with each other:
23+
+
24+
[source,yaml]
25+
----
26+
apiVersion: networking.k8s.io/v1
27+
kind: NetworkPolicy
28+
metadata:
29+
name: allow-same-namespace
30+
spec:
31+
podSelector: {}
32+
policyTypes:
33+
- Ingress
34+
ingress:
35+
- from:
36+
- podSelector: {}
37+
----
38+
+
39+
* Advanced users who know exactly which pod-to-pod connections should be allowed in their application can explicitly allow each connection. For example, if you want pods in *Deployment A* to communicate with pods in *Deployment B*, use the following `allow-server-to-access` network policy reference to allow that connection. Note that you must update the pod's labels to match those defined in the following YAML:
40+
+
41+
[source,yaml]
42+
----
43+
apiVersion: networking.k8s.io/v1
44+
kind: NetworkPolicy
45+
metadata:
46+
name: allow-server-to-access
47+
spec:
48+
podSelector:
49+
matchLabels:
50+
deployment-b-pod-label-1-key: deployment-b-pod-label-1-value
51+
deployment-b-pod-label-2-key: deployment-b-pod-label-2-value
52+
policyTypes:
53+
- Ingress
54+
ingress:
55+
- from:
56+
- podSelector:
57+
matchLabels:
58+
deployment-a-pod-label-1-key: deployment-a-pod-label-1-value
59+
deployment-a-pod-label-2-key: deployment-a-pod-label-2-value
60+
----
61+
+
62+
* To allow communication across namespaces, you can create a label for the source namespace and add a `namespaceSelector` query next to the `podSelector` query
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * networking/network_security/network_policy/nw-networkpolicy-full-multitenant-isolation.adoc
4+
5+
:_mod-docs-content-type: REFERENCE
6+
[id="nw-networkpolicy-same-namespace-communication_{context}"]
7+
= Creating a network policy for same namespace communication
8+
9+
Advanced users who know exactly which pod-to-pod connections should be allowed in their application can explicitly allow each connection. The following `allow-server-to-access` network policy allows pods in *Deployment A* to communicate with pods in *Deployment B*, and shows you how to reference that connection.
10+
11+
.Prerequisites
12+
13+
* You have created the `deny-by-default` network policy and applied it to all necessary namespaces.
14+
* You have created an `internet-access` network policy and applied it to all necessary namespaces.
15+
16+
.Procedure
17+
18+
. Create the following `allow-server-to-access` network policy to allow pods across deployments to communicate with each other. Save the YAML in the `allow-server-to-access` file:
19+
+
20+
[source,yaml]
21+
----
22+
apiVersion: networking.k8s.io/v1
23+
kind: NetworkPolicy
24+
metadata:
25+
name: allow-server-to-access
26+
spec:
27+
podSelector: # target pods
28+
matchLabels:
29+
deployment-b-pod-label-1-key: deployment-b-pod-label-1-value
30+
deployment-b-pod-label-2-key: deployment-b-pod-label-2-value
31+
policyTypes:
32+
- Ingress
33+
ingress:
34+
- from: # allow traffic from
35+
- podSelector:
36+
matchLabels:
37+
deployment-a-pod-label-1-key: deployment-a-pod-label-1-value
38+
deployment-a-pod-label-2-key: deployment-a-pod-label-2-value
39+
----
40+
+
41+
[NOTE]
42+
====
43+
This network policy allows pods to communicate from *Deployment A* -> *Deployment B*, but not *Deployment B* -> *Deployment A*. To allow communication in reverse direction, a separate policy applied to *Deployment A's* pods would need created and applied.
44+
====
45+
46+
. Label the pods in *Deployment B* with the `deployment-b-pod-label-1-key=deployment-b-pod-label-1-value` label by entering the following command:
47+
+
48+
[source,terminal]
49+
----
50+
$ oc label pod <deployment-b-pod-name> deployment-b-pod-label-1-key=deployment-b-pod-label-1-value
51+
----
52+
53+
. Label the pods in *Deployment B* with the `deployment-b-pod-label-2-key=deployment-b-pod-label-2-value` label by entering the following command:
54+
+
55+
[source,terminal]
56+
----
57+
$ oc label pod <deployment-b-pod-name> deployment-b-pod-label-2-key=deployment-b-pod-label-2-value
58+
----
59+
60+
. Label the pods in *Deployment A* with the `deployment-a-pod-label-1-key=deployment-a-pod-label-1-value` label by entering the following command:
61+
+
62+
[source,terminal]
63+
----
64+
$ oc label pod <deployment-a-pod-name> deployment-a-pod-label-1-key=deployment-a-pod-label-1-value
65+
----
66+
67+
. Label the pods in *Deployment A* with the `deployment-a-pod-label-2-key=deployment-a-pod-label-2-value` label by entering the following command:
68+
+
69+
[source,terminal]
70+
----
71+
$ oc label pod <deployment-a-pod-name> deployment-a-pod-label-2-key=deployment-a-pod-label-2-value
72+
----
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
:_mod-docs-content-type: ASSEMBLY
2+
[id="nw-networkpolicy-full-multitenant-isolation"]
3+
= Configuring full multitenant isolation with network policy using ingress and egress
4+
include::_attributes/common-attributes.adoc[]
5+
:context: multitenant-network-policy
6+
7+
toc::[]
8+
9+
As a cluster administrator, you can configure ingress and egress network policies to enforce full multitenant isolation between project namespaces. This ensures that pods can only communicate with explicitly allowed services or destinations, which helps improve the security of your deployment.
10+
11+
[NOTE]
12+
====
13+
Configuring network policies as described in this section provides network isolation similar to the multitenant mode of OpenShift SDN in previous versions of {product-title}.
14+
====
15+
16+
17+
//ingress
18+
include::modules/nw-networkpolicy-multitenant-isolation-ingress.adoc[leveloffset=+1]
19+
include::modules/nw-networkpolicy-deny-all-allowed.adoc[leveloffset=+2]
20+
include::modules/nw-networkpolicy-allow-internet.adoc[leveloffset=+2]
21+
include::modules/nw-networkpolicy-pod-pod-communication.adoc[leveloffset=+2]
22+
include::modules/nw-networkpolicy-same-namespace-communication.adoc[leveloffset=+3]
23+
24+
//egress
25+
include::modules/nw-networkpolicy-multitenant-isolation-egress.adoc[leveloffset=+1]

0 commit comments

Comments
 (0)