Force security_group_id uuid validation of sg rules

security_groups_db._check_security_group is supposed to check the
security_group_id of the _create_security_group_rule payload.
When using an integer e.g. 0, as security_group_id, the check
succededs because mysql accepts following query:

SELECT * FROM securitygroups WHERE id in (0)

Forcing validation of security_group_id as uuid fixes the problem

Closes-Bug: #1968343
Change-Id: I7c36b09309c1ef66608afacfb281b6f4b06ea5b8
This commit is contained in:
Andrew Karpow 2022-04-08 18:32:03 +02:00
parent 430abde13e
commit c0bf560fa3
No known key found for this signature in database
GPG Key ID: 5B1BD70412859599
2 changed files with 12 additions and 1 deletions

View File

@ -245,7 +245,9 @@ RESOURCE_ATTRIBUTE_MAP = {
'primary_key': True},
'security_group_id': {'allow_post': True, 'allow_put': False,
'is_visible': True, 'required_by_policy': True,
'is_sort_key': True, 'is_filter': True},
'is_sort_key': True, 'is_filter': True,
'validate': {
'type:string': db_const.UUID_FIELD_SIZE}},
'remote_group_id': {'allow_post': True, 'allow_put': False,
'default': None, 'is_visible': True,
'is_sort_key': True, 'is_filter': True},

View File

@ -2087,6 +2087,15 @@ class TestSecurityGroups(SecurityGroupDBTestCase):
self.deserialize(self.fmt, res)
self.assertEqual(webob.exc.HTTPBadRequest.code, res.status_int)
def test_create_security_group_rule_with_non_uuid_security_group_id(self):
security_group_id = 0
rule = self._build_security_group_rule(
security_group_id, 'ingress',
const.PROTO_NAME_TCP, '22', '22')
res = self._create_security_group_rule(self.fmt, rule)
self.deserialize(self.fmt, res)
self.assertEqual(webob.exc.HTTPBadRequest.code, res.status_int)
def test_create_port_with_non_uuid(self):
with self.network() as n:
with self.subnet(n):