Skip to content

Commit 872c6ad

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 a8bf8cd commit 872c6ad

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
@@ -599,9 +599,15 @@ def _select_sg_rules_for_port(self, port, direction):
599599
rule, port, direction))
600600
return port_rules
601601

602+
def _get_any_remote_group_id_in_rule(self, rule):
603+
remote_group_id = rule.get('remote_group_id')
604+
if not remote_group_id:
605+
remote_group_id = rule.get('remote_address_group_id')
606+
return remote_group_id
607+
602608
def _expand_sg_rule_with_remote_ips(self, rule, port, direction):
603609
"""Expand a remote group rule to rule per remote group IP."""
604-
remote_group_id = rule.get('remote_group_id')
610+
remote_group_id = self._get_any_remote_group_id_in_rule(rule)
605611
if remote_group_id:
606612
ethertype = rule['ethertype']
607613
port_ips = port.get('fixed_ips', [])
@@ -623,7 +629,7 @@ def _get_remote_sg_ids(self, port, direction=None):
623629
for sg_id in sg_ids:
624630
for rule in self.sg_rules.get(sg_id, []):
625631
if not direction or rule['direction'] == direction:
626-
remote_sg_id = rule.get('remote_group_id')
632+
remote_sg_id = self._get_any_remote_group_id_in_rule(rule)
627633
ether_type = rule.get('ethertype')
628634
if remote_sg_id and ether_type:
629635
remote_sg_ids[ether_type].add(remote_sg_id)
@@ -703,7 +709,7 @@ def _generate_plain_rule_args(self, sg_rule):
703709
return args
704710

705711
def _convert_sg_rule_to_iptables_args(self, sg_rule):
706-
remote_gid = sg_rule.get('remote_group_id')
712+
remote_gid = self._get_any_remote_group_id_in_rule(sg_rule)
707713
if self.enable_ipset and remote_gid:
708714
return self._generate_ipset_rule_args(sg_rule, remote_gid)
709715
else:

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

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

23342334
self.firewall.ipset.assert_has_calls(calls, True)
23352335

2336+
def test__get_any_remote_group_id_in_rule_with_remote_group(self):
2337+
sg_rule = {'direction': 'ingress',
2338+
'remote_group_id': FAKE_SGID,
2339+
'ethertype': _IPv4}
2340+
2341+
self.assertEqual(FAKE_SGID,
2342+
self.firewall._get_any_remote_group_id_in_rule(sg_rule))
2343+
2344+
def test__get_any_remote_group_id_in_rule_with_remote_address_group(self):
2345+
sg_rule = {'direction': 'ingress',
2346+
'remote_address_group_id': FAKE_SGID,
2347+
'ethertype': _IPv6}
2348+
2349+
self.assertEqual(FAKE_SGID,
2350+
self.firewall._get_any_remote_group_id_in_rule(sg_rule))
2351+
23362352
def test_sg_rule_expansion_with_remote_ips(self):
23372353
other_ips = [('10.0.0.2', 'fa:16:3e:aa:bb:c1'),
23382354
('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)