Skip to content

Commit b8fdc8b

Browse files
authored
Kubernetes: global deny network policy for simcore (ITISFoundation#1169)
Apply global deny network policy for all applications running in `simcore` namespace Add explicit network policy for simcore rut to allow traffic. Add network policy checksum annotation to rut deployment to restart rut pods on policy changes and thus be sure new network rules are used Pin point extra dns request sent to nodelocaldns service and allow this traffic in global policy (update adminer network policy correspondingly) Related issue/s * closes ITISFoundation#1168
1 parent af61d4a commit b8fdc8b

File tree

6 files changed

+71
-13
lines changed

6 files changed

+71
-13
lines changed

charts/adminer/templates/networkpolicy.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,3 @@ spec:
1818
destination:
1919
ports:
2020
- 5432
21-
# allow dns requests to public dns servers
22-
- action: Allow
23-
protocol: UDP
24-
destination:
25-
ports:
26-
- 53

charts/calico-configuration/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if calico version 3.30+ is installed
1414
- https://docs.tigera.io/calico/3.30/observability/view-flow-logs
1515

1616
if calico version <= 3.29
17-
* create network policy with action log
17+
* create network policy with action log (read more https://docs.tigera.io/calico/latest/network-policy/policy-rules/log-rules)
1818
```yaml
1919
apiVersion: projectcalico.org/v3
2020
kind: NetworkPolicy
@@ -25,7 +25,8 @@ if calico version <= 3.29
2525
ingress:
2626
- action: Log
2727
```
28-
* apply policy and see logs via journalctl (you can grep with `calico-packet`)
28+
* apply policy and see logs via journalctl (you can grep with `calico-packet` on the node where the pod is running)
29+
* Note: one may implement policy step by step (allowing all traffic that is known and making last rule `Log` to see what traffic is still missing)
2930

3031
## Known issues
3132

@@ -43,7 +44,7 @@ via calicoctl:
4344

4445
Note:
4546
* global network policies and network policies are separate resources for calico
46-
* To see all resources execute `kubectl get crd | grep calico` or `calicoctl get --help`
47+
* To see all calico resources execute `kubectl get crd | grep calico` or `calicoctl get --help`
4748

4849
Warning:
4950
* Network policies update are only applied to "new connections". To make them act, one may need to restart affected applications (pods)

charts/calico-configuration/templates/globalpolicy.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ spec:
88
# "calico-system", "calico-apiserver", "tigera-operator" -- calico namespaces (when installed via scripts [local deployment])
99
# TODO: other namespaces are to be removed from this list (once appropriate network policies are created)
1010
namespaceSelector:
11-
kubernetes.io/metadata.name not in {"kube-public", "kube-system", "kube-node-lease", "calico-system", "calico-apiserver", "tigera-operator", "simcore", "cert-manager", "reflector", "traefik", "victoria-logs", "csi-s3", "portainer", "topolvm", "local-path-storage", "longhorn"}
11+
kubernetes.io/metadata.name not in {"kube-public", "kube-system", "kube-node-lease", "calico-system", "calico-apiserver", "tigera-operator", "cert-manager", "reflector", "traefik", "victoria-logs", "csi-s3", "portainer", "topolvm", "local-path-storage", "longhorn"}
1212
types:
1313
- Ingress
1414
- Egress
@@ -22,9 +22,23 @@ spec:
2222
selector: 'k8s-app == "kube-dns"'
2323
ports:
2424
- 53
25+
# nodelocaldns: https://github.com/kubernetes/kubernetes/blob/master/cluster/addons/dns/nodelocaldns/README.md#nodelocal-dns-cache
26+
# IP from https://github.com/kubernetes-sigs/kubespray/blob/v2.24.1/roles/kubespray-defaults/defaults/main/main.yml#L108
27+
- action: Allow
28+
protocol: UDP
29+
nets:
30+
- 169.254.25.10/32
31+
ports:
32+
- 53
2533
- action: Allow
2634
protocol: TCP
2735
destination:
2836
selector: 'k8s-app == "kube-dns"'
2937
ports:
3038
- 53
39+
- action: Allow
40+
protocol: TCP
41+
nets:
42+
- 169.254.25.10/32
43+
ports:
44+
- 53

charts/simcore-charts/resource-usage-tracker/templates/deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ spec:
1313
{{- include "resource-usage-tracker.selectorLabels" . | nindent 6 }}
1414
template:
1515
metadata:
16-
{{- with .Values.podAnnotations }}
16+
{{- if .Values.podAnnotations }}
1717
annotations:
18-
{{- toYaml . | nindent 8 }}
18+
{{- tpl (toYaml .Values.podAnnotations) . | nindent 8 }}
1919
{{- end }}
2020
labels:
2121
{{- include "resource-usage-tracker.labels" . | nindent 8 }}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
apiVersion: projectcalico.org/v3
2+
kind: NetworkPolicy
3+
metadata:
4+
name: resource-usage-tracker-network-policy
5+
labels:
6+
{{- include "resource-usage-tracker.labels" . | nindent 4 }}
7+
spec:
8+
selector: app.kubernetes.io/instance == "{{ .Release.Name }}"
9+
ingress:
10+
- action: Allow
11+
protocol: TCP
12+
destination:
13+
ports:
14+
- {{ .Values.service.port }}
15+
egress:
16+
- action: Allow
17+
protocol: TCP
18+
destination:
19+
nets:
20+
- 10.0.0.0/8
21+
- 192.168.0.0/16
22+
- 172.16.0.0/12
23+
ports:
24+
- {{ .Values.networkPolicyEgressPorts.postgres }}
25+
- action: Allow
26+
protocol: TCP
27+
destination:
28+
nets:
29+
- 10.0.0.0/8
30+
- 192.168.0.0/16
31+
- 172.16.0.0/12
32+
ports:
33+
- {{ .Values.networkPolicyEgressPorts.redis }}
34+
- action: Allow
35+
protocol: TCP
36+
destination:
37+
nets:
38+
- 10.0.0.0/8
39+
- 192.168.0.0/16
40+
- 172.16.0.0/12
41+
ports:
42+
- {{ .Values.networkPolicyEgressPorts.rabbit }}

charts/simcore-charts/resource-usage-tracker/values.yaml.gotmpl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ serviceAccount:
2525
# If not set and create is true, a name is generated using the fullname template
2626
name: ""
2727

28-
podAnnotations: {}
28+
podAnnotations:
29+
checksum/networkpolicy: '{{`{{ include (print $.Template.BasePath "/networkpolicy.yaml") . | sha256sum }}`}}'
30+
2931
podLabels: {}
3032

3133
podSecurityContext:
@@ -150,3 +152,8 @@ env:
150152
- name: RESOURCE_USAGE_TRACKER_S3
151153
value: {{ requiredEnv "RESOURCE_USAGE_TRACKER_S3" | quote }} # without quote `null` won't work
152154
sensitive: true
155+
156+
networkPolicyEgressPorts:
157+
rabbit: {{ requiredEnv "RABBIT_EXTERNAL_PORT" }}
158+
redis: {{ requiredEnv "REDIS_EXTERNAL_PORT" }}
159+
postgres: {{ requiredEnv "POSTGRES_EXTERNAL_PORT" }}

0 commit comments

Comments
 (0)