Repository navigation
[vm] Remove egress restrictions on non-isolated vm - #1602
Timofei Larkin (lllamnyp) wants to merge 1 commit into
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughRemoved per-VM egress-to-world rules from service CiliumNetworkPolicy, moved/added policy labels on VM resources, and introduced tenant-scoped and clusterwide Cilium policies that conditionally allow world egress for labeled VMs and route tenant egress targets. Changes
Sequence Diagram(s)sequenceDiagram
participant User as User/Controller
participant K8s as Kubernetes API
participant Cilium as Cilium (CNP/CCNP)
participant VM as VirtualMachine Pod
participant Cluster as Cluster DNS/Services
rect `#f0f8ff`
note left of K8s: Apply VM manifests & tenant policies
end
User->>K8s: create VM (labels: allow-world-egress=true)
K8s->>Cilium: reconcile CNP/CCNP (tenant + clusterwide egress rules)
K8s->>VM: create VM Pod with labels
VM->>Cluster: DNS / in-cluster request
alt VM selected by tenant/cluster policies
Cilium-->>Cluster: allow intra-cluster endpoints per clusterwide/tenant rules
Cluster-->>VM: response (allowed)
else No matching allow rules
Cilium-->>VM: egress to world only (if namespace-scoped allow-world applies)
Cluster-->>VM: blocked (if not permitted)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (5)
💤 Files with no reviewable changes (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello Timofei Larkin (@lllamnyp), I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the egress traffic management for virtual machines, particularly those with public IPs in non-isolated tenants. It moves away from a potentially restrictive explicit network policy to a more flexible label-based approach. This ensures that VMs can communicate as intended, either governed by Cozystack's default network policies or, in their absence, without unintended egress restrictions. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on Gemini (@gemini-code-assist) comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly identifies the cause of unintended egress traffic restrictions on virtual machines and proposes a sound solution: removing the specific egress network policy and using a label for targeting by default policies. While the removal of the egress policy is implemented correctly, the new label policy.cozystack.io/allow-external-communication: "true" is applied to the VirtualMachine resource itself, instead of its pod template (spec.template). As network policies target pods, the pod running the VM will not receive this label, and the fix will not be effective. I have left critical comments on both vm.yaml files explaining how to correctly apply the label to the pod template to make the solution work as intended.
| metadata: | ||
| name: {{ include "virtual-machine.fullname" . }} | ||
| labels: | ||
| policy.cozystack.io/allow-external-communication: "true" |
There was a problem hiding this comment.
This label is intended for network policies to target the VM's pod, but it's placed on the VirtualMachine resource's metadata. Labels from the VirtualMachine are not propagated to the pod created by KubeVirt. For the network policy to apply, this label must be on the pod, which means it should be in spec.template.metadata.labels.
Additionally, there's a conflicting annotation policy.cozystack.io/allow-external-communication: "false" on line 66 within spec.template.metadata.annotations that should be removed.
To fix this, please move the label and remove the old annotation. The spec.template.metadata section should be updated as follows:
metadata:
annotations:
kubevirt.io/allow-pod-bridge-network-live-migration: "true"
labels:
policy.cozystack.io/allow-external-communication: "true"
{{- include "virtual-machine.labels" . | nindent 8 }}| metadata: | ||
| name: {{ include "virtual-machine.fullname" . }} | ||
| labels: | ||
| policy.cozystack.io/allow-external-communication: "true" |
There was a problem hiding this comment.
This label is intended for network policies to target the VM's pod, but it's placed on the VirtualMachine resource's metadata. Labels from the VirtualMachine are not propagated to the pod created by KubeVirt. For the network policy to apply, this label must be on the pod, which means it should be in spec.template.metadata.labels.
Additionally, there's a conflicting annotation policy.cozystack.io/allow-external-communication: "false" on line 30 within spec.template.metadata.annotations that should be removed.
To fix this, please move the label and remove the old annotation. The spec.template.metadata section should be updated as follows:
metadata:
annotations:
kubevirt.io/allow-pod-bridge-network-live-migration: "true"
labels:
policy.cozystack.io/allow-external-communication: "true"
{{- include "virtual-machine.labels" . | nindent 8 }}e6df544 to
590337a
Compare
60c1f15 to
6622496
Compare
## 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]>
6622496 to
e997495
Compare
Pull request was closed
Signed-off-by: Andrei Kvapil <[email protected]> <!-- Thank you for making a contribution! Here are some tips for you: - Start the PR title with the [label] of Cozystack component: - For system components: [platform], [system], [linstor], [cilium], [kube-ovn], [dashboard], [cluster-api], etc. - For managed apps: [apps], [tenant], [kubernetes], [postgres], [virtual-machine] etc. - For development and maintenance: [tests], [ci], [docs], [maintenance]. - If it's a work in progress, consider creating this PR as a draft. - Don't hesistate to ask for opinion and review in the community chats, even if it's still a draft. - Add the label `backport` if it's a bugfix that needs to be backported to a previous version. --> ## What this PR does Revert per-vm network policies functionality introduced by #1611 As it is not working as expected any way. This is temporary solution before implementing full-fledged security groups in Cozystack fixes #1601 alternative solution: #1602 ### Release note <!-- Write a release note: - Explain what has changed internally and for users. - Start with the same [label] as in the PR title - Follow the guidelines at https://github.com/kubernetes/community/blob/master/contributors/guide/release-notes.md. --> ```release-note [virtual-machine] Revert per-vm network policies ```
Signed-off-by: Andrei Kvapil <[email protected]> <!-- Thank you for making a contribution! Here are some tips for you: - Start the PR title with the [label] of Cozystack component: - For system components: [platform], [system], [linstor], [cilium], [kube-ovn], [dashboard], [cluster-api], etc. - For managed apps: [apps], [tenant], [kubernetes], [postgres], [virtual-machine] etc. - For development and maintenance: [tests], [ci], [docs], [maintenance]. - If it's a work in progress, consider creating this PR as a draft. - Don't hesistate to ask for opinion and review in the community chats, even if it's still a draft. - Add the label `backport` if it's a bugfix that needs to be backported to a previous version. --> ## What this PR does Revert per-vm network policies functionality introduced by #1611 As it is not working as expected any way. This is temporary solution before implementing full-fledged security groups in Cozystack fixes #1601 alternative solution: #1602 ### Release note <!-- Write a release note: - Explain what has changed internally and for users. - Start with the same [label] as in the PR title - Follow the guidelines at https://github.com/kubernetes/community/blob/master/contributors/guide/release-notes.md. --> ```release-note [virtual-machine] Revert per-vm network policies ```
Signed-off-by: Andrei Kvapil <[email protected]> <!-- Thank you for making a contribution! Here are some tips for you: - Start the PR title with the [label] of Cozystack component: - For system components: [platform], [system], [linstor], [cilium], [kube-ovn], [dashboard], [cluster-api], etc. - For managed apps: [apps], [tenant], [kubernetes], [postgres], [virtual-machine] etc. - For development and maintenance: [tests], [ci], [docs], [maintenance]. - If it's a work in progress, consider creating this PR as a draft. - Don't hesistate to ask for opinion and review in the community chats, even if it's still a draft. - Add the label `backport` if it's a bugfix that needs to be backported to a previous version. --> ## What this PR does Revert per-vm network policies functionality introduced by #1611 As it is not working as expected any way. This is temporary solution before implementing full-fledged security groups in Cozystack fixes #1601 alternative solution: #1602 ### Release note <!-- Write a release note: - Explain what has changed internally and for users. - Start with the same [label] as in the PR title - Follow the guidelines at https://github.com/kubernetes/community/blob/master/contributors/guide/release-notes.md. --> ```release-note [virtual-machine] Revert per-vm network policies ```
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
Summary by CodeRabbit
Chores
New Features