Skip to content

Commit 79b333a

Browse files
committed
Global deny network policy
1 parent eadd4a7 commit 79b333a

File tree

4 files changed

+47
-24
lines changed

4 files changed

+47
-24
lines changed
Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
## Observe network traffic
1+
## How to add network policy (local deployment)
22

3-
https://docs.tigera.io/calico/latest/observability/enable-whisker
4-
https://docs.tigera.io/calico/3.30/observability/view-flow-logs
3+
How to discover ports / networks that are used by application
4+
* enable and observer traffic via
5+
- https://docs.tigera.io/calico/3.30/observability/enable-whisker
6+
- https://docs.tigera.io/calico/3.30/observability/view-flow-logs
7+
* add staged policies to make sure all cases are included https://docs.tigera.io/calico/3.30/network-policy/staged-network-policies
8+
9+
Debug network policies:
10+
* observe traffic and check `policies` field in whisker logs
11+
- https://docs.tigera.io/calico/3.30/observability/enable-whisker
12+
- https://docs.tigera.io/calico/3.30/observability/view-flow-logs
13+
14+
Warning: make sure that calico version being used support Whisker (e.g. in v3.26 whisker is not documented at all)
15+
16+
17+
## Known issues
18+
19+
If network policy is created after pod, pod **MUST** be restarted for policy to take effect. Read more https://github.com/projectcalico/calico/issues/10753#issuecomment-3140717418
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
This chart configures Calico but does not deploy Calico itself. This is done via Kubespray during Kubernetes Cluster provisioning.
2+
3+
Note: to make sure network policies are applied correctly, you may need to restart targeted application pods.
Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
# Source: https://docs.tigera.io/calico-enterprise/latest/network-policy/default-deny#best-practice-2-keep-the-scope-to-non-system-pods
1+
# Source: https://docs.tigera.io/calico/3.30/network-policy/get-started/kubernetes-default-deny
22
apiVersion: projectcalico.org/v3
33
kind: GlobalNetworkPolicy
44
metadata:
55
name: default-global-deny-network-policy
66
spec:
7-
# on local deployment, calico is installed in the `calico-system` namespace
8-
# and the operator is in the `tigera-operator` namespace
9-
namespaceSelector: kubernetes.io/metadata.name in {"adminer"}
7+
# "kube-public", "kube-system", "kube-node-lease" -- system namespaces
8+
# "calico-system", "calico-apiserver", "tigera-operator" -- calico namespaces (when installed via scripts [local deployment])
9+
# TODO: other namespaces are to be removed from this list (once appropriate network policies are created)
10+
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"}
1012
types:
11-
- Ingress
12-
- Egress
13+
- Ingress
14+
- Egress
1315
egress:
14-
# allow all namespaces to communicate to DNS pods
15-
- action: Allow
16-
protocol: UDP
17-
destination:
18-
selector: 'k8s-app == "kube-dns"'
19-
ports:
20-
- 53
21-
- action: Allow
22-
protocol: TCP
23-
destination:
24-
selector: 'k8s-app == "kube-dns"'
25-
ports:
26-
- 53
16+
# allow all namespaces to communicate to DNS pods
17+
# this will also apply to pods that have network policy defined
18+
# so that we don't need to define DNS policy for each pod
19+
- action: Allow
20+
protocol: UDP
21+
destination:
22+
selector: 'k8s-app == "kube-dns"'
23+
ports:
24+
- 53
25+
- action: Allow
26+
protocol: TCP
27+
destination:
28+
selector: 'k8s-app == "kube-dns"'
29+
ports:
30+
- 53

charts/portainer/templates/networkpolicy.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ spec:
2222
- action: Allow
2323
protocol: UDP
2424
destination:
25-
selector: 'k8s-app == "kube-dns"'
25+
# `selector: 'k8s-app == "kube-dns"'` does not work (so global policy default dns allow does not work)
26+
# manually allow dns and use different selector that works.
27+
selectorNamespace: kubernetes.io/metadata.name == "kube-system"
2628
ports:
2729
- 53
2830
ingress:
@@ -31,4 +33,4 @@ spec:
3133
protocol: TCP
3234
destination:
3335
ports:
34-
- 9000
36+
- {{ .Values.servicePort }}

0 commit comments

Comments
 (0)