|
18 | 18 |
|
19 | 19 | # pylint: disable=line-too-long
|
20 | 20 |
|
21 |
| -from neutron.conf.policies import base |
| 21 | +from neutron.conf.policies import base, network |
22 | 22 | from oslo_policy import policy
|
23 | 23 |
|
24 | 24 | rules = [
|
25 |
| - # Base rule definitions must be exact copies of the base poilicy. |
26 |
| - policy.RuleDefault( |
27 |
| - name='base_create_network', |
28 |
| - check_str=base.ADMIN_OR_PROJECT_MEMBER, |
29 |
| - description='Create a network', |
30 |
| - ), |
31 |
| - policy.RuleDefault( |
32 |
| - name='base_create_network:segments', |
33 |
| - check_str=base.ADMIN, |
34 |
| - description='Specify ``segments`` attribute when creating a network', |
35 |
| - ), |
36 |
| - policy.RuleDefault( |
37 |
| - name='base_create_network:provider:network_type', |
38 |
| - check_str=base.ADMIN, |
39 |
| - description='Specify ``provider:network_type`` when creating a network', |
40 |
| - ), |
41 |
| - policy.RuleDefault( |
42 |
| - name='base_create_network:provider:physical_network', |
43 |
| - check_str=base.ADMIN, |
44 |
| - description='Specify ``provider:physical_network`` when creating a network', |
45 |
| - ), |
46 |
| - policy.RuleDefault( |
47 |
| - name='base_create_network:provider:segmentation_id', |
48 |
| - check_str=base.ADMIN, |
49 |
| - description='Specify ``provider:segmentation_id`` when creating a network', |
50 |
| - ), |
51 |
| - policy.RuleDefault( |
52 |
| - name='base_delete_network', |
53 |
| - check_str=base.ADMIN_OR_PROJECT_MEMBER, |
54 |
| - description='Delete a network', |
55 |
| - ), |
56 |
| - |
57 | 25 | # The domain manager has the role 'manager', as defined by
|
58 | 26 | # https://docs.scs.community/standards/scs-0302-v1-domain-manager-role/
|
59 | 27 | policy.RuleDefault(
|
|
63 | 31 | ),
|
64 | 32 |
|
65 | 33 | # The domain manager can create and delete networks in its domain.
|
| 34 | + # If the domain manager is able to create a network, it can also create provider networks. |
| 35 | + # Don't be naive enough here to assume the ability to provision a network is enough to |
| 36 | + # allow provider networks, if the prior rule changes, then we can open up a security hole. |
66 | 37 | policy.RuleDefault(
|
67 | 38 | name='create_network',
|
68 | 39 | check_str='(rule:is_domain_manager and domain_id:%(domain_id)s) or rule:base_create_network',
|
|
73 | 44 | check_str='(rule:is_domain_manager and domain_id:%(domain_id)s) or rule:base_delete_network',
|
74 | 45 | description='Delete a network',
|
75 | 46 | ),
|
76 |
| - |
77 |
| - # If the domain manager is able to create a network, it can also create provider networks. |
78 |
| - # Don't be naive enough here to assume the ability to provision a network is enough to |
79 |
| - # allow provider networks, if the prior rule changes, then we can open up a security hole. |
80 | 47 | policy.RuleDefault(
|
81 | 48 | name='create_network:segments',
|
82 | 49 | check_str='(rule:is_domain_manager and domain_id:%(domain_id)s) or rule:base_create_network:segments',
|
|
99 | 66 | ),
|
100 | 67 | ]
|
101 | 68 |
|
| 69 | + |
| 70 | +def basify(rule): |
| 71 | + """Do a copy of the existing rule with a base_ name prefix""" |
| 72 | + |
| 73 | + return policy.RuleDefault( |
| 74 | + name='base_' + rule.name, check_str=rule.check_str, description=rule.description) |
| 75 | + |
| 76 | + |
| 77 | +def inherited(rule): |
| 78 | + """Is the rule inherited by one that we have defined?""" |
| 79 | + |
| 80 | + return any(rule.name == my_rule.name for my_rule in rules) |
| 81 | + |
| 82 | + |
102 | 83 | def list_rules():
|
103 | 84 | """Implements the "oslo.policy.policies" entry point"""
|
104 |
| - return base.list_rules() + rules |
| 85 | + |
| 86 | + # Okay now for the "hard" bit. We reference built in rules directly from neutron so |
| 87 | + # we can augment the exact rules for a specific version, thus we pick up any changes. |
| 88 | + # We prefix the existing rules with "base_" as already seen above but only if they |
| 89 | + # are redefined (and by implication referenced) from one of ours. |
| 90 | + network_rules = [basify(rule) for rule in network.list_rules() if inherited(rule)] |
| 91 | + |
| 92 | + # Those rules will also rely on base rules, so include them too in the final output. |
| 93 | + return base.list_rules() + network_rules + rules |
105 | 94 |
|
106 | 95 | # vi: ts=4 et:
|
0 commit comments