Skip to content

Commit 1b5dfd0

Browse files
authored
Merge pull request #112 from stackhpc/upstream/master-2025-02-24
Synchronise master with upstream
2 parents 3f0c310 + 0f0754d commit 1b5dfd0

File tree

12 files changed

+127
-38
lines changed

12 files changed

+127
-38
lines changed

cloudkitty/common/policies/base.py

+43-2
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

+10-5
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

+10-5
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

+10-5
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

+8-5
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

+3-2
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

+5-3
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

+6-3
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

+8-4
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

+3-2
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

cloudkitty/common/policies/v2/tasks.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
check_str=base.ROLE_ADMIN,
2323
description='Schedule a scope for reprocessing',
2424
operations=[{'path': '/v2/task/reprocesses',
25-
'method': 'POST'}]),
25+
'method': 'POST'}],
26+
scope_types=['project']),
2627
policy.DocumentedRuleDefault(
2728
name='schedule:get_task_reprocesses',
2829
check_str=base.ROLE_ADMIN,
2930
description='Get reprocessing schedule tasks for scopes.',
3031
operations=[{'path': '/v2/task/reprocesses',
31-
'method': 'GET'}]),
32+
'method': 'GET'}],
33+
scope_types=['project']),
3234
]
3335

3436

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
features:
3+
- |
4+
The CloudKitty policies implemented the scope concept and new default roles
5+
(``admin``, ``member``, and ``reader``) provided by keystone.
6+
upgrade:
7+
- |
8+
All the policies implement the ``scope_type`` and new defaults.
9+
10+
* **Scope**
11+
12+
Each policy is protected with ``project`` ``scope_type``.
13+
14+
* **New Defaults (Admin, Member and Reader)**
15+
16+
Policies are default to Admin, Member and Reader roles. Old roles are
17+
also supported. There is no change in the legacy admin access.

0 commit comments

Comments
 (0)