Skip to content

Commit 60c1f15

Browse files
committed
[vm] Remove egress restrictions on non-isolated vm
## What this PR does Virtual machines with a public IP have a network policy that explicitly allows them to communicate with the external internet. When created in a non-isolated tenant that has no network policies by default, creating such a policy, instead, **restricts** egress traffic originating from the VM from going anywhere, __except__ the outside internet. Instead of allowing VMs to communicate with the outside internet via a network policy, this patch now adds a label to the VMs by which they will be targetted by Cozystack's default network policies, if such policies exist. When no policies are present, the VM's egress traffic will no longer be policed. Resolves #1601. ### Release note ```release-note [virtual-machine,vm-instance] Remove the egress network policy from virtual machines and govern egress traffic by default network policies instead, resolving the bug in #1601. ``` Signed-off-by: Timofei Larkin <[email protected]>
1 parent 5b96190 commit 60c1f15

5 files changed

Lines changed: 17 additions & 8 deletions

File tree

‎packages/apps/tenant/templates/networkpolicy.yaml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ spec:
3434
- world
3535
---
3636
apiVersion: cilium.io/v2
37+
kind: CiliumNetworkPolicy
38+
metadata:
39+
name: allow-world-egress
40+
namespace: {{ include "tenant.name" . }}
41+
spec:
42+
endpointSelector:
43+
matchExpressions:
44+
- key: policy.cozystack.io/allow-world-egress
45+
operator: NotIn
46+
values: ["false"]
47+
egress:
48+
- toEntities:
49+
- world
50+
---
51+
apiVersion: cilium.io/v2
3752
kind: CiliumClusterwideNetworkPolicy
3853
metadata:
3954
name: {{ include "tenant.name" . }}-egress

‎packages/apps/virtual-machine/templates/service.yaml‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,3 @@ spec:
4949
- port: {{ quote . }}
5050
{{- end }}
5151
{{- end }}
52-
egress:
53-
- toEntities:
54-
- world

‎packages/apps/virtual-machine/templates/vm.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ spec:
6262
template:
6363
metadata:
6464
annotations:
65-
policy.cozystack.io/allow-external-communication: "false"
6665
kubevirt.io/allow-pod-bridge-network-live-migration: "true"
6766
labels:
67+
policy.cozystack.io/allow-world-egress: "true"
6868
{{- include "virtual-machine.labels" . | nindent 8 }}
6969
spec:
7070
domain:

‎packages/apps/vm-instance/templates/service.yaml‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,3 @@ spec:
4949
- port: {{ quote . }}
5050
{{- end }}
5151
{{- end }}
52-
egress:
53-
- toEntities:
54-
- world

‎packages/apps/vm-instance/templates/vm.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ spec:
2626
template:
2727
metadata:
2828
annotations:
29-
policy.cozystack.io/allow-external-communication: "false"
3029
kubevirt.io/allow-pod-bridge-network-live-migration: "true"
3130
labels:
31+
policy.cozystack.io/allow-world-egress: "true"
3232
{{- include "virtual-machine.labels" . | nindent 8 }}
3333
spec:
3434
domain:

0 commit comments

Comments
 (0)