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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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
LokiStackcustom resource (CR).
Procedure
Update the
LokiStackCR: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: RestrictIngressEgressYou can set one of the following values for the
spec.networkPolicies.ruleSetfield:None- Loki Operator will not deploy any network policy.
RestrictIngressEgressLoki 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.ruleSetvalue, the platform and operator default values are inherited and full network access is allowed.
Apply the
LokiStackCR object by running the following command:$ oc apply -f <filename>.yaml
2.1.2. Loki NetworkPolicy resources Copy linkLink copied to clipboard!
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 |
|
| {name}-loki-allow-gateway-ingress | Allow gateway access to Loki components |
|
| {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 |
|
|
| Query front-end external access |
|
2.1.3. Integrate a Loki network policy with external systems Copy linkLink copied to clipboard!
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
LokiStackcustom resource (CR).
Procedure
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.
Apply the network policy:
$ oc apply -f <file_name>.yaml