Chapter 3. Configure collector network policies
You can configure network policies to enable the collector to operate in clusters with restrictive network configurations.
3.1. Collector network policy Copy linkLink copied to clipboard!
Red Hat OpenShift Logging Operator creates a NetworkPolicy resource for the collector pods when a ClusterLogForwarder resource is deployed if you specify a network policy rule set in the ClusterLogForwarder custom resource (CR). NetworkPolicy resources are automatically created, updated, and removed along with the component deployment lifecycle.
You can specify the network policy rule set by defining the networkPolicy.ruleSet field in the collector specification. The collector supports the following network policy rule set types:
AllowAllIngressEgress- Allows all ingress and egress traffic.
RestrictIngressEgress- Restricts traffic to specific ports based on the configured inputs, outputs, and the metrics port.
If you do not define a spec.collector.networkPolicy field, the Operator will not create a NetworkPolicy resource for the collector. Without a NetworkPolicy resource, logging components might not function if a cluster-wide AdminNetworkPolicy restricts traffic or other restrictive network policies are in place.
3.2. Configure a network policy rule set for the collector Copy linkLink copied to clipboard!
Define a network policy rule set so that Red Hat OpenShift Logging Operator creates a NetworkPolicy resource for the collector pods when the ClusterLogForwarder resource is deployed. The NetworkPolicy resource overrides network restrictions to ensure that the permitted ingress and egress traffic for the collector pods is allowed to flow.
Prerequisites
- You have administrator permissions.
-
You have installed the OpenShift CLI (
oc). - You have installed the Red Hat OpenShift Logging Operator.
-
You have created a
ClusterLogForwardercustom resource (CR).
Procedure
Update the
ClusterLogForwarderCR:apiVersion: observability.openshift.io/v1 kind: ClusterLogForwarder metadata: name: my-forwarder namespace: openshift-logging spec: collector: networkPolicy: ruleSet: <RestrictIngressEgress_or_AllowAllIngressEgress> # ...Where the value for the
ruleSetfield can be eitherRestrictIngressEgressorAllowAllIngressEgress.Apply the configuration by running the following command:
$ oc apply -f <filename>.yaml
3.3. LogFileMetricExporter network policy Copy linkLink copied to clipboard!
Red Hat OpenShift Logging Operator creates a NetworkPolicy resource for the metric exporter pods when a LogFileMetricExporter resource is deployed if you specify a network policy rule set in the LogFileMetricExporter custom resource (CR). NetworkPolicy resources are automatically created, updated, and removed along with the component deployment lifecycle.
The LogFileMetricExporter resource supports the following network policy rule set types:
AllowIngressMetrics- Allows ingress traffic only on the metrics port, denies all egress traffic.
AllowAllIngressEgress- Allows all ingress and egress traffic.
If you do not define a spec.networkPolicy field, the Operator will not create a NetworkPolicy resource for the LogFileMetricExporter. Without a NetworkPolicy resource, logging components might not function if a cluster-wide AdminNetworkPolicy restricts traffic or other restrictive network policies are in place.
3.4. Configure a network policy rule set for LogFileMetricExporter Copy linkLink copied to clipboard!
Define a network policy rule set so that Red Hat OpenShift Logging Operator creates a NetworkPolicy resource for the LogFileMetricExporter pods when the LogFileMetricExporter resource is deployed. The NetworkPolicy resource overrides network restrictions to ensure that the permitted ingress and egress traffic for the LogFileMetricExporter pods is allowed to flow.
Prerequisites
- You have administrator permissions.
-
You have installed the OpenShift CLI (
oc). - You have installed the Red Hat OpenShift Logging Operator.
-
You have created a
LogFileMetricExporterCR.
Procedure
Update the
LogFileMetricExporterCR:apiVersion: logging.openshift.io/v1alpha1 kind: LogFileMetricExporter metadata: name: my-lfme namespace: openshift-logging spec: networkPolicy: ruleSet: <AllowAllIngressEgress_or_AllowIngressMetrics> #...Where the value for the
ruleSetfield can be eitherAllowAllIngressEgressorAllowIngressMetrics.Apply the configuration by running the following command:
$ oc apply -f <filename>.yaml
3.5. Create an AdminNetworkPolicy rule for resources managed by Red Hat OpenShift Logging Operator Copy linkLink copied to clipboard!
To ensure that the pods running resources managed by Red Hat OpenShift Logging Operator can communicate when an AdminNetworkPolicy configuration is blocking traffic, create an AdminNetworkPolicy rule that delegates to a NetworkPolicy definition.
OpenShift Container Platform network policy precedence:
-
AdminNetworkPolicy: Cluster-admin controlled, highest priority. -
BaselineAdminNetworkPolicy: Default fallback rules. -
NetworkPolicy: Namespace-level policies. This is where collector policies reside.
Prerequisites
- You have administrator permissions.
-
You installed the OpenShift CLI (
oc).
Procedure
Create an
AdminNetworkPolicyrule:apiVersion: policy.networking.k8s.io/v1alpha1 kind: AdminNetworkPolicy metadata: name: allow-logging-collector-delegation spec: priority: 50 # Adjust based on your cluster's ANP priority scheme. Lower number means higher priority subject: pods: # Target the pods in openshift-logging namespace namespaceSelector: matchLabels: kubernetes.io/metadata.name: openshift-logging podSelector: matchLabels: app.kubernetes.io/name: <name> app.kubernetes.io/instance: <instance> app.kubernetes.io/managed-by: cluster-logging-operator app.kubernetes.io/part-of: cluster-logging app.kubernetes.io/component: <component> ingress: - name: "delegate-to-collector-ingress" action: "Pass" from: # Select all pods in all namespaces as the source. - pods: namespaceSelector: {} podSelector: {} egress: - name: "delegate-to-collector-egress" action: "Pass" to: # Select all pods in all namespaces for internal traffic. - pods: namespaceSelector: {} podSelector: {} # Select all external destinations for egress traffic. - networks: - "0.0.0.0/0" - "::/0"To apply this network policy to all the resources in a namespace, remove
app.kubernetes.io/name,app.kubernetes.io/instance, andapp.kubernetes.io/componentfields. To apply the admin network policy to specific resources, define the fields as follows:-
Replace
<name>with the name of the collector or theLogFileMetricExporterresource. -
Replace
<instance>with the instance name of the collector or theLogFileMetricExporterresource. -
Replace
<component>with the valuecollectororlogfilesmetricexporter.
-
Replace
Apply the
AdminNetworkPolicyrule by running the following command:$ oc apply -f <filename>.yaml