diff --git a/nova/policies/instance_actions.py b/nova/policies/instance_actions.py index 3d800b2bd6..32d465cd80 100644 --- a/nova/policies/instance_actions.py +++ b/nova/policies/instance_actions.py @@ -24,9 +24,9 @@ POLICY_ROOT = 'os_compute_api:os-instance-actions:%s' instance_actions_policies = [ policy.DocumentedRuleDefault( - POLICY_ROOT % 'events', - base.RULE_ADMIN_API, - """Add events details in action details for a server. + name=POLICY_ROOT % 'events', + check_str=base.RULE_ADMIN_API, + description="""Add events details in action details for a server. This check is performed only after the check os_compute_api:os-instance-actions passes. Beginning with @@ -35,17 +35,18 @@ information is provided per event if policy enforcement passes. Beginning with Microversion 2.62, each event includes a hashed host identifier and, if policy enforcement passes, the name of the host.""", - [ + operations=[ { 'method': 'GET', 'path': '/servers/{server_id}/os-instance-actions/{request_id}' } - ]), + ], + scope_types=['system']), policy.DocumentedRuleDefault( - BASE_POLICY_NAME, - base.RULE_ADMIN_OR_OWNER, - """List actions and show action details for a server.""", - [ + name=BASE_POLICY_NAME, + check_str=base.RULE_ADMIN_OR_OWNER, + description="""List actions and show action details for a server.""", + operations=[ { 'method': 'GET', 'path': '/servers/{server_id}/os-instance-actions' @@ -54,7 +55,8 @@ the host.""", 'method': 'GET', 'path': '/servers/{server_id}/os-instance-actions/{request_id}' } - ]), + ], + scope_types=['system', 'project']), ] diff --git a/nova/tests/unit/policies/test_instance_actions.py b/nova/tests/unit/policies/test_instance_actions.py index 0ed11dc165..0fa18ed279 100644 --- a/nova/tests/unit/policies/test_instance_actions.py +++ b/nova/tests/unit/policies/test_instance_actions.py @@ -160,3 +160,17 @@ class InstanceActionsScopeTypePolicyTest(InstanceActionsPolicyTest): def setUp(self): super(InstanceActionsScopeTypePolicyTest, self).setUp() self.flags(enforce_scope=True, group="oslo_policy") + + # Check that system admin is able to get the + # instance action events + self.admin_authorized_contexts = [ + self.system_admin_context] + # Check that non-system or non-admin is not able to + # get the instance action events + self.admin_unauthorized_contexts = [ + self.legacy_admin_context, self.system_member_context, + self.system_reader_context, self.system_foo_context, + self.project_admin_context, self.project_member_context, + self.other_project_member_context, + self.project_foo_context, self.project_reader_context + ]