Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@fosterseth
Copy link
Member

@fosterseth fosterseth commented Jun 25, 2024

SUMMARY

AAP-24919

requires ansible/django-ansible-base#490

Utilizes the validate_role_assignment callback from dab to prevent granting credential access to a user of another organization.

This prevention was already being handled correctly for the RoleUsersList view, but not through the newer
role assignment endpoints.

This change is for assignments that are made through the role_user_assignments and role_team_assignments endpoints.

ISSUE TYPE
  • Bug, Docs Fix or other nominal change
COMPONENT NAME
  • API


def validate_role_assignment(self, actor, role_definition):
if isinstance(actor, User):
if actor.is_superuser or self.organization in actor.organizations:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actor.organizations wasn't correct, and it was my fault. #15298

Copy link
Member

@AlanCoding AlanCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a unit test for this. Considering it now has 2 dependent patches, I would not feel comfortable merging without that as added verification. Otherwise we should be good.

@fosterseth fosterseth requested a review from AlanCoding June 27, 2024 02:44
resp = post(url=url, data={"user": rando.id, "role_definition": rd.id, "object_id": credential.id}, user=admin_user, expect=400)
assert "You cannot grant credential access to a User not in the credentials' organization" in str(resp.data)

# can assign credential to superuser
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never really thought about this case, also don't think I care either way.

@fosterseth
Copy link
Member Author

CI should be re-ran once ansible/django-ansible-base#490 is merged

@AlanCoding AlanCoding force-pushed the callback_for_role_assignment branch from d861cfc to 4076208 Compare June 27, 2024 12:24
@AlanCoding
Copy link
Member

I previously rebased this (using github). Checks failed due to stale image. I rebuilt the image and restarted the check (without modifying patch) just now. I am expecting a pass, but we'll see.

@AlanCoding
Copy link
Member

I know the image has rebuilt, but locally, I pulled it and got a version from 19 hours ago (which is too old) and confirmed it has this commit:

ansible/django-ansible-base@8eab0c0

And if that's what the checks are using (which it could be) then that would be why it's failing.

@AlanCoding AlanCoding force-pushed the callback_for_role_assignment branch from 4076208 to 0c2f5a8 Compare June 28, 2024 15:13
@AlanCoding
Copy link
Member

#15308 was merged to freshen up the images and address the issue with CI here.

Utilizes the `validate_role_assignment` callback
from dab (see dab PR ansible#490) to prevent granting credential
access to a user of another organization.

This logic will work for role_user_assignments
and role_team_assignments endpoints.

Signed-off-by: Seth Foster <[email protected]>
Signed-off-by: Seth Foster <[email protected]>
Signed-off-by: Seth Foster <[email protected]>
Signed-off-by: Seth Foster <[email protected]>
@fosterseth fosterseth force-pushed the callback_for_role_assignment branch from 0c2f5a8 to 71bba17 Compare July 1, 2024 17:54
Signed-off-by: Seth Foster <[email protected]>
Signed-off-by: Seth Foster <[email protected]>
@AlanCoding
Copy link
Member

With the latest test failure, I think we're seeing a conflict of expectations with what I did in #15298

What I merged there considered indirect "member" permission to an organization. We have faced this in a couple of circumstances, and according to the logic of indirect access, the superuser has "member" permission to all organizations. However (and I hit this in other places as well), people are confused about listing superuser as a member of all organizations.

Consulting the prior expectations, I think it would give a 400 even if the user in question was a superuser (who was not a direct member of the organization).

@AlanCoding
Copy link
Member

Link related issue #15296 (comment)

@AlanCoding
Copy link
Member

diff --git a/awx/main/tests/functional/dab_rbac/test_dab_rbac_api.py b/awx/main/tests/functional/dab_rbac/test_dab_rbac_api.py
index c54f5677cb..5bc4244fa3 100644
--- a/awx/main/tests/functional/dab_rbac/test_dab_rbac_api.py
+++ b/awx/main/tests/functional/dab_rbac/test_dab_rbac_api.py
@@ -134,9 +134,8 @@ def test_assign_credential_to_user_of_another_org(setup_managed_roles, credentia
     assert "You cannot grant credential access to a User not in the credentials' organization" in str(resp.data)
 
     # can assign credential to superuser
-    rando.super_user = True
+    rando.is_superuser = True
     rando.save()
-    assert organization not in rando.organizations
     post(url=url, data={"user": rando.id, "role_definition": rd.id, "object_id": credential.id}, user=admin_user, expect=201)
 
     # can assign credential to org_member

This brings it from failing to passing. We are pretty well agreed that this is acceptable, and is the same as before.

Signed-off-by: Seth Foster <[email protected]>
@fosterseth fosterseth enabled auto-merge (squash) July 2, 2024 21:01
@fosterseth fosterseth merged commit 94e5795 into ansible:devel Jul 2, 2024
djyasin pushed a commit to djyasin/awx that referenced this pull request Sep 16, 2024
Utilizes the `validate_role_assignment` callback
from dab (see dab PR ansible#490) to prevent granting credential
access to a user of another organization.

This logic will work for role_user_assignments
and role_team_assignments endpoints.

Signed-off-by: Seth Foster <[email protected]>
djyasin pushed a commit to djyasin/awx that referenced this pull request Nov 11, 2024
Utilizes the `validate_role_assignment` callback
from dab (see dab PR ansible#490) to prevent granting credential
access to a user of another organization.

This logic will work for role_user_assignments
and role_team_assignments endpoints.

Signed-off-by: Seth Foster <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants