Skip to content

Commit 0eccc52

Browse files
rbreker-godaddyrobertbreker
authored andcommitted
Enhance IptablesFirewallDriver with remote address groups
This change enhances the IptablesFirewallDriver with support for remote address groups. Previously, this feature was only available in the OVSFirewallDriver. This commit harmonizes the capabilities across both firewall drivers, and by inheritance also to OVSHybridIptablesFirewallDriver. Background - The Neutron API allows operators to configure remote address groups [1], however the OVSHybridIptablesFirewallDriver and IptablesFirewallDriver do not implement these remote group restrictions. When configuring security group rules with remote address groups, connections get enabled based on other rule parameters, ignoring the configured remote address group restrictions. This behaviour undocumented, and may lead to more-open-than-configured network access. Closes-Bug: #2058138 Change-Id: I76b3cb46ee603fa5e829537af41316bb42a6f30f (cherry picked from commit 5e1188e)
1 parent fed9654 commit 0eccc52

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

neutron/agent/linux/iptables_firewall.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,15 @@ def _select_sg_rules_for_port(self, port, direction):
622622
rule, port, direction))
623623
return port_rules
624624

625+
def _get_any_remote_group_id_in_rule(self, rule):
626+
remote_group_id = rule.get('remote_group_id')
627+
if not remote_group_id:
628+
remote_group_id = rule.get('remote_address_group_id')
629+
return remote_group_id
630+
625631
def _expand_sg_rule_with_remote_ips(self, rule, port, direction):
626632
"""Expand a remote group rule to rule per remote group IP."""
627-
remote_group_id = rule.get('remote_group_id')
633+
remote_group_id = self._get_any_remote_group_id_in_rule(rule)
628634
if remote_group_id:
629635
ethertype = rule['ethertype']
630636
port_ips = port.get('fixed_ips', [])
@@ -646,7 +652,7 @@ def _get_remote_sg_ids(self, port, direction=None):
646652
for sg_id in sg_ids:
647653
for rule in self.sg_rules.get(sg_id, []):
648654
if not direction or rule['direction'] == direction:
649-
remote_sg_id = rule.get('remote_group_id')
655+
remote_sg_id = self._get_any_remote_group_id_in_rule(rule)
650656
ether_type = rule.get('ethertype')
651657
if remote_sg_id and ether_type:
652658
remote_sg_ids[ether_type].add(remote_sg_id)
@@ -726,7 +732,7 @@ def _generate_plain_rule_args(self, sg_rule):
726732
return args
727733

728734
def _convert_sg_rule_to_iptables_args(self, sg_rule):
729-
remote_gid = sg_rule.get('remote_group_id')
735+
remote_gid = self._get_any_remote_group_id_in_rule(sg_rule)
730736
if self.enable_ipset and remote_gid:
731737
return self._generate_ipset_rule_args(sg_rule, remote_gid)
732738
else:

neutron/tests/unit/agent/linux/test_iptables_firewall.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,6 +2457,22 @@ def test_filter_defer_apply_off_with_sg_only_ipv6_rule(self):
24572457

24582458
self.firewall.ipset.assert_has_calls(calls, True)
24592459

2460+
def test__get_any_remote_group_id_in_rule_with_remote_group(self):
2461+
sg_rule = {'direction': 'ingress',
2462+
'remote_group_id': FAKE_SGID,
2463+
'ethertype': _IPv4}
2464+
2465+
self.assertEqual(FAKE_SGID,
2466+
self.firewall._get_any_remote_group_id_in_rule(sg_rule))
2467+
2468+
def test__get_any_remote_group_id_in_rule_with_remote_address_group(self):
2469+
sg_rule = {'direction': 'ingress',
2470+
'remote_address_group_id': FAKE_SGID,
2471+
'ethertype': _IPv6}
2472+
2473+
self.assertEqual(FAKE_SGID,
2474+
self.firewall._get_any_remote_group_id_in_rule(sg_rule))
2475+
24602476
def test_sg_rule_expansion_with_remote_ips(self):
24612477
other_ips = [('10.0.0.2', 'fa:16:3e:aa:bb:c1'),
24622478
('10.0.0.3', 'fa:16:3e:aa:bb:c2'),
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
features:
3+
- |
4+
Remote address group support was added to the iptables-based firewall
5+
drivers (IptablesFirewallDriver and OVSHybridIptablesFirewallDriver),
6+
Previously it was only available in the OVSFirewallDriver.
7+
For more information, see bug
8+
`2058138 <https://bugs.launchpad.net/neutron/+bug/2058138>`_.

0 commit comments

Comments
 (0)