Skip to content

Commit

Permalink
Merge pull request #1056 from DSD-DBS/feat-add-network-policies
Browse files Browse the repository at this point in the history
feat: Add network policies
  • Loading branch information
MoritzWeber0 authored Sep 29, 2023
2 parents 7995430 + bbc0c4e commit 34bcaaa
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 3 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ helm-deploy:
--set general.port=8080 \
--set development=$(DEVELOPMENT_MODE) \
--set cluster.ingressClassName=traefik \
--set cluster.ingressNamespace=kube-system \
--set backend.k8sSessionNamespace="$(SESSION_NAMESPACE)" \
--set backend.authentication.oauth.redirectURI="http://localhost:$(PORT)/oauth2/callback" \
--set backend.authentication.oauth.endpoints.wellKnown="http://$(RELEASE)-oauth-mock:8080/default/.well-known/openid-configuration" \
Expand Down
2 changes: 0 additions & 2 deletions helm/templates/promtail/promtail.networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# SPDX-License-Identifier: Apache-2.0

{{ if .Values.loki.enabled }}
{{ if eq .Values.cluster.kind "OpenShift" }}
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
Expand All @@ -21,4 +20,3 @@ spec:
policyTypes:
- Ingress
{{ end }}
{{ end }}
42 changes: 42 additions & 0 deletions helm/templates/routing/manager.networkpolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# SPDX-FileCopyrightText: Copyright DB Netz AG and the capella-collab-manager contributors
# SPDX-License-Identifier: Apache-2.0

{{- if .Values.cluster.ingressNamespace }}
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: default-deny
namespace: {{ .Release.Namespace }}
spec:
podSelector: {}
policyTypes:
- Ingress
---
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: allow-from-same-namespace
namespace: {{ .Release.Namespace }}
spec:
podSelector: {}
ingress:
- from:
- podSelector: {}
policyTypes:
- Ingress
---
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: allow-from-ingress-namespace
namespace: {{ .Release.Namespace }}
spec:
podSelector: {}
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: {{ .Values.cluster.ingressNamespace }}
policyTypes:
- Ingress
{{ end }}
27 changes: 26 additions & 1 deletion helm/templates/sessions/sessions.networkpolicy.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-FileCopyrightText: Copyright DB Netz AG and the capella-collab-manager contributors
# SPDX-License-Identifier: Apache-2.0

{{- if eq .Values.cluster.kind "OpenShift" }}
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
Expand All @@ -16,4 +15,30 @@ spec:
kubernetes.io/metadata.name: {{ .Release.Namespace }}
policyTypes:
- Ingress
{{- if .Values.cluster.ingressNamespace }}
---
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: default-deny
namespace: {{ .Values.backend.k8sSessionNamespace }}
spec:
podSelector: {}
policyTypes:
- Ingress
---
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: allow-from-ingress-namespace
namespace: {{ .Values.backend.k8sSessionNamespace }}
spec:
podSelector: {}
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: {{ .Values.cluster.ingressNamespace }}
policyTypes:
- Ingress
{{ end }}
2 changes: 2 additions & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ mocks:
cluster:
kind: Kubernetes # Kubernetes | OpenShift

ingressNamespace:

podSecurityContext: &podSecurityContext
runAsUser: 1004370000
runAsGroup: 1004370000
Expand Down

0 comments on commit 34bcaaa

Please sign in to comment.