Skip to content

Commit 824f92a

Browse files
committed
kvm: keep conntrack disabled for security groups with allow-all ingress and no egress rules
Egress with no rules ends in an unconditional ACCEPT, so it is as open as an explicit allow-all egress rule. Treat it as open when deciding whether the VM IP can be added to the notrack ipset.
1 parent 698614a commit 824f92a

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎scripts/vm/network/security_group.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,12 @@ def add_network_rules(vm_name, vm_id, vm_ip, vm_ip6, signature, seqno, vmMac, ru
11401140
egress4_allow_all = False
11411141
ingress6_allow_all = False
11421142
egress6_allow_all = False
1143+
egress4_has_rules = False
1144+
egress6_has_rules = False
11431145
for rule in rules:
1146+
if rule['ruletype'] == 'E':
1147+
egress4_has_rules = egress4_has_rules or bool(rule['ipv4'])
1148+
egress6_has_rules = egress6_has_rules or bool(rule['ipv6'])
11441149
if rule['protocol'].lower() == 'all':
11451150
if '0.0.0.0/0' in rule['ipv4']:
11461151
if rule['ruletype'] == 'E':
@@ -1153,8 +1158,11 @@ def add_network_rules(vm_name, vm_id, vm_ip, vm_ip6, signature, seqno, vmMac, ru
11531158
else:
11541159
ingress6_allow_all = True
11551160

1156-
conntrack4_not_needed = ingress4_allow_all and egress4_allow_all
1157-
conntrack6_not_needed = ingress6_allow_all and egress6_allow_all
1161+
# The NOTRACK rules apply to the IP in both directions, so conntrack can only be skipped when
1162+
# ingress allows all and egress is open as well: either an explicit allow-all egress rule or no
1163+
# egress rules at all (the egress chain then accepts everything).
1164+
conntrack4_not_needed = ingress4_allow_all and (egress4_allow_all or not egress4_has_rules)
1165+
conntrack6_not_needed = ingress6_allow_all and (egress6_allow_all or not egress6_has_rules)
11581166

11591167
if conntrack4_not_needed:
11601168
add_to_ipset(NOTRACK_IPV4_IPSET, ip4s, "add")

0 commit comments

Comments
 (0)