Skip to content

Commit 3845ca2

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Do not allow a tenant to create a default SG for another one" into stable/yoga
2 parents c002627 + fd7fb0e commit 3845ca2

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

neutron/db/securitygroups_db.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,10 @@ def _ensure_default_security_group(self, context, tenant_id):
930930
931931
:returns: the default security group id for given tenant.
932932
"""
933+
# Do not allow a tenant to create a default SG for another one.
934+
# See Bug 1987410.
935+
if tenant_id != context.tenant_id and not context.is_admin:
936+
return
933937
if not extensions.is_extension_supported(self, 'security-group'):
934938
return
935939
default_group_id = self._get_default_sg_id(context, tenant_id)

neutron/tests/unit/db/test_securitygroups_db.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,3 +660,15 @@ def test__ensure_default_security_group_when_disabled(self):
660660
self.mixin._ensure_default_security_group(self.ctx, 'tenant_1')
661661
create_sg.assert_not_called()
662662
get_default_sg_id.assert_not_called()
663+
664+
def test__ensure_default_security_group_tenant_mismatch(self):
665+
with mock.patch.object(
666+
self.mixin, '_get_default_sg_id') as get_default_sg_id,\
667+
mock.patch.object(
668+
self.mixin, 'create_security_group') as create_sg:
669+
context = mock.Mock()
670+
context.tenant_id = 'tenant_0'
671+
context.is_admin = False
672+
self.mixin._ensure_default_security_group(context, 'tenant_1')
673+
create_sg.assert_not_called()
674+
get_default_sg_id.assert_not_called()

0 commit comments

Comments
 (0)