From 1d8ac830a1ed6a571db6987d4ef657cf3e04d640 Mon Sep 17 00:00:00 2001 From: Lance Bragstad Date: Thu, 21 Mar 2019 18:21:42 +0000 Subject: [PATCH] Update system group assignment policies for reader and member This commit introduces the reader and member default roles to the system assignment API for groups. Users with the `reader` and `member` role on the system should be able to list and check system role assignments for all users in the deployment. Subsequent patches will: - simplify the policies for system admin - add domain user test coverage - add project user test coverage - remove obsolete policies from policy.v3cloudsample.json Change-Id: I7eebb1b07213a1406e98f8a621ec44c87b812457 Related-Bug: 1805368 Related-Bug: 1750669 Related-Bug: 1806762 (cherry picked from commit 593e67e6ca429c6e6b54c5453a05c40a73abee85) --- keystone/common/policies/grant.py | 22 +++++-- .../protection/v3/test_system_assignments.py | 66 +++++++++++++++++++ 2 files changed, 84 insertions(+), 4 deletions(-) diff --git a/keystone/common/policies/grant.py b/keystone/common/policies/grant.py index d99db48748..eaa7269580 100644 --- a/keystone/common/policies/grant.py +++ b/keystone/common/policies/grant.py @@ -31,6 +31,14 @@ deprecated_revoke_system_grant_for_user = policy.DeprecatedRule( name=base.IDENTITY % 'revoke_system_grant_for_user', check_str=base.RULE_ADMIN_REQUIRED ) +deprecated_check_system_grant_for_group = policy.DeprecatedRule( + name=base.IDENTITY % 'check_system_grant_for_group', + check_str=base.RULE_ADMIN_REQUIRED +) +deprecated_list_system_grants_for_group = policy.DeprecatedRule( + name=base.IDENTITY % 'list_system_grants_for_group', + check_str=base.RULE_ADMIN_REQUIRED +) DEPRECATED_REASON = """ As of the Stein release, the system assignment API now understands default @@ -201,7 +209,7 @@ grant_policies = [ ), policy.DocumentedRuleDefault( name=base.IDENTITY % 'list_system_grants_for_group', - check_str=base.RULE_ADMIN_REQUIRED, + check_str=base.SYSTEM_READER, scope_types=['system'], description='List all grants a specific group has on the system.', operations=[ @@ -209,11 +217,14 @@ grant_policies = [ 'path': '/v3/system/groups/{group_id}/roles', 'method': ['HEAD', 'GET'] } - ] + ], + deprecated_rule=deprecated_list_system_grants_for_group, + deprecated_reason=DEPRECATED_REASON, + deprecated_since=versionutils.deprecated.STEIN ), policy.DocumentedRuleDefault( name=base.IDENTITY % 'check_system_grant_for_group', - check_str=base.RULE_ADMIN_REQUIRED, + check_str=base.SYSTEM_READER, scope_types=['system'], description='Check if a group has a role on the system.', operations=[ @@ -221,7 +232,10 @@ grant_policies = [ 'path': '/v3/system/groups/{group_id}/roles/{role_id}', 'method': ['HEAD', 'GET'] } - ] + ], + deprecated_rule=deprecated_check_system_grant_for_group, + deprecated_reason=DEPRECATED_REASON, + deprecated_since=versionutils.deprecated.STEIN ), policy.DocumentedRuleDefault( name=base.IDENTITY % 'create_system_grant_for_group', diff --git a/keystone/tests/unit/protection/v3/test_system_assignments.py b/keystone/tests/unit/protection/v3/test_system_assignments.py index 60c75a088f..57905fd5ef 100644 --- a/keystone/tests/unit/protection/v3/test_system_assignments.py +++ b/keystone/tests/unit/protection/v3/test_system_assignments.py @@ -65,6 +65,42 @@ class _SystemUserSystemAssignmentTests(object): expected_status_code=http_client.NO_CONTENT ) + def test_user_can_list_group_system_role_assignments(self): + group = PROVIDERS.identity_api.create_group( + unit.new_group_ref(CONF.identity.default_domain_id) + ) + + PROVIDERS.assignment_api.create_system_grant_for_group( + group['id'], self.bootstrapper.member_role_id + ) + + with self.test_client() as c: + r = c.get( + '/v3/system/groups/%s/roles' % group['id'], + headers=self.headers + ) + self.assertEqual(1, len(r.json['roles'])) + self.assertEqual( + self.bootstrapper.member_role_id, r.json['roles'][0]['id'] + ) + + def test_user_can_check_group_system_role_assignments(self): + group = PROVIDERS.identity_api.create_group( + unit.new_group_ref(CONF.identity.default_domain_id) + ) + + PROVIDERS.assignment_api.create_system_grant_for_group( + group['id'], self.bootstrapper.member_role_id + ) + + with self.test_client() as c: + c.get( + '/v3/system/groups/%s/roles/%s' % ( + group['id'], self.bootstrapper.member_role_id + ), headers=self.headers, + expected_status_code=http_client.NO_CONTENT + ) + class _SystemMemberAndReaderSystemAssignmentTests(object): @@ -98,6 +134,36 @@ class _SystemMemberAndReaderSystemAssignmentTests(object): expected_status_code=http_client.FORBIDDEN ) + def test_user_cannot_grant_group_system_assignment(self): + group = PROVIDERS.identity_api.create_group( + unit.new_group_ref(CONF.identity.default_domain_id) + ) + + with self.test_client() as c: + c.put( + '/v3/system/groups/%s/roles/%s' % ( + group['id'], self.bootstrapper.member_role_id + ), headers=self.headers, + expected_status_code=http_client.FORBIDDEN + ) + + def test_user_cannot_revoke_group_system_assignment(self): + group = PROVIDERS.identity_api.create_group( + unit.new_group_ref(CONF.identity.default_domain_id) + ) + + PROVIDERS.assignment_api.create_system_grant_for_group( + group['id'], self.bootstrapper.member_role_id + ) + + with self.test_client() as c: + c.delete( + '/v3/system/groups/%s/roles/%s' % ( + group['id'], self.bootstrapper.member_role_id + ), headers=self.headers, + expected_status_code=http_client.FORBIDDEN + ) + class _DomainAndProjectUserSystemAssignmentTests(object):