Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug where cred org permission was not checked #4483

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions awx/main/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,15 +1168,20 @@ def can_add(self, data):
return True
if data and data.get('user', None):
user_obj = get_object_from_data('user', User, data)
return bool(self.user == user_obj or UserAccess(self.user).can_admin(user_obj, None, check_setting=False))
if not bool(self.user == user_obj or UserAccess(self.user).can_admin(user_obj, None, check_setting=False)):
return False
if data and data.get('team', None):
team_obj = get_object_from_data('team', Team, data)
return check_user_access(self.user, Team, 'change', team_obj, None)
if not check_user_access(self.user, Team, 'change', team_obj, None):
return False
if data and data.get('organization', None):
organization_obj = get_object_from_data('organization', Organization, data)
return any([check_user_access(self.user, Organization, 'change', organization_obj, None),
self.user in organization_obj.credential_admin_role])
return False
if not any([check_user_access(self.user, Organization, 'change', organization_obj, None),
self.user in organization_obj.credential_admin_role]):
return False
if not any(data.get(key, None) for key in ('user', 'team', 'organization')):
return False # you have to provide 1 owner field
return True

@check_superuser
def can_use(self, obj):
Expand Down
13 changes: 13 additions & 0 deletions awx/main/tests/functional/test_rbac_credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ def test_org_credential_access_admin(role_name, alice, org_credential):
'organization': org_credential.organization.pk})


@pytest.mark.django_db
def test_org_and_user_credential_access(alice, organization):
"""Address specific bug where any user could make an org credential
in another org without any permissions to that org
"""
# Owner is both user and org, but org permission should still be checked
assert not CredentialAccess(alice).can_add({
'name': 'New credential.',
'user': alice.pk,
'organization': organization.pk
})


@pytest.mark.django_db
def test_org_credential_access_member(alice, org_credential):
org_credential.admin_role.members.add(alice)
Expand Down