|
54 | 54 | from neutron.extensions import l3
|
55 | 55 | from neutron.extensions import segment as segment_ext
|
56 | 56 | from neutron.objects import base as base_obj
|
| 57 | +from neutron.objects import network as network_obj |
57 | 58 | from neutron.objects import port_forwarding
|
58 | 59 | from neutron.objects import ports as port_obj
|
59 | 60 | from neutron.objects import router as l3_obj
|
@@ -856,9 +857,24 @@ def _add_interface_by_subnet(self, context, router, subnet_id, owner):
|
856 | 857 | msg = _('Subnet for router interface must have a gateway IP')
|
857 | 858 | raise n_exc.BadRequest(resource='router', msg=msg)
|
858 | 859 | if subnet['project_id'] != context.project_id and not context.is_admin:
|
859 |
| - msg = (_('Cannot add interface to router because subnet %s is not ' |
860 |
| - 'owned by project making the request') % subnet_id) |
861 |
| - raise n_exc.BadRequest(resource='router', msg=msg) |
| 860 | + # NOTE(amorin): check if network is RBAC or globaly shared |
| 861 | + # globaly shared --> disallow adding interface (see LP-1757482) |
| 862 | + # RBAC shared --> allow adding interface (see LP-1975603) |
| 863 | + elevated = context.elevated() |
| 864 | + |
| 865 | + with db_api.CONTEXT_READER.using(elevated): |
| 866 | + rbac_allowed_projects = network_obj.NetworkRBAC.get_projects( |
| 867 | + elevated, object_id=subnet['network_id'], |
| 868 | + action='access_as_shared', |
| 869 | + target_project=context.project_id) |
| 870 | + |
| 871 | + # Fail if the current project_id is NOT in the allowed |
| 872 | + # projects |
| 873 | + if context.project_id not in rbac_allowed_projects: |
| 874 | + msg = (_('Cannot add interface to router because subnet ' |
| 875 | + '%s is not owned by project making the request') |
| 876 | + % subnet_id) |
| 877 | + raise n_exc.BadRequest(resource='router', msg=msg) |
862 | 878 | self._validate_subnet_address_mode(subnet)
|
863 | 879 | self._check_for_dup_router_subnets(context, router,
|
864 | 880 | subnet['network_id'], [subnet])
|
|
0 commit comments