From cd470539eda4fc53a34a06728da0b26b5e7faca5 Mon Sep 17 00:00:00 2001 From: Ghanshyam Mann Date: Sun, 5 Apr 2020 03:36:40 -0500 Subject: [PATCH] Add new default roles in shelve server policies This adds new defaults roles in shelve server API policies. This policy is default to - PROJECT_MEMBER_OR_SYSTEM_ADMIN for shelve/unshelve - SYSTEM_ADMIN for shelve offload. Also add tests to simulates the future where we drop the deprecation fall back in the policy by overriding the rules with a version where there are no deprecated rule options. Operators can do the same by adding overrides in their policy files that match the default but stop the rule deprecation fallback from happening. Partial implement blueprint policy-defaults-refresh Change-Id: I63e65789e8cc48b75c9e6e4e333624172fd298d8 --- nova/policies/shelve.py | 6 ++--- nova/tests/unit/policies/test_shelve.py | 36 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/nova/policies/shelve.py b/nova/policies/shelve.py index f861274ab242..da4a3354ce73 100644 --- a/nova/policies/shelve.py +++ b/nova/policies/shelve.py @@ -24,7 +24,7 @@ POLICY_ROOT = 'os_compute_api:os-shelve:%s' shelve_policies = [ policy.DocumentedRuleDefault( name=POLICY_ROOT % 'shelve', - check_str=base.RULE_ADMIN_OR_OWNER, + check_str=base.PROJECT_MEMBER_OR_SYSTEM_ADMIN, description="Shelve server", operations=[ { @@ -35,7 +35,7 @@ shelve_policies = [ scope_types=['system', 'project']), policy.DocumentedRuleDefault( name=POLICY_ROOT % 'unshelve', - check_str=base.RULE_ADMIN_OR_OWNER, + check_str=base.PROJECT_MEMBER_OR_SYSTEM_ADMIN, description="Unshelve (restore) shelved server", operations=[ { @@ -46,7 +46,7 @@ shelve_policies = [ scope_types=['system', 'project']), policy.DocumentedRuleDefault( name=POLICY_ROOT % 'shelve_offload', - check_str=base.RULE_ADMIN_API, + check_str=base.SYSTEM_ADMIN, description="Shelf-offload (remove) server", operations=[ { diff --git a/nova/tests/unit/policies/test_shelve.py b/nova/tests/unit/policies/test_shelve.py index 9b1bbcd12a54..988549dc2164 100644 --- a/nova/tests/unit/policies/test_shelve.py +++ b/nova/tests/unit/policies/test_shelve.py @@ -135,3 +135,39 @@ class ShelveServerScopeTypePolicyTest(ShelveServerPolicyTest): def setUp(self): super(ShelveServerScopeTypePolicyTest, self).setUp() self.flags(enforce_scope=True, group="oslo_policy") + + +class ShelveServerNoLegacyPolicyTest(ShelveServerScopeTypePolicyTest): + """Test Shelve Server APIs policies with system scope enabled, + and no more deprecated rules. + """ + without_deprecated_rules = True + + def setUp(self): + super(ShelveServerNoLegacyPolicyTest, self).setUp() + + # Check that system admin or and owner is able to shelve/unshelve + # the server. + self.admin_or_owner_authorized_contexts = [ + self.system_admin_context, + self.project_admin_context, self.project_member_context] + # Check that non-system/admin/owner is not able to shelve/unshelve + # the server. + self.admin_or_owner_unauthorized_contexts = [ + self.legacy_admin_context, self.system_member_context, + self.system_reader_context, self.system_foo_context, + self.other_project_member_context, self.project_reader_context, + self.project_foo_context + ] + # Check that system admin is able to shelve offload the server. + self.admin_authorized_contexts = [ + self.system_admin_context + ] + # Check that non system admin is not able to shelve offload the server + self.admin_unauthorized_contexts = [ + self.legacy_admin_context, self.project_admin_context, + self.system_member_context, self.system_reader_context, + self.system_foo_context, self.project_member_context, + self.project_reader_context, self.project_foo_context, + self.other_project_member_context + ]