Skip to content

Commit 27ee13a

Browse files
committed
OSDOCS-13364-egfw:separates OVN-K egress firewall from SDN egressnetworkpolicy
1 parent b91e3ca commit 27ee13a

17 files changed

+511
-331
lines changed

modules/nw-coredns-egress-firewall.adoc

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,22 @@ include::snippets/technology-preview.adoc[]
1919
apiVersion: networking.openshift.io/v1alpha1
2020
kind: DNSNameResolver
2121
spec:
22-
name: www.example.com. <1>
22+
name: www.example.com.
2323
status:
2424
resolvedNames:
25-
- dnsName: www.example.com. <2>
25+
- dnsName: www.example.com.
2626
resolvedAddress:
27-
- ip: "1.2.3.4" <3>
28-
ttlSeconds: 60 <4>
29-
lastLookupTime: "2023-08-08T15:07:04Z" <5>
27+
- ip: "1.2.3.4"
28+
ttlSeconds: 60
29+
lastLookupTime: "2023-08-08T15:07:04Z"
3030
----
31-
<1> The DNS name. This can be either a standard DNS name or a wildcard DNS name. For a wildcard DNS name, the DNS name resolution information contains all of the DNS names that match the wildcard DNS name.
32-
<2> The resolved DNS name matching the `spec.name` field. If the `spec.name` field contains a wildcard DNS name, then multiple `dnsName` entries are created that contain the standard DNS names that match the wildcard DNS name when resolved. If the wildcard DNS name can also be successfully resolved, then this field also stores the wildcard DNS name.
33-
<3> The current IP addresses associated with the DNS name.
34-
<4> The last time-to-live (TTL) duration.
35-
<5> The last lookup time.
31+
where:
32+
33+
<name>:: Specifies the DNS name. This can be either a standard DNS name or a wildcard DNS name. For a wildcard DNS name, the DNS name resolution information contains all of the DNS names that match the wildcard DNS name.
34+
<dnsName>:: Specifies the resolved DNS name matching the `spec.name` field. If the `spec.name` field contains a wildcard DNS name, then multiple `dnsName` entries are created that contain the standard DNS names that match the wildcard DNS name when resolved. If the wildcard DNS name can also be successfully resolved, then this field also stores the wildcard DNS name.
35+
<ip> Specifies the current IP addresses associated with the DNS name.
36+
<ttlSeconds>:: Specifies the last time-to-live (TTL) duration.
37+
<lastLookupTime>:: Specifies the last lookup time.
3638

3739
If during DNS resolution the DNS name in the query matches any name defined in a `DNSNameResolver` CR, then the previous information is updated accordingly in the CR `status` field. For unsuccessful DNS wildcard name lookups, the request is retried after a default TTL of 30 minutes.
3840

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * networking/network_security/configuring-egress-firewall-ovn.adoc
4+
5+
:_mod-docs-content-type: CONCEPT
6+
[id="nw-egress-firewall-about_{context}"]
7+
= How an egress firewall works in a project
8+
9+
As a cluster administrator, you can use an _egress firewall_ to limit the external hosts that some or all pods can access from within the
10+
cluster. An egress firewall supports the following scenarios:
11+
12+
- A pod can only connect to internal hosts and cannot initiate connections to
13+
the public internet.
14+
- A pod can only connect to the public internet and cannot initiate connections
15+
to internal hosts that are outside the {product-title} cluster.
16+
- A pod cannot reach specified internal subnets or hosts outside the {product-title} cluster.
17+
- A pod can only connect to specific external hosts.
18+
19+
For example, you can allow one project access to a specified IP range but deny the same access to a different project. Or, you can restrict application developers from updating from Python pip mirrors, and force updates to come only from approved sources.
20+
21+
You configure an egress firewall policy by creating an `EgressFirewall` custom resource (CR). The egress firewall matches network traffic that meets any of the following criteria:
22+
23+
- An IP address range in CIDR format
24+
- A DNS name that resolves to an IP address
25+
- A port number
26+
- A protocol that is one of the following protocols: TCP, UDP, and SCTP
27+
28+
[id="limitations-of-an-egress-firewall-ovn-k_{context}"]
29+
== Limitations of an egress firewall
30+
31+
An egress firewall has the following limitations:
32+
33+
* No project can have more than one `EgressFirewall` CR.
34+
35+
* Egress firewall rules do not apply to traffic that goes through routers. Any user with permission to create a `Route` CR object can bypass egress firewall policy rules by creating a route that points to a forbidden destination.
36+
37+
* Egress firewall does not apply to the host network namespace. Pods with host networking enabled are unaffected by egress firewall rules.
38+
39+
* If your egress firewall includes a deny rule for `0.0.0.0/0`, access to your {product-title} API servers is blocked. You must either add allow rules for each IP address or use the `nodeSelector` type allow rule in your egress policy rules to connect to API servers.
40+
+
41+
The following example illustrates the order of the egress firewall rules necessary to ensure API server access:
42+
+
43+
.`EgressFirewall` API server access example
44+
[source,yaml,subs="attributes+"]
45+
----
46+
apiVersion: k8s.ovn.org/v1
47+
kind: EgressFirewall
48+
metadata:
49+
name: default
50+
namespace: <namespace> <1>
51+
spec:
52+
egress:
53+
- to:
54+
cidrSelector: <api_server_address_range> <2>
55+
type: Allow
56+
# ...
57+
- to:
58+
cidrSelector: 0.0.0.0/0 <3>
59+
type: Deny
60+
----
61+
+
62+
where:
63+
64+
<namespace>:: Specifies the namespace for the egress firewall.
65+
<api_server_address_range>:: Specifies the IP address range that includes your {product-title} API servers.
66+
<cidrSelector>:: Specifies a value of `0.0.0.0/0` to set a global deny rule that prevents access to the {product-title} API servers.
67+
+
68+
To find the IP address for your API servers, run `oc get ep kubernetes -n default`.
69+
+
70+
For more information, see link:https://bugzilla.redhat.com/show_bug.cgi?id=1988324[BZ#1988324].
71+
72+
* A maximum of one `EgressFirewall` object with a maximum of 8,000 rules can be defined per project.
73+
74+
* If you are using the OVN-Kubernetes network plugin with shared gateway mode in Red{nbsp}Hat OpenShift Networking, return ingress replies are affected by egress firewall rules. If the egress firewall rules drop the ingress reply destination IP, the traffic is dropped.
75+
76+
* In general, using Domain Name Server (DNS) names in your egress firewall policy does not affect local DNS resolution through CoreDNS. However, if your egress firewall policy uses domain names and an external DNS server handles DNS resolution for an affected pod, you must include egress firewall rules that permit access to the IP addresses of your DNS server.
77+
78+
Violating any of these restrictions results in a broken egress firewall for the project. Consequently, all external network traffic is dropped, which can cause security risks for your organization.
79+
80+
An `EgressFirewall` resource is created in the `kube-node-lease`, `kube-public`, `kube-system`, `openshift` and `openshift-` projects.
81+
82+
[id="policy-rule-order-ovn-k_{context}"]
83+
== Matching order for egress firewall policy rules
84+
85+
OVN-Kubernetes evaluates egress firewall policy rules in the order they are defined in, from first to last. The first rule that matches an egress connection from a pod applies. Any subsequent rules are ignored for that connection.
86+
87+
[id="domain-name-server-resolution-ovn-k_{context}"]
88+
== How Domain Name Server (DNS) resolution works
89+
90+
If you use DNS names in any of your egress firewall policy rules, proper resolution of the domain names is subject to the following restrictions:
91+
92+
* Domain name updates are polled based on a time-to-live (TTL) duration. By default, the duration is 30 minutes. When the egress firewall controller queries the local name servers for a domain name, if the response includes a TTL and the TTL is less than 30 minutes, the controller sets the duration for that DNS name to the returned value. Each DNS name is queried after the TTL for the DNS record expires.
93+
94+
* The pod must resolve the domain from the same local name servers when necessary. Otherwise the IP addresses for the domain known by the egress firewall controller and the pod can be different. If the IP addresses for a hostname differ, the egress firewall might not be enforced consistently.
95+
96+
* Because the egress firewall controller and pods asynchronously poll the same local name server, the pod might obtain the updated IP address before the egress controller does, which causes a race condition. Due to this current limitation, domain name usage in `EgressFirewall` objects is only recommended for domains with infrequent IP address changes.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * networking/network_security/configuring-egress-firewall-ovn.adoc
4+
5+
:_mod-docs-content-type: PROCEDURE
6+
[id="nw-egress-firewall-policy-create_{context}"]
7+
= Creating an EgressFirewall custom resource (CR)
8+
9+
As a cluster administrator, you can create an egress firewall policy object for a project.
10+
11+
[IMPORTANT]
12+
====
13+
If the project already has an `EgressFirewall` resource, you must edit the existing policy to make changes to egress firewall rules.
14+
====
15+
16+
.Prerequisites
17+
18+
* A cluster that uses the OVN-Kubernetes network plugin.
19+
* Install the OpenShift CLI (`oc`).
20+
* You must log in to the cluster as a cluster administrator.
21+
22+
.Procedure
23+
24+
. Create a policy rule:
25+
.. Create a `<policy_name>.yaml` file where `<policy_name>` describes the egress
26+
policy rules.
27+
.. Define the `EgressFirewall` object in the file.
28+
29+
. Create the policy object by entering the following command. Replace `<policy_name>` with the name of the policy and `<project>` with the project that the rule applies to.
30+
+
31+
[source,terminal]
32+
----
33+
$ oc create -f <policy_name>.yaml -n <project>
34+
----
35+
+
36+
Successful output lists the `egressfirewall.k8s.ovn.org/v1` name and the `created` status.
37+
38+
. Optional: Save the `<policy_name>.yaml` file so that you can make changes later.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * networking/ovn_kubernetes_network_provider/removing-egress-firewall-ovn.adoc
4+
5+
:_mod-docs-content-type: PROCEDURE
6+
[id="nw-egress-firewall-delete_{context}"]
7+
= Removing an EgressFirewall CR
8+
9+
As a cluster administrator, you can remove an egress firewall from a project.
10+
11+
.Prerequisites
12+
13+
* A cluster using the OVN-Kubernetes network plugin.
14+
* Install the OpenShift CLI (`oc`).
15+
* You must log in to the cluster as a cluster administrator.
16+
17+
.Procedure
18+
19+
. Find the name of the `EgressFirewall` CR for the project. Replace `<project>` with the name of the project.
20+
+
21+
[source,terminal,subs="attributes+"]
22+
----
23+
$ oc get egressfirewall -n <project>
24+
----
25+
26+
. Delete the `EgressFirewall` CR by entering the following command. Replace `<project>` with the name of the project and `<name>` with the name of the object.
27+
+
28+
[source,terminal,subs="attributes+"]
29+
----
30+
$ oc delete -n <project> egressfirewall <name>
31+
----
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * networking/ovn_kubernetes_network_provider/editing-egress-firewall-ovn.adoc
4+
5+
:_mod-docs-content-type: PROCEDURE
6+
[id="nw-egress-firewall-edit_{context}"]
7+
= Editing an EgressFirewall custom resource (CR)
8+
9+
As a cluster administrator, you can update the egress firewall for a project.
10+
11+
.Prerequisites
12+
13+
* A cluster using the OVN-Kubernetes network plugin.
14+
* Install the OpenShift CLI (`oc`).
15+
* You must log in to the cluster as a cluster administrator.
16+
17+
.Procedure
18+
19+
. Find the name of the `EgressFirewall` CR for the project. Replace `<project>` with the name of the project.
20+
+
21+
[source,terminal,subs="attributes+"]
22+
----
23+
$ oc get -n <project> egressfirewall
24+
----
25+
26+
. Optional: If you did not save a copy of the `EgressFirewall` object when you created the egress network firewall, enter the following command to create a copy.
27+
+
28+
[source,terminal,subs="attributes+"]
29+
----
30+
$ oc get -n <project> egressfirewall <name> -o yaml > <filename>.yaml
31+
----
32+
+
33+
Replace `<project>` with the name of the project. Replace `<name>` with the name of the object. Replace `<filename>` with the name of the file to save the YAML to.
34+
35+
. After making changes to the policy rules, enter the following command to replace the `EgressFirewall` CR. Replace `<filename>` with the name of the file containing the updated `EgressFirewall` CR.
36+
+
37+
[source,terminal]
38+
----
39+
$ oc replace -f <filename>.yaml
40+
----
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * networking/network_security/configuring-egress-firewall-ovn.adoc
4+
5+
:_mod-docs-content-type: REFERENCE
6+
[id="nw-egress-firewall-object_{context}"]
7+
= EgressFirewall custom resource (CR)
8+
9+
You can define one or more rules for an egress firewall. A rule is either an `Allow` rule or a `Deny` rule, with a specification for the traffic that the rule applies to.
10+
11+
The following YAML describes an `EgressFirewall` CR:
12+
13+
.EgressFirewall object
14+
[source,yaml,subs="attributes+"]
15+
----
16+
apiVersion: k8s.ovn.org/v1
17+
kind: EgressFirewall
18+
metadata:
19+
name: <ovn>
20+
spec:
21+
egress: <egress_rules>
22+
...
23+
----
24+
where:
25+
26+
<ovn>:: The name for the object must be `default`.
27+
<egress_rules>:: Specifies a collection of one or more egress network policy rules as described in the following section.
28+
29+
[id="egress-firewall-rules_{context}"]
30+
== EgressFirewall rules
31+
32+
The following YAML describes the rules for an `EgressFirewall` resource. The user can select either an IP address range in CIDR format, a domain name, or use the `nodeSelector` field to allow or deny egress traffic. The `egress` stanza expects an array of one or more objects.
33+
34+
// - OVN-Kubernetes does not support DNS
35+
// - OpenShift SDN does not support port and protocol specification
36+
37+
.Egress policy rule stanza
38+
[source,yaml]
39+
----
40+
egress:
41+
- type: <type>
42+
to:
43+
cidrSelector: <cidr_range>
44+
dnsName: <dns_name>
45+
nodeSelector: <label_name>: <label_value>
46+
ports: <optional_port>
47+
...
48+
----
49+
where:
50+
51+
<type>:: Specifies the type of rule. The value must be either `Allow` or `Deny`.
52+
<to>:: Specifies a stanza describing an egress traffic match rule that specifies the `cidrSelector` field or the `dnsName` field. You cannot use both fields in the same rule.
53+
<cidr_range>:: Specifies an IP address range in CIDR format.
54+
<dns_name>:: Specifies a DNS domain name.
55+
<nodeSelector>:: Specifies labels which are key and value pairs that the user defines. Labels are attached to objects, such as pods. The `nodeSelector` allows for one or more node labels to be selected and attached to pods.
56+
<ports>:: Specifies an optional field that describes a collection of network ports and protocols for the rule.
57+
58+
.Ports stanza
59+
[source,yaml]
60+
----
61+
ports:
62+
- port:
63+
protocol:
64+
----
65+
where:
66+
67+
<port>:: Specifies a network port, such as `80` or `443`. If you specify a value for this field, you must also specify a value for the `protocol` field.
68+
<protocol>:: Specifies a network protocol. The value must be either `TCP`, `UDP`, or `SCTP`.
69+
70+
[id="egress-firewall-example_{context}"]
71+
== Example EgressFirewall CR
72+
73+
The following example defines several egress firewall policy rules:
74+
75+
[source,yaml,subs="attributes+"]
76+
----
77+
apiVersion: k8s.ovn.org/v1
78+
kind: EgressFirewall
79+
metadata:
80+
name: default
81+
spec:
82+
egress: <1>
83+
- type: Allow
84+
to:
85+
cidrSelector: 1.2.3.0/24
86+
- type: Deny
87+
to:
88+
cidrSelector: 0.0.0.0/0
89+
----
90+
where:
91+
92+
<egress>:: Specifies a collection of egress firewall policy rule objects.
93+
94+
The following example defines a policy rule that denies traffic to the host at the `172.16.1.1/32` IP address, if the traffic is using either the TCP protocol and destination port `80` or any protocol and destination port `443`.
95+
96+
[source,yaml,subs="attributes+"]
97+
----
98+
apiVersion: k8s.ovn.org/v1
99+
kind: EgressFirewall
100+
metadata:
101+
name: default
102+
spec:
103+
egress:
104+
- type: Deny
105+
to:
106+
cidrSelector: 172.16.1.1/32
107+
ports:
108+
- port: 80
109+
protocol: TCP
110+
- port: 443
111+
----
112+
113+
[id="configuring-NodeSelector-egfw-example_{context}"]
114+
== Example EgressFirewall CR using nodeSelector
115+
116+
As a cluster administrator, you can allow or deny egress traffic to nodes in your cluster by specifying a label using `nodeSelector` field. Labels can be applied to one or more nodes. Labels can be helpful because instead of adding manual rules per node IP address, you can use node selectors to create a label that allows pods behind an egress firewall to access host network pods. The following is an example with the `region=east` label:
117+
118+
[source,yaml,subs="attributes+"]
119+
----
120+
apiVersion: k8s.ovn.org/v1
121+
kind: EgressFirewall
122+
metadata:
123+
name: default
124+
spec:
125+
egress:
126+
- to:
127+
nodeSelector:
128+
matchLabels:
129+
region: east
130+
type: Allow
131+
----

0 commit comments

Comments
 (0)