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
cluster. An egress firewall supports the following scenarios:
-
A pod can only connect to internal hosts and cannot initiate connections to
the public internet.
-
A pod can only connect to the public internet and cannot initiate connections
to internal hosts that are outside the OKD cluster.
-
A pod cannot reach specified internal subnets or hosts outside the OKD cluster.
-
A pod can connect to only specific external hosts.
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.
|
egress firewall does not apply to the host network namespace. Pods with host networking enabled are unaffected by egress firewall rules.
|
You configure an egress firewall policy by creating an egressNetworkPolicy custom resource (CR) object. The egress firewall matches network traffic that meets any of the following criteria:
|
If your egress firewall includes a deny rule for 0.0.0.0/0 , access to your OKD 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.
The following example illustrates the order of the egress firewall rules necessary to ensure API server access:
apiVersion: network.openshift.io/v1
kind: egressNetworkPolicy
metadata:
name: default
namespace: <namespace> (1)
spec:
egress:
- to:
cidrSelector: <api_server_address_range> (2)
type: Allow
# ...
- to:
cidrSelector: 0.0.0.0/0 (3)
type: Deny
1 |
The namespace for the egress firewall. |
2 |
The IP address range that includes your OKD API servers. |
3 |
A global deny rule prevents access to the OKD API servers. |
To find the IP address for your API servers, run oc get ep kubernetes -n default .
|
|
You must have OpenShift SDN configured to use either the network policy or multitenant mode to configure an egress firewall.
If you use network policy mode, an egress firewall is compatible with only one policy per namespace and will not work with projects that share a network, such as global projects.
|
|
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.
|
Limitations of an egress firewall
An egress firewall has the following limitations:
-
No project can have more than one egressNetworkPolicy object.
|
The creation of more than one egressNetworkPolicy object is allowed, however it should not be done. When you create more than one egressNetworkPolicy object, the following message is returned: dropping all rules . In actuality, all external traffic is dropped, which can cause security risks for your organization.
|
-
A maximum of one egressNetworkPolicy object with a maximum of 1,000 rules can be defined per project.
-
The default
project cannot use an egress firewall.
-
When using the OpenShift SDN network plugin in multitenant mode, the following limitations apply:
-
Global projects cannot use an egress firewall. You can make a project global by using the oc adm pod-network make-projects-global
command.
-
Projects merged by using the oc adm pod-network join-projects
command cannot use an egress firewall in any of the joined projects.
-
If you create a selectorless service and manually define endpoints or EndpointSlices
that point to external IPs, traffic to the service IP might still be allowed, even if your egressNetworkPolicy
is configured to deny all egress traffic. This occurs because OpenShift SDN does not fully enforce egress network policies for these external endpoints. Consequently, this might result in unexpected access to external services.
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.
An egress Firewall resource can be created in the kube-node-lease
, kube-public
, kube-system
, openshift
and openshift-
projects.
Matching order for egress firewall policy rules
The egress firewall policy rules are evaluated in the order that they are defined, from first to last. The first rule that matches an egress connection from a pod applies. Any subsequent rules are ignored for that connection.
How Domain Name Server (DNS) resolution works
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:
-
Domain name updates are polled based on a time-to-live (TTL) duration. By default, the duration is 30 seconds. When the egress firewall controller queries the local name servers for a domain name, if the response includes a TTL that is less than 30 seconds, the controller sets the duration to the returned value. If the TTL in the response is greater than 30 minutes, the controller sets the duration to 30 minutes. If the TTL is between 30 seconds and 30 minutes, the controller ignores the value and sets the duration to 30 seconds.
-
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.
-
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 egressNetworkPolicy objects is only recommended for domains with infrequent IP address changes.
|
Using 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.
|