Skip to content

Commit 0f0754d

Browse files
gmaanospriteau
authored andcommitted
Add secure RBAC role as new default
This add new RBAC defaults in the cloukitty API policy. There is no change in the admin policy except they are scoped to the 'project'. Adding project reader role in the read APIs which continue to be allow by the member and admin role. Change-Id: Ia693a50210a850626adcd9daab1736335ae2b015
1 parent 591106a commit 0f0754d

File tree

12 files changed

+127
-38
lines changed

12 files changed

+127
-38
lines changed

cloudkitty/common/policies/base.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@
1919
ROLE_ADMIN = 'role:admin'
2020
UNPROTECTED = ''
2121

22+
DEPRECATED_REASON = """
23+
CloudKitty API policies are introducing new default roles with scope_type
24+
capabilities. Old policies are deprecated and silently going to be ignored
25+
in future release.
26+
"""
27+
28+
DEPRECATED_ADMIN_OR_OWNER_POLICY = policy.DeprecatedRule(
29+
name=RULE_ADMIN_OR_OWNER,
30+
check_str='is_admin:True or '
31+
'(role:admin and is_admin_project:True) or '
32+
'project_id:%(project_id)s',
33+
deprecated_reason=DEPRECATED_REASON,
34+
deprecated_since='22.0.0'
35+
)
36+
37+
PROJECT_MEMBER_OR_ADMIN = 'rule:project_member_or_admin'
38+
PROJECT_READER_OR_ADMIN = 'rule:project_reader_or_admin'
39+
2240
rules = [
2341
policy.RuleDefault(
2442
name='context_is_admin',
@@ -27,10 +45,33 @@
2745
name='admin_or_owner',
2846
check_str='is_admin:True or '
2947
'(role:admin and is_admin_project:True) or '
30-
'project_id:%(project_id)s'),
48+
'project_id:%(project_id)s',
49+
deprecated_for_removal=True,
50+
deprecated_reason=DEPRECATED_REASON,
51+
deprecated_since='22.0.0'),
3152
policy.RuleDefault(
3253
name='default',
33-
check_str=UNPROTECTED)
54+
check_str=UNPROTECTED),
55+
policy.RuleDefault(
56+
"project_member_api",
57+
"role:member and project_id:%(project_id)s",
58+
"Default rule for Project level non admin APIs.",
59+
deprecated_rule=DEPRECATED_ADMIN_OR_OWNER_POLICY),
60+
policy.RuleDefault(
61+
"project_reader_api",
62+
"role:reader and project_id:%(project_id)s",
63+
"Default rule for Project level read only APIs.",
64+
deprecated_rule=DEPRECATED_ADMIN_OR_OWNER_POLICY),
65+
policy.RuleDefault(
66+
"project_member_or_admin",
67+
"rule:project_member_api or rule:context_is_admin",
68+
"Default rule for Project Member or admin APIs.",
69+
deprecated_rule=DEPRECATED_ADMIN_OR_OWNER_POLICY),
70+
policy.RuleDefault(
71+
"project_reader_or_admin",
72+
"rule:project_reader_api or rule:context_is_admin",
73+
"Default rule for Project reader or admin APIs.",
74+
deprecated_rule=DEPRECATED_ADMIN_OR_OWNER_POLICY)
3475
]
3576

3677

cloudkitty/common/policies/v1/collector.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,38 @@
2323
check_str=base.ROLE_ADMIN,
2424
description='Return the list of every services mapped to a collector.',
2525
operations=[{'path': '/v1/collector/mappings',
26-
'method': 'LIST'}]),
26+
'method': 'LIST'}],
27+
scope_types=['project']),
2728
policy.DocumentedRuleDefault(
2829
name='collector:get_mapping',
2930
check_str=base.ROLE_ADMIN,
3031
description='Return a service to collector mapping.',
3132
operations=[{'path': '/v1/collector/mappings/{service_id}',
32-
'method': 'GET'}]),
33+
'method': 'GET'}],
34+
scope_types=['project']),
3335
policy.DocumentedRuleDefault(
3436
name='collector:manage_mapping',
3537
check_str=base.ROLE_ADMIN,
3638
description='Manage a service to collector mapping.',
3739
operations=[{'path': '/v1/collector/mappings',
3840
'method': 'POST'},
3941
{'path': '/v1/collector/mappings/{service_id}',
40-
'method': 'DELETE'}]),
42+
'method': 'DELETE'}],
43+
scope_types=['project']),
4144
policy.DocumentedRuleDefault(
4245
name='collector:get_state',
4346
check_str=base.ROLE_ADMIN,
4447
description='Query the enable state of a collector.',
4548
operations=[{'path': '/v1/collector/states/{collector_id}',
46-
'method': 'GET'}]),
49+
'method': 'GET'}],
50+
scope_types=['project']),
4751
policy.DocumentedRuleDefault(
4852
name='collector:update_state',
4953
check_str=base.ROLE_ADMIN,
5054
description='Set the enable state of a collector.',
5155
operations=[{'path': '/v1/collector/states/{collector_id}',
52-
'method': 'PUT'}])
56+
'method': 'PUT'}],
57+
scope_types=['project'])
5358
]
5459

5560

cloudkitty/common/policies/v1/info.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,36 @@
2323
check_str=base.UNPROTECTED,
2424
description='List available services information in Cloudkitty.',
2525
operations=[{'path': '/v1/info/services',
26-
'method': 'LIST'}]),
26+
'method': 'LIST'}],
27+
scope_types=['project']),
2728
policy.DocumentedRuleDefault(
2829
name='info:get_service_info',
2930
check_str=base.UNPROTECTED,
3031
description='Get specified service information.',
3132
operations=[{'path': '/v1/info/services/{metric_id}',
32-
'method': 'GET'}]),
33+
'method': 'GET'}],
34+
scope_types=['project']),
3335
policy.DocumentedRuleDefault(
3436
name='info:list_metrics_info',
3537
check_str=base.UNPROTECTED,
3638
description='List available metrics information in Cloudkitty.',
3739
operations=[{'path': '/v1/info/metrics',
38-
'method': 'LIST'}]),
40+
'method': 'LIST'}],
41+
scope_types=['project']),
3942
policy.DocumentedRuleDefault(
4043
name='info:get_metric_info',
4144
check_str=base.UNPROTECTED,
4245
description='Get specified metric information.',
4346
operations=[{'path': '/v1/info/metrics/{metric_id}',
44-
'method': 'GET'}]),
47+
'method': 'GET'}],
48+
scope_types=['project']),
4549
policy.DocumentedRuleDefault(
4650
name='info:get_config',
4751
check_str=base.UNPROTECTED,
4852
description='Get current configuration in Cloudkitty.',
4953
operations=[{'path': '/v1/info/config',
50-
'method': 'GET'}])
54+
'method': 'GET'}],
55+
scope_types=['project'])
5156
]
5257

5358

cloudkitty/common/policies/v1/rating.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,37 @@
2323
check_str=base.ROLE_ADMIN,
2424
description='Return the list of loaded modules in Cloudkitty.',
2525
operations=[{'path': '/v1/rating/modules',
26-
'method': 'LIST'}]),
26+
'method': 'LIST'}],
27+
scope_types=['project']),
2728
policy.DocumentedRuleDefault(
2829
name='rating:get_module',
2930
check_str=base.ROLE_ADMIN,
3031
description='Get specified module.',
3132
operations=[{'path': '/v1/rating/modules/{module_id}',
32-
'method': 'GET'}]),
33+
'method': 'GET'}],
34+
scope_types=['project']),
3335
policy.DocumentedRuleDefault(
3436
name='rating:update_module',
3537
check_str=base.ROLE_ADMIN,
3638
description='Change the state and priority of a module.',
3739
operations=[{'path': '/v1/rating/modules/{module_id}',
38-
'method': 'PUT'}]),
40+
'method': 'PUT'}],
41+
scope_types=['project']),
3942
policy.DocumentedRuleDefault(
4043
name='rating:quote',
4144
check_str=base.UNPROTECTED,
4245
description='Get an instant quote based on multiple resource '
4346
'descriptions.',
4447
operations=[{'path': '/v1/rating/quote',
45-
'method': 'POST'}]),
48+
'method': 'POST'}],
49+
scope_types=['project']),
4650
policy.DocumentedRuleDefault(
4751
name='rating:module_config',
4852
check_str=base.ROLE_ADMIN,
4953
description='Trigger a rating module list reload.',
5054
operations=[{'path': '/v1/rating/reload_modules',
51-
'method': 'GET'}])
55+
'method': 'GET'}],
56+
scope_types=['project'])
5257
]
5358

5459

cloudkitty/common/policies/v1/report.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,22 @@
2323
check_str=base.ROLE_ADMIN,
2424
description='Return the list of rated tenants.',
2525
operations=[{'path': '/v1/report/tenants',
26-
'method': 'GET'}]),
26+
'method': 'GET'}],
27+
scope_types=['project']),
2728
policy.DocumentedRuleDefault(
2829
name='report:get_summary',
29-
check_str=base.RULE_ADMIN_OR_OWNER,
30+
check_str=base.PROJECT_READER_OR_ADMIN,
3031
description='Return the summary to pay for a given period.',
3132
operations=[{'path': '/v1/report/summary',
32-
'method': 'GET'}]),
33+
'method': 'GET'}],
34+
scope_types=['project']),
3335
policy.DocumentedRuleDefault(
3436
name='report:get_total',
35-
check_str=base.RULE_ADMIN_OR_OWNER,
37+
check_str=base.PROJECT_READER_OR_ADMIN,
3638
description='Return the amount to pay for a given period.',
3739
operations=[{'path': '/v1/report/total',
38-
'method': 'GET'}])
40+
'method': 'GET'}],
41+
scope_types=['project'])
3942
]
4043

4144

cloudkitty/common/policies/v1/storage.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
storage_policies = [
2121
policy.DocumentedRuleDefault(
2222
name='storage:list_data_frames',
23-
check_str=base.RULE_ADMIN_OR_OWNER,
23+
check_str=base.PROJECT_READER_OR_ADMIN,
2424
description='Return a list of rated resources for a time period '
2525
'and a tenant.',
2626
operations=[{'path': '/v1/storage/dataframes',
27-
'method': 'GET'}])
27+
'method': 'GET'}],
28+
scope_types=['project'])
2829
]
2930

3031

cloudkitty/common/policies/v2/dataframes.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323
check_str=base.ROLE_ADMIN,
2424
description='Add one or several DataFrames',
2525
operations=[{'path': '/v2/dataframes',
26-
'method': 'POST'}]),
26+
'method': 'POST'}],
27+
scope_types=['project']),
2728
policy.DocumentedRuleDefault(
2829
name='dataframes:get',
29-
check_str=base.RULE_ADMIN_OR_OWNER,
30+
check_str=base.PROJECT_READER_OR_ADMIN,
3031
description='Get DataFrames',
3132
operations=[{'path': '/v2/dataframes',
32-
'method': 'GET'}]),
33+
'method': 'GET'}],
34+
scope_types=['project']),
3335
]
3436

3537

cloudkitty/common/policies/v2/rating.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,22 @@
2323
check_str=base.ROLE_ADMIN,
2424
description='Returns the list of loaded modules in Cloudkitty.',
2525
operations=[{'path': '/v2/rating/modules',
26-
'method': 'GET'}]),
26+
'method': 'GET'}],
27+
scope_types=['project']),
2728
policy.DocumentedRuleDefault(
2829
name='v2_rating:get_module',
2930
check_str=base.ROLE_ADMIN,
3031
description='Get specified module.',
3132
operations=[{'path': '/v2/rating/modules/{module_id}',
32-
'method': 'GET'}]),
33+
'method': 'GET'}],
34+
scope_types=['project']),
3335
policy.DocumentedRuleDefault(
3436
name='v2_rating:update_module',
3537
check_str=base.ROLE_ADMIN,
3638
description='Change the state and priority of a module.',
3739
operations=[{'path': '/v2/rating/modules/{module_id}',
38-
'method': 'PUT'}])
40+
'method': 'PUT'}],
41+
scope_types=['project'])
3942
]
4043

4144

cloudkitty/common/policies/v2/scope.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,29 @@
2323
check_str=base.ROLE_ADMIN,
2424
description='Get the state of one or several scopes',
2525
operations=[{'path': '/v2/scope',
26-
'method': 'GET'}]),
26+
'method': 'GET'}],
27+
scope_types=['project']),
2728
policy.DocumentedRuleDefault(
2829
name='scope:reset_state',
2930
check_str=base.ROLE_ADMIN,
3031
description='Reset the state of one or several scopes',
3132
operations=[{'path': '/v2/scope',
32-
'method': 'PUT'}]),
33+
'method': 'PUT'}],
34+
scope_types=['project']),
3335
policy.DocumentedRuleDefault(
3436
name='scope:patch_state',
3537
check_str=base.ROLE_ADMIN,
3638
description='Enables operators to patch a storage scope',
3739
operations=[{'path': '/v2/scope',
38-
'method': 'PATCH'}]),
40+
'method': 'PATCH'}],
41+
scope_types=['project']),
3942
policy.DocumentedRuleDefault(
4043
name='scope:post_state',
4144
check_str=base.ROLE_ADMIN,
4245
description='Enables operators to create a storage scope',
4346
operations=[{'path': '/v2/scope',
44-
'method': 'POST'}]),
47+
'method': 'POST'}],
48+
scope_types=['project']),
4549
]
4650

4751

cloudkitty/common/policies/v2/summary.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
example_policies = [
2020
policy.DocumentedRuleDefault(
2121
name='summary:get_summary',
22-
check_str=base.RULE_ADMIN_OR_OWNER,
22+
check_str=base.PROJECT_READER_OR_ADMIN,
2323
description='Get a rating summary',
2424
operations=[{'path': '/v2/summary',
25-
'method': 'GET'}]),
25+
'method': 'GET'}],
26+
scope_types=['project']),
2627
]
2728

2829

0 commit comments

Comments
 (0)