Skip to content

Commit 5a96fc1

Browse files
committed
[S-RBAC] Fix policies for the local_ip association APIs
This patch updates local_ip association API policies so that POST and DELETE actions are allowed for the PARENT_OWNER_MEMBER role and GET is allowed for the PARENT_OWNER_READER. Additionally this patch fixes unit tests for the api policies for that APIs so that owner check is done during unit tests and issues like the one mentioned above can be catched by unit tests. Closes-bug: #2125657 Change-Id: I6844995d2b4c6e5ec4e2772d48d1a2b606dc558b Signed-off-by: Slawek Kaplonski <[email protected]> (cherry picked from commit cc3813b)
1 parent 1555e14 commit 5a96fc1

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

neutron/conf/policies/local_ip_association.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
name='create_local_ip_port_association',
3030
check_str=neutron_policy.policy_or(
3131
base.ADMIN_OR_PROJECT_MEMBER,
32-
base.RULE_PARENT_OWNER),
32+
base.PARENT_OWNER_MEMBER),
3333
scope_types=['project'],
3434
description='Create a Local IP port association',
3535
operations=[
@@ -48,7 +48,7 @@
4848
name='get_local_ip_port_association',
4949
check_str=neutron_policy.policy_or(
5050
base.ADMIN_OR_PROJECT_READER,
51-
base.RULE_PARENT_OWNER),
51+
base.PARENT_OWNER_READER),
5252
scope_types=['project'],
5353
description='Get a Local IP port association',
5454
operations=[
@@ -71,7 +71,7 @@
7171
name='delete_local_ip_port_association',
7272
check_str=neutron_policy.policy_or(
7373
base.ADMIN_OR_PROJECT_MEMBER,
74-
base.RULE_PARENT_OWNER),
74+
base.PARENT_OWNER_MEMBER),
7575
scope_types=['project'],
7676
description='Delete a Local IP port association',
7777
operations=[

neutron/tests/unit/conf/policies/test_local_ip_association.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,29 @@ def setUp(self):
2929
self.local_ip = {
3030
'id': uuidutils.generate_uuid(),
3131
'project_id': self.project_id}
32+
self.alt_local_ip = {
33+
'id': uuidutils.generate_uuid(),
34+
'project_id': self.alt_project_id}
3235

3336
self.target = {
3437
'project_id': self.project_id,
3538
'local_ip_id': self.local_ip['id'],
3639
'ext_parent_local_ip_id': self.local_ip['id']}
3740
self.alt_target = {
3841
'project_id': self.alt_project_id,
39-
'local_ip_id': self.local_ip['id'],
40-
'ext_parent_local_ip_id': self.local_ip['id']}
42+
'local_ip_id': self.alt_local_ip['id'],
43+
'ext_parent_local_ip_id': self.alt_local_ip['id']}
44+
45+
local_ips = {
46+
self.local_ip['id']: self.local_ip,
47+
self.alt_local_ip['id']: self.alt_local_ip,
48+
}
49+
50+
def get_local_ip(context, lip_id, fields=None):
51+
return local_ips[lip_id]
4152

4253
self.plugin_mock = mock.Mock()
43-
self.plugin_mock.get_local_ip.return_value = self.local_ip
54+
self.plugin_mock.get_local_ip.side_effect = get_local_ip
4455
mock.patch(
4556
'neutron_lib.plugins.directory.get_plugin',
4657
return_value=self.plugin_mock).start()

0 commit comments

Comments
 (0)