Skip to content
Snippets Groups Projects
Commit e3ecebaf authored by OZGCloud's avatar OZGCloud
Browse files

OZG-3880 - add network policy

parent a12e9d70
Branches
Tags
No related merge requests found
#!/bin/sh
set -e
helm template ./src/main/helm/ -f src/main/helm/test-values.yaml
helm lint -f src/test/helm/values/unit-values.yaml ./src/main/helm/
cd src/main/helm && helm unittest --helm3 -f '../../test/helm/*.yaml' -v '../../test/helm/values/unit-values.yaml' .
\ No newline at end of file
#
# Copyright (C) 2022 Das Land Schleswig-Holstein vertreten durch den
# Ministerpräsidenten des Landes Schleswig-Holstein
# Staatskanzlei
# Abteilung Digitalisierung und zentrales IT-Management der Landesregierung
#
# Lizenziert unter der EUPL, Version 1.2 oder - sobald
# diese von der Europäischen Kommission genehmigt wurden -
# Folgeversionen der EUPL ("Lizenz");
# Sie dürfen dieses Werk ausschließlich gemäß
# dieser Lizenz nutzen.
# Eine Kopie der Lizenz finden Sie hier:
#
# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
#
# Sofern nicht durch anwendbare Rechtsvorschriften
# gefordert oder in schriftlicher Form vereinbart, wird
# die unter der Lizenz verbreitete Software "so wie sie
# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN -
# ausdrücklich oder stillschweigend - verbreitet.
# Die sprachspezifischen Genehmigungen und Beschränkungen
# unter der Lizenz sind dem Lizenztext zu entnehmen.
#
{{- if not (.Values.network_policy).disabled }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: network-policy-xta-adapter
namespace: {{ .Release.Namespace }}
spec:
podSelector:
matchLabels:
ozg-component: xta-adapter
policyTypes:
- Egress
egress:
- to:
- podSelector:
matchLabels:
component: pluto
ports:
- port: 9090
protocol: TCP
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
podSelector:
matchLabels:
k8s-app: kube-dns
ports:
- port: 53
protocol: UDP
- port: 53
protocol: TCP
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ssh-port-forward
ports:
- port: 9000
protocol: TCP
{{- with (.Values.network_policy).additional_egress_config }}
- to:
{{ toYaml . | indent 8 }}
{{- end }}
{{- end }}
\ No newline at end of file
...@@ -42,6 +42,7 @@ spec: ...@@ -42,6 +42,7 @@ spec:
metadata: metadata:
labels: labels:
workload: xta-adapter-cronjob workload: xta-adapter-cronjob
ozg-component: xta-adapter
spec: spec:
restartPolicy: Never restartPolicy: Never
containers: containers:
......
#
# Copyright (C) 2022 Das Land Schleswig-Holstein vertreten durch den
# Ministerpräsidenten des Landes Schleswig-Holstein
# Staatskanzlei
# Abteilung Digitalisierung und zentrales IT-Management der Landesregierung
#
# Lizenziert unter der EUPL, Version 1.2 oder - sobald
# diese von der Europäischen Kommission genehmigt wurden -
# Folgeversionen der EUPL ("Lizenz");
# Sie dürfen dieses Werk ausschließlich gemäß
# dieser Lizenz nutzen.
# Eine Kopie der Lizenz finden Sie hier:
#
# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
#
# Sofern nicht durch anwendbare Rechtsvorschriften
# gefordert oder in schriftlicher Form vereinbart, wird
# die unter der Lizenz verbreitete Software "so wie sie
# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN -
# ausdrücklich oder stillschweigend - verbreitet.
# Die sprachspezifischen Genehmigungen und Beschränkungen
# unter der Lizenz sind dem Lizenztext zu entnehmen.
#
suite: network policy test
release:
namespace: by-helm-test
templates:
- templates/network_policy.yaml
tests:
- it: should match apiVersion
asserts:
- isAPIVersion:
of: networking.k8s.io/v1
- it: should match kind
asserts:
- isKind:
of: NetworkPolicy
- it: validate metadata
asserts:
- equal:
path: metadata
value:
name: network-policy-xta-adapter
namespace: by-helm-test
- it: validate spec
asserts:
- equal:
path: spec
value:
podSelector:
matchLabels:
ozg-component: xta-adapter
policyTypes:
- Egress
egress:
- to:
- podSelector:
matchLabels:
component: pluto
ports:
- port: 9090
protocol: TCP
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
podSelector:
matchLabels:
k8s-app: kube-dns
ports:
- port: 53
protocol: UDP
- port: 53
protocol: TCP
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ssh-port-forward
ports:
- port: 9000
protocol: TCP
- it: add ingress rule by values
set:
network_policy:
additional_egress_config:
- podSelector:
matchLabels:
component: client2
asserts:
- equal:
path: spec.egress
value:
- to:
- podSelector:
matchLabels:
component: pluto
ports:
- port: 9090
protocol: TCP
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
podSelector:
matchLabels:
k8s-app: kube-dns
ports:
- port: 53
protocol: UDP
- port: 53
protocol: TCP
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ssh-port-forward
ports:
- port: 9000
protocol: TCP
- to:
- podSelector:
matchLabels:
component: client2
- it: test network policy disabled
set:
network_policy:
disabled: true
asserts:
- hasDocuments:
count: 0
- it: test network policy unset should be disabled
set:
network_policy:
disabled: false
asserts:
- hasDocuments:
count: 1
\ No newline at end of file
...@@ -100,3 +100,12 @@ tests: ...@@ -100,3 +100,12 @@ tests:
- equal: - equal:
path: spec.jobTemplate.spec.template.spec.containers[0].securityContext.runAsNonRoot path: spec.jobTemplate.spec.template.spec.containers[0].securityContext.runAsNonRoot
value: false value: false
- it: check pod labels
template: xta_adapter_cronjob.yaml
asserts:
- equal:
path: spec.jobTemplate.spec.template.metadata.labels
value:
ozg-component: xta-adapter
workload: xta-adapter-cronjob
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment