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

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.

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 ClusterLogForwarder custom resource (CR).

Procedure

  1. Update the ClusterLogForwarder CR:

    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 ruleSet field can be either RestrictIngressEgress or AllowAllIngressEgress.

  2. Apply the configuration by running the following command:

    $ oc apply -f <filename>.yaml

3.3. LogFileMetricExporter network policy

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.

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 LogFileMetricExporter CR.

Procedure

  1. Update the LogFileMetricExporter CR:

    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 ruleSet field can be either AllowAllIngressEgress or AllowIngressMetrics.

  2. Apply the configuration by running the following command:

    $ oc apply -f <filename>.yaml

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

  1. Create an AdminNetworkPolicy rule:

    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, and app.kubernetes.io/component fields. To apply the admin network policy to specific resources, define the fields as follows:

    • Replace <name> with the name of the collector or the LogFileMetricExporter resource.
    • Replace <instance> with the instance name of the collector or the LogFileMetricExporter resource.
    • Replace <component> with the value collector or logfilesmetricexporter.
  2. Apply the AdminNetworkPolicy rule by running the following command:

    $ oc apply -f <filename>.yaml
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat Documentation

Legal Notice

Theme

© 2026 Red Hat
Back to top