Skip to content

kvm: fix security group conntrack NOTRACK optimization triggered by single-direction allow-all rule - #14100

Draft
weizhouapache wants to merge 1 commit into
apache:mainfrom
weizhouapache:24-fix-sg-allow-all-egress
Draft

kvm: fix security group conntrack NOTRACK optimization triggered by single-direction allow-all rule#14100
weizhouapache wants to merge 1 commit into
apache:mainfrom
weizhouapache:24-fix-sg-allow-all-egress

Conversation

@weizhouapache

Copy link
Copy Markdown
Member

Description

This PR fixes #14099

The raw-table NOTRACK rules for a VM IP in the cs_notrack/cs_notrack6 ipsets apply to that IP as both source and destination, disabling connection tracking for it in both directions at once. The check that populates these ipsets did not look at rule['ruletype'], so an allow-all rule in only one direction (e.g. egress all to 0.0.0.0/0) was enough to disable conntrack for the VM, breaking return traffic when the other direction (e.g. ingress) is restricted.

Only skip conntrack for a family now when both an ingress allow-all and an egress allow-all rule exist for that family, matching the actual bidirectional effect of the NOTRACK rules.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

…ingle-direction allow-all rule

The raw-table NOTRACK rules for a VM IP in the cs_notrack/cs_notrack6
ipsets apply to that IP as both source and destination, disabling
connection tracking for it in both directions at once. The check that
populates these ipsets did not look at rule['ruletype'], so an
allow-all rule in only one direction (e.g. egress all to 0.0.0.0/0)
was enough to disable conntrack for the VM, breaking return traffic
when the other direction (e.g. ingress) is restricted.

Only skip conntrack for a family now when both an ingress allow-all
and an egress allow-all rule exist for that family, matching the
actual bidirectional effect of the NOTRACK rules.
@boring-cyborg boring-cyborg Bot added component:networking Python Warning... Python code Ahead! labels Sep 9, 2026
@weizhouapache weizhouapache added this to the 24.0 milestone Sep 9, 2026
@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 19.80%. Comparing base (c77e16a) to head (698614a).

Additional details and impacted files
@@            Coverage Diff            @@
##               main   #14100   +/-   ##
=========================================
  Coverage     19.79%   19.80%           
- Complexity    20020    20022    +2     
=========================================
  Files          6371     6371           
  Lines        575954   575954           
  Branches      70521    70521           
=========================================
+ Hits         114034   114043    +9     
+ Misses       449486   449472   -14     
- Partials      12434    12439    +5     
Flag Coverage Δ
uitests 3.52% <ø> (ø)
unittests 21.07% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@weizhouapache

Copy link
Copy Markdown
Member Author

verified the following cases

Ingress Egress Actual egress traffic ipset list cs_notrack - before fix ipset list cs_notrack - after fix
no rule (deny) no rule allowed (default ACCEPT) not in set not in set
no rule (deny) allow a (restricted) allowed only for that rule not in set not in set
no rule (deny) allow all (explicit) allowed in set (bug) not in set
allow a (restricted) no rule allowed (default ACCEPT) not in set not in set
allow a (restricted) allow a (restricted) allowed only for that rule not in set not in set
allow a (restricted) allow all (explicit) allowed in set (bug) not in set
allow all (explicit) no rule allowed (default ACCEPT) in set (bug) not in set
allow all (explicit) allow a (restricted) allowed only for that rule in set (bug) not in set
allow all (explicit) allow all (explicit) allowed in set (correct) in set (correct)

@weizhouapache
weizhouapache requested a lite review from Copilot September 9, 2026 15:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Fixes a security group conntrack optimization bug where a single-direction allow-all rule could incorrectly disable conntrack for both traffic directions on a VM IP.

Changes:

  • Track ingress/egress “allow-all” rules separately per IP family (IPv4/IPv6).
  • Only disable conntrack (NOTRACK ipset membership) when both ingress and egress are allow-all for a given family.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +1139 to +1142
ingress4_allow_all = False
egress4_allow_all = False
ingress6_allow_all = False
egress6_allow_all = False
Comment on lines +1145 to +1153
if '0.0.0.0/0' in rule['ipv4']:
if rule['ruletype'] == 'E':
egress4_allow_all = True
else:
ingress4_allow_all = True
if '::/0' in rule['ipv6']:
if rule['ruletype'] == 'E':
egress6_allow_all = True
else:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:networking Python Warning... Python code Ahead!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VMs with security groups allowing all egress traffic cannot access the Internet in 4.23.0.0

2 participants