operator/docs/user-guides/network_policies.md
Network policies provide network segmentation for your LokiStack deployment by controlling ingress and egress traffic between Loki components and external services. When enabled, the Loki Operator automatically creates Kubernetes NetworkPolicy resources that implement a "default deny" security model with explicit allow rules for required communications.
This guide covers how to configure and understand network policies for your LokiStack deployment.
On standard Kubernetes clusters:
Network policies on OpenShift include additional integrations:
Network policies are configured through the networkPolicies field in your LokiStack specification:
apiVersion: loki.grafana.com/v1
kind: LokiStack
metadata:
name: lokistack-sample
namespace: openshift-logging
spec:
size: 1x.small
storage:
secret:
name: lokistack-object-storage
type: s3
storageClassName: gp3-csi
tenants:
mode: openshift-logging
networkPolicies:
ruleSet: RestrictIngressEgress # Enable network policies
| Configuration | Description | Behavior |
|---|---|---|
networkPolicies: null (omitted) | Default - inherit platform and operator defaults | Currently allows full network access everywhere |
networkPolicies.ruleSet: None | Disabled - no network policies created | Full network access allowed |
networkPolicies.ruleSet: RestrictIngressEgress | Enabled - network policies enforced | Restricted network access with explicit allow rules |
When network policies are enabled, the Loki Operator creates several NetworkPolicy resources to secure different aspects of your LokiStack deployment:
| Policy Name | Purpose | Affected Components |
|---|---|---|
{name}-default-deny | Baseline deny-all policy | All LokiStack pods |
{name}-loki-allow | Inter-component communication | All Loki components |
{name}-loki-allow-bucket-egress | Object storage access | ingester, querier, index-gateway, compactor, ruler |
{name}-loki-allow-gateway-ingress | Gateway access to Loki components | distributor, query-frontend, ruler |
{name}-gateway-allow | Gateway external & monitoring access | lokistack-gateway |
{name}-ruler-allow-alert-egress | Ruler egress to AlertManager | ruler |
{name}-loki-allow-query-frontend | Query frontend external access | query-frontend (OpenShift network mode) |
| Component | From Gateway | From Components | From External | From Monitoring |
|---|---|---|---|---|
| distributor | ✅ | ✅ | ❌ | ✅ |
| ingester | ❌ | ✅ | ❌ | ✅ |
| querier | ❌ | ✅ | ❌ | ✅ |
| query-frontend | ✅ | ✅ | ✅* | ✅ |
| ruler | ✅ | ✅ | ❌ | ✅ |
| compactor | ❌ | ✅ | ❌ | ✅ |
| index-gateway | ❌ | ✅ | ❌ | ✅ |
| gateway | ❌ | ❌ | ✅ | ✅ |
*Only in OpenShift network mode
| Component | To Components | To Object Storage | To DNS | To AlertManager | To API Server |
|---|---|---|---|---|---|
| distributor | ✅ | ❌ | ✅ | ❌ | ❌ |
| ingester | ✅ | ✅ | ✅ | ❌ | ❌ |
| querier | ✅ | ✅ | ✅ | ❌ | ❌ |
| query-frontend | ✅ | ❌ | ✅ | ❌ | ❌ |
| ruler | ✅ | ✅ | ✅ | ✅ | ❌ |
| compactor | ✅ | ✅ | ✅ | ❌ | ❌ |
| index-gateway | ✅ | ✅ | ✅ | ❌ | ❌ |
| gateway | ✅ | ❌ | ✅ | ❌ | ✅ |
For additional integrations (custom dashboards, external alerting), you may need to create supplementary NetworkPolicies. You can select specific components by using the label app.kubernetes.io/component you should always also include the labels app.kubernetes.io/name=lokistack and app.kubernetes.io/instance={name} to avoid collision with other pods deployed in the namespace.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: custom-dashboard-access
spec:
podSelector:
matchLabels:
app.kubernetes.io/name: lokistack
app.kubernetes.io/instance: lokistack-dev
app.kubernetes.io/component: ruler
policyTypes:
- Egress
egress:
- to:
- namespaceSelector:
matchLabels:
name: monitoring
- podSelector:
matchLabels:
app: custom-alertmanager
ports:
- protocol: TCP
port: 3100
Network policies provide essential security controls for LokiStack deployments by implementing network segmentation and access controls. While they add a layer of complexity, the security benefits make them highly recommended for production environments.
The Loki Operator's network policies are designed to be secure by default while maintaining compatibility across diverse environments.