Remove legacy remove_role_from_user_and_project
The remove_role_from_user_and_project method is a legacy V2 API remnant with no production callers. All API-driven role unassignment goes through delete_grant. Keeping both methods creates a confusing parallel code path with subtly different behavior (different exceptions, different side effects around application credential cleanup). Remove the method from the assignment manager, SQL backend, and abstract driver interface. Update all tests to use delete_grant instead. Generated-By: claude-opus-4-6 (OpenCode) Signed-off-by: Boris Bobrov <b.bobrov@sap.com> Change-Id: I74a09cc298bdc38e7361412f89b98a0de9200b95
This commit is contained in:
8 files changed
+24
-154
No files matched your search
@@ -34,15 +34,6 @@ class AssignmentDriverBase(metaclass=abc.ABCMeta):
|
||||
"""
|
||||
raise exception.NotImplemented() # pragma: no cover
|
||||
|
||||
@abc.abstractmethod
|
||||
def remove_role_from_user_and_project(self, user_id, project_id, role_id):
|
||||
"""Remove a role from a user within given project.
|
||||
|
||||
:raises keystone.exception.RoleNotFound: If the role doesn't exist.
|
||||
|
||||
"""
|
||||
raise exception.NotImplemented() # pragma: no cover
|
||||
|
||||
# assignment/grant crud
|
||||
|
||||
@abc.abstractmethod
|
||||
|
||||
@@ -183,20 +183,6 @@ class Assignment(base.AssignmentDriverBase):
|
||||
msg = f'User {user_id} already has role {role_id} in tenant {project_id}'
|
||||
raise exception.Conflict(type='role grant', details=msg)
|
||||
|
||||
def remove_role_from_user_and_project(self, user_id, project_id, role_id):
|
||||
with sql.session_for_write() as session:
|
||||
q = session.query(RoleAssignment)
|
||||
q = q.filter_by(actor_id=user_id)
|
||||
q = q.filter_by(target_id=project_id)
|
||||
q = q.filter_by(role_id=role_id)
|
||||
if q.delete() == 0:
|
||||
raise exception.RoleNotFound(
|
||||
message=_(
|
||||
'Cannot remove role that has not been granted, %s'
|
||||
)
|
||||
% role_id
|
||||
)
|
||||
|
||||
def _get_user_assignment_types(self):
|
||||
return [AssignmentType.USER_PROJECT, AssignmentType.USER_DOMAIN]
|
||||
|
||||
|
||||
@@ -278,38 +278,6 @@ class Manager(manager.Manager):
|
||||
)
|
||||
return PROVIDERS.resource_api.list_projects_from_ids(project_ids)
|
||||
|
||||
@notifications.role_assignment('deleted')
|
||||
def _remove_role_from_user_and_project_adapter(
|
||||
self,
|
||||
role_id,
|
||||
user_id=None,
|
||||
group_id=None,
|
||||
domain_id=None,
|
||||
project_id=None,
|
||||
inherited_to_projects=False,
|
||||
context=None,
|
||||
):
|
||||
# The parameters for this method must match the parameters for
|
||||
# delete_grant so that the notifications.role_assignment decorator
|
||||
# will work.
|
||||
|
||||
self.driver.remove_role_from_user_and_project(
|
||||
user_id, project_id, role_id
|
||||
)
|
||||
payload = {'user_id': user_id, 'project_id': project_id}
|
||||
notifications.Audit.internal(
|
||||
notifications.REMOVE_APP_CREDS_FOR_USER, payload
|
||||
)
|
||||
self._invalidate_token_cache(
|
||||
role_id, group_id, user_id, project_id, domain_id
|
||||
)
|
||||
|
||||
def remove_role_from_user_and_project(self, user_id, project_id, role_id):
|
||||
self._remove_role_from_user_and_project_adapter(
|
||||
role_id, user_id=user_id, project_id=project_id
|
||||
)
|
||||
COMPUTED_ASSIGNMENTS_REGION.invalidate()
|
||||
|
||||
def _invalidate_token_cache(
|
||||
self, role_id, group_id, user_id, project_id, domain_id
|
||||
):
|
||||
|
||||
@@ -274,68 +274,6 @@ class ApplicationCredentialTests:
|
||||
app_cred_2['id'],
|
||||
)
|
||||
|
||||
def test_removing_user_from_project_deletes_application_credentials(self):
|
||||
app_cred_proj_A_1 = self._new_app_cred_data(
|
||||
self.user_foo['id'], project_id=self.project_bar['id'], name='app1'
|
||||
)
|
||||
app_cred_proj_A_2 = self._new_app_cred_data(
|
||||
self.user_foo['id'], project_id=self.project_bar['id'], name='app2'
|
||||
)
|
||||
app_cred_proj_B = self._new_app_cred_data(
|
||||
self.user_foo['id'], project_id=self.project_baz['id'], name='app3'
|
||||
)
|
||||
PROVIDERS.assignment_api.add_role_to_user_and_project(
|
||||
project_id=self.project_baz['id'],
|
||||
user_id=self.user_foo['id'],
|
||||
role_id=self.role__member_['id'],
|
||||
)
|
||||
self.app_cred_api.create_application_credential(app_cred_proj_A_1)
|
||||
self.app_cred_api.create_application_credential(app_cred_proj_A_2)
|
||||
self.app_cred_api.create_application_credential(app_cred_proj_B)
|
||||
self.assertIn(app_cred_proj_A_1['id'], self._list_ids(self.user_foo))
|
||||
self.assertIn(app_cred_proj_A_2['id'], self._list_ids(self.user_foo))
|
||||
self.assertIn(app_cred_proj_B['id'], self._list_ids(self.user_foo))
|
||||
|
||||
# cache the information
|
||||
self.app_cred_api.get_application_credential(app_cred_proj_A_1['id'])
|
||||
self.app_cred_api.get_application_credential(app_cred_proj_A_2['id'])
|
||||
self.app_cred_api.get_application_credential(app_cred_proj_B['id'])
|
||||
|
||||
# This should trigger a notification which should invoke a callback in
|
||||
# the application credential Manager to cleanup all of user_foo's
|
||||
# application credentials on project bar.
|
||||
PROVIDERS.assignment_api.remove_role_from_user_and_project(
|
||||
user_id=self.user_foo['id'],
|
||||
project_id=self.project_bar['id'],
|
||||
role_id=self.role__member_['id'],
|
||||
)
|
||||
self.assertNotIn(
|
||||
app_cred_proj_A_1['id'], self._list_ids(self.user_foo)
|
||||
)
|
||||
self.assertNotIn(
|
||||
app_cred_proj_A_2['id'], self._list_ids(self.user_foo)
|
||||
)
|
||||
self.assertIn(app_cred_proj_B['id'], self._list_ids(self.user_foo))
|
||||
|
||||
# the cache information has been invalidated only for the deleted
|
||||
# application credential.
|
||||
self.assertRaises(
|
||||
exception.ApplicationCredentialNotFound,
|
||||
self.app_cred_api.get_application_credential,
|
||||
app_cred_proj_A_1['id'],
|
||||
)
|
||||
self.assertRaises(
|
||||
exception.ApplicationCredentialNotFound,
|
||||
self.app_cred_api.get_application_credential,
|
||||
app_cred_proj_A_2['id'],
|
||||
)
|
||||
self.assertEqual(
|
||||
app_cred_proj_B['id'],
|
||||
self.app_cred_api.get_application_credential(
|
||||
app_cred_proj_B['id']
|
||||
)['id'],
|
||||
)
|
||||
|
||||
def test_authenticate(self):
|
||||
app_cred = self._new_app_cred_data(
|
||||
self.user_foo['id'], project_id=self.project_bar['id']
|
||||
|
||||
@@ -492,10 +492,10 @@ class AssignmentTests(AssignmentTestHelperMixin):
|
||||
)
|
||||
self.assertIn(self.user_two['id'], user_ids)
|
||||
|
||||
PROVIDERS.assignment_api.remove_role_from_user_and_project(
|
||||
project_id=self.project_bar['id'],
|
||||
PROVIDERS.assignment_api.delete_grant(
|
||||
self.role_other['id'],
|
||||
user_id=self.user_two['id'],
|
||||
role_id=self.role_other['id'],
|
||||
project_id=self.project_bar['id'],
|
||||
)
|
||||
|
||||
user_ids = PROVIDERS.assignment_api.list_user_ids_for_project(
|
||||
@@ -507,11 +507,11 @@ class AssignmentTests(AssignmentTestHelperMixin):
|
||||
# Expect failure if attempt to remove a role that was never assigned to
|
||||
# the user.
|
||||
self.assertRaises(
|
||||
exception.RoleNotFound,
|
||||
PROVIDERS.assignment_api.remove_role_from_user_and_project,
|
||||
project_id=self.project_bar['id'],
|
||||
exception.RoleAssignmentNotFound,
|
||||
PROVIDERS.assignment_api.delete_grant,
|
||||
self.role_other['id'],
|
||||
user_id=self.user_two['id'],
|
||||
role_id=self.role_other['id'],
|
||||
project_id=self.project_bar['id'],
|
||||
)
|
||||
|
||||
def test_list_user_ids_for_project(self):
|
||||
@@ -1004,10 +1004,10 @@ class AssignmentTests(AssignmentTestHelperMixin):
|
||||
self.project_bar['id'],
|
||||
default_fixtures.MEMBER_ROLE_ID,
|
||||
)
|
||||
PROVIDERS.assignment_api.remove_role_from_user_and_project(
|
||||
self.user_foo['id'],
|
||||
self.project_bar['id'],
|
||||
PROVIDERS.assignment_api.delete_grant(
|
||||
default_fixtures.MEMBER_ROLE_ID,
|
||||
user_id=self.user_foo['id'],
|
||||
project_id=self.project_bar['id'],
|
||||
)
|
||||
roles_ref = PROVIDERS.assignment_api.get_roles_for_user_and_project(
|
||||
self.user_foo['id'], self.project_bar['id']
|
||||
@@ -1015,10 +1015,10 @@ class AssignmentTests(AssignmentTestHelperMixin):
|
||||
self.assertNotIn(default_fixtures.MEMBER_ROLE_ID, roles_ref)
|
||||
self.assertRaises(
|
||||
exception.NotFound,
|
||||
PROVIDERS.assignment_api.remove_role_from_user_and_project,
|
||||
self.user_foo['id'],
|
||||
self.project_bar['id'],
|
||||
PROVIDERS.assignment_api.delete_grant,
|
||||
default_fixtures.MEMBER_ROLE_ID,
|
||||
user_id=self.user_foo['id'],
|
||||
project_id=self.project_bar['id'],
|
||||
)
|
||||
|
||||
def test_get_role_grant_by_user_and_project(self):
|
||||
|
||||
@@ -1747,23 +1747,6 @@ class CadfNotificationsWrapperTestCase(test_v3.RestfulTestCase):
|
||||
|
||||
self._assert_event(self.role_id, project=project_id, user=self.user_id)
|
||||
|
||||
def test_remove_role_from_user_and_project(self):
|
||||
# A notification is sent when remove_role_from_user_and_project is
|
||||
# called on the assignment manager.
|
||||
|
||||
PROVIDERS.assignment_api.remove_role_from_user_and_project(
|
||||
self.user_id, self.project_id, self.role_id
|
||||
)
|
||||
|
||||
self.assertTrue(self._notifications)
|
||||
note = self._notifications[-1]
|
||||
self.assertEqual('deleted.role_assignment', note['action'])
|
||||
self.assertTrue(note['send_notification_called'])
|
||||
|
||||
self._assert_event(
|
||||
self.role_id, project=self.project_id, user=self.user_id
|
||||
)
|
||||
|
||||
|
||||
class TestCallbackRegistration(unit.BaseTestCase):
|
||||
def setUp(self):
|
||||
|
||||
@@ -5494,8 +5494,8 @@ class TestTrustChain(test_v3.RestfulTestCase):
|
||||
def test_trustor_roles_revoked(self):
|
||||
self.assert_user_authenticate(self.user_list[0])
|
||||
|
||||
PROVIDERS.assignment_api.remove_role_from_user_and_project(
|
||||
self.user_id, self.project_id, self.role_id
|
||||
PROVIDERS.assignment_api.delete_grant(
|
||||
self.role_id, user_id=self.user_id, project_id=self.project_id
|
||||
)
|
||||
|
||||
# Verify that users are not allowed to authenticate with trust
|
||||
@@ -6420,13 +6420,17 @@ class ApplicationCredentialAuth(test_v3.RestfulTestCase):
|
||||
app_cred_ref = self.app_cred_api.create_application_credential(
|
||||
app_cred
|
||||
)
|
||||
PROVIDERS.assignment_api.remove_role_from_user_and_project(
|
||||
self.user['id'], self.project['id'], self.role_id
|
||||
PROVIDERS.assignment_api.delete_grant(
|
||||
self.role_id,
|
||||
user_id=self.user['id'],
|
||||
project_id=self.project['id'],
|
||||
)
|
||||
auth_data = self.build_authentication_request(
|
||||
app_cred_id=app_cred_ref['id'], secret=app_cred_ref['secret']
|
||||
)
|
||||
self.v3_create_token(auth_data, expected_status=http.client.NOT_FOUND)
|
||||
self.v3_create_token(
|
||||
auth_data, expected_status=http.client.UNAUTHORIZED
|
||||
)
|
||||
|
||||
def test_application_credential_through_group_membership(self):
|
||||
user1 = unit.create_user(
|
||||
|
||||
@@ -975,8 +975,8 @@ class MaliciousOAuth1Tests(OAuth1Tests):
|
||||
credentials = _urllib_parse_qs_text_keys(content.result)
|
||||
request_key = credentials['oauth_token'][0]
|
||||
|
||||
PROVIDERS.assignment_api.remove_role_from_user_and_project(
|
||||
self.user_id, self.project_id, new_role['id']
|
||||
PROVIDERS.assignment_api.delete_grant(
|
||||
new_role['id'], user_id=self.user_id, project_id=self.project_id
|
||||
)
|
||||
url = self._authorize_request_token(request_key)
|
||||
body = {'roles': [{'id': new_role['id']}]}
|
||||
|
||||
Reference in new issue
Block a user