Skip to content

Commit

Permalink
feat(monitoring): add network policies for ingress
Browse files Browse the repository at this point in the history
  • Loading branch information
Simone Bruzzese committed Nov 7, 2024
1 parent 405039d commit 346206c
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ spec:
ports:
- protocol: UDP
port: 53
- protocol: TCP
port: 53

145 changes: 145 additions & 0 deletions templates/distribution/manifests/monitoring/policies/ingress.yaml.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Copyright (c) 2017-present SIGHUP s.r.l All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: grafana-ingress-nginxingresscontroller
namespace: monitoring
spec:
podSelector:
matchLabels:
app.kubernetes.io/component: grafana
app.kubernetes.io/name: grafana
app.kubernetes.io/part-of: kube-prometheus
policyTypes:
- Ingress
ingress:
# single nginx, no sso
{{if and (eq .spec.distribution.modules.ingress.nginx.type "single") (ne .spec.distribution.modules.auth.provider.type "sso") }}
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ingress-nginx
podSelector:
matchLabels:
app: ingress-nginx
# dual nginx, no sso
{{ else if (eq .spec.distribution.modules.ingress.nginx.type "dual") (ne .spec.distribution.modules.auth.provider.type "sso") }}
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ingress-nginx
podSelector:
matchLabels:
app: ingress
# sso
{{ else if (eq .spec.distribution.modules.auth.provider.type "sso") }}
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ingress-nginx
podSelector:
matchLabels:
app: pomerium
{{ end }}
ports:
- port: 3000
protocol: TCP
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: prometheus-ingress-nginxingresscontroller
namespace: monitoring
spec:
podSelector:
matchLabels:
app.kubernetes.io/component: alert-router
app.kubernetes.io/instance: main
app.kubernetes.io/name: alertmanager
app.kubernetes.io/part-of: kube-prometheus
policyTypes:
- Ingress
ingress:
# single nginx, no sso
{{if and (eq .spec.distribution.modules.ingress.nginx.type "single") (ne .spec.distribution.modules.auth.provider.type "sso") }}
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ingress-nginx
podSelector:
matchLabels:
app: ingress-nginx
# dual nginx, no sso
{{ else if (eq .spec.distribution.modules.ingress.nginx.type "dual") (ne .spec.distribution.modules.auth.provider.type "sso") }}
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ingress-nginx
podSelector:
matchLabels:
app: ingress
# sso
{{ else if (eq .spec.distribution.modules.auth.provider.type "sso") }}
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ingress-nginx
podSelector:
matchLabels:
app: pomerium
{{ end }}
ports:
- port: 9090
protocol: TCP
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: alertmanager-ingress-nginxingresscontroller
namespace: monitoring
spec:
podSelector:
matchLabels:
app.kubernetes.io/component: prometheus
app.kubernetes.io/instance: k8s
app.kubernetes.io/name: prometheus
app.kubernetes.io/part-of: kube-prometheus
policyTypes:
- Ingress
ingress:
# single nginx, no sso
{{if and (eq .spec.distribution.modules.ingress.nginx.type "single") (ne .spec.distribution.modules.auth.provider.type "sso") }}
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ingress-nginx
podSelector:
matchLabels:
app: ingress-nginx
# dual nginx, no sso
{{ else if (eq .spec.distribution.modules.ingress.nginx.type "dual") (ne .spec.distribution.modules.auth.provider.type "sso") }}
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ingress-nginx
podSelector:
matchLabels:
app: ingress
# sso
{{ else if (eq .spec.distribution.modules.auth.provider.type "sso") }}
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ingress-nginx
podSelector:
matchLabels:
app: pomerium
{{ end }}
ports:
- port: 9093
protocol: TCP
---
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ resources:
- minio.yaml
{{- end }}
{{- end }}

{{- if and (ne .spec.distribution.modules.ingress.nginx.type "none") }}{{/* we don't need ingresses for Prometheus in Agent mode */}}
- ingress.yaml
{{- end }}

0 comments on commit 346206c

Please sign in to comment.