Chapter 2. Configure Loki network policies


You can deploy and manage network policies that restrict communications to and from Loki components to enhance security.

2.1. Loki network policies for added security

The Loki Operator can deploy and manage a set of network policies that restrict communications to and from Loki components to enhance security. These network policies control ingress and egress traffic at the pod level, limiting exposure to only necessary services while allowing integration with external monitoring systems when required.

2.1.1. Configure a network policy for Loki

Enable or disable the deployment of NetworkPolicies per LokiStack by setting the networkPolicies field.

Prerequisites

  • You have administrator permissions.
  • You have installed the OpenShift CLI (oc).
  • You have installed the Loki Operator.
  • You have created a LokiStack custom resource (CR).

Procedure

  1. Update the LokiStack CR:

    apiVersion: loki.grafana.com/v1
    kind: LokiStack
    metadata:
      name: logging-loki
      namespace: openshift-logging
    spec:
      size: 1x.small
      storage:
        schemas:
        - version: v13
          effectiveDate: "<yyyy>-<mm>-<dd>"
        secret:
          name: logging-loki-s3
          type: s3
      storageClassName: <storage_class_name>
      tenants:
        mode: openshift-logging
      networkPolicies:
        ruleSet: RestrictIngressEgress

    You can set one of the following values for the spec.networkPolicies.ruleSet field:

    None
    Loki Operator will not deploy any network policy.
    RestrictIngressEgress

    Loki Operator will deploy a set of network policies that restrict the communications to and from the Loki components.

    If you do not define a spec.networkPolicies.ruleSet value, the platform and operator default values are inherited and full network access is allowed.

  2. Apply the LokiStack CR object by running the following command:

    $ oc apply -f <filename>.yaml

2.1.2. Loki NetworkPolicy resources

When network policies are enabled, the Loki Operator creates several NetworkPolicy resources to secure different aspects of your LokiStack deployment.

Policy name

Purpose

Components affected

{name}-default-deny

A baseline deny-all policy

All LokiStack pods

{name}-loki-allow

Inter-component communication allowed

All Loki components

{name}-loki-allow-metrics

Allow metric scraping on the prometheus endpoint

All Loki components

{name}-loki-allow-bucket-egress

Policy for object storage access

ingester, querier, index-gateway, compactor, ruler

{name}-loki-allow-gateway-ingress

Allow gateway access to Loki components

distributor, query-frontend, ruler

{name}-gateway-allow

Gateway external and monitoring access

LokiStack-gateway

{name}-gateway-allow-metrics

Allow metric scraping on the prometheus endpoint

LokiStack-gateway

{name}-ruler-allow-alert-egress

Allow ruler egress to AlertManager

ruler

{name}-loki-allow-query-frontend

Query front-end external access

query-frontend (OpenShift network mode)

Create additional network policies to integrate Loki with external systems.

To integrate Loki with external systems such as custom dashboards, or external alerting, create additional network policies. You can select specific components by using the label app.kubernetes.io/component. Always include the labels app.kubernetes.io/name=lokistack and app.kubernetes.io/instance={name} to avoid collision with other pods deployed in the namespace.

Prerequisites

  • You have administrator permissions.
  • You have installed the OpenShift CLI (oc).
  • You have installed the Loki Operator.
  • You have created a LokiStack custom resource (CR).

Procedure

  1. Create a network policy:

    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy
    metadata:
      name: <name>
    spec:
      podSelector:
        matchLabels:
          app.kubernetes.io/name: lokistack
          app.kubernetes.io/instance: <instance_name>
          app.kubernetes.io/component: <loki_component>
      policyTypes:
      - Egress
      egress:
      - to:
        - namespaceSelector:
            matchLabels:
              kubernetes.io/metadata.name: <namespace_name>
        ports:
        - protocol: TCP
          port: <port_number>

    Replace <component_name> with the component you want to integrate with.

  2. Apply the network policy:

    $ oc apply -f <file_name>.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