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

Bring WFJT job access to parity with UnifiedJobAccess #15344

Draft
wants to merge 3 commits into
base: devel
Choose a base branch
from
Draft
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
5 changes: 2 additions & 3 deletions awx/main/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -2175,7 +2175,7 @@ class WorkflowJobAccess(BaseAccess):
def filtered_queryset(self):
return WorkflowJob.objects.filter(
Q(unified_job_template__in=UnifiedJobTemplate.accessible_pk_qs(self.user, 'read_role'))
| Q(organization__in=Organization.objects.filter(Q(admin_role__members=self.user)), is_bulk_job=True)
| Q(organization__in=Organization.accessible_pk_qs(self.user, 'auditor_role'))
)

def can_read(self, obj):
Expand Down Expand Up @@ -2573,12 +2573,11 @@ class UnifiedJobAccess(BaseAccess):

def filtered_queryset(self):
inv_pk_qs = Inventory._accessible_pk_qs(Inventory, self.user, 'read_role')
org_auditor_qs = Organization.objects.filter(Q(admin_role__members=self.user) | Q(auditor_role__members=self.user))
qs = self.model.objects.filter(
Q(unified_job_template_id__in=UnifiedJobTemplate.accessible_pk_qs(self.user, 'read_role'))
| Q(inventoryupdate__inventory_source__inventory__id__in=inv_pk_qs)
| Q(adhoccommand__inventory__id__in=inv_pk_qs)
| Q(organization__in=org_auditor_qs)
| Q(organization__in=Organization.accessible_pk_qs(self.user, 'auditor_role'))
)
return qs

Expand Down
11 changes: 11 additions & 0 deletions awx/main/tests/functional/dab_rbac/test_translation_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@
assert rd.created_by is None


@pytest.mark.django_db
def test_organization_admin_has_audit(setup_managed_roles):
"""This formalizes a behavior change from old to new RBAC system

Previously, the auditor_role did not list admin_role as a parent
this made various queries hard to deal with, requiring adding 2 conditions
The new system should explicitly list the auditor permission in org admin role"""
rd = RoleDefinition.objects.get(name='Organization Admin')
assert 'audit_organization' in rd.permissions.values_list('codename', flat=True)

Check warning on line 117 in awx/main/tests/functional/dab_rbac/test_translation_layer.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tests/functional/dab_rbac/test_translation_layer.py#L116-L117

Added lines #L116 - L117 were not covered by tests


@pytest.mark.django_db
def test_organization_level_permissions(organization, inventory, setup_managed_roles):
u1 = User.objects.create(username='alice')
Expand Down
25 changes: 25 additions & 0 deletions awx/main/tests/functional/test_rbac_workflow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from awx.main.access import (
UnifiedJobAccess,
WorkflowJobTemplateAccess,
WorkflowJobTemplateNodeAccess,
WorkflowJobAccess,
Expand Down Expand Up @@ -245,6 +246,30 @@
inventory.use_role.members.add(rando)
assert WorkflowJobAccess(rando).can_start(workflow_job)

@pytest.mark.parametrize('org_role', ['admin_role', 'auditor_role'])
def test_workflow_job_org_audit_access(self, workflow_job_template, rando, org_role):
assert workflow_job_template.organization # sanity
workflow_job = workflow_job_template.create_unified_job()
assert workflow_job.organization # sanity

Check warning on line 253 in awx/main/tests/functional/test_rbac_workflow.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tests/functional/test_rbac_workflow.py#L251-L253

Added lines #L251 - L253 were not covered by tests

assert not UnifiedJobAccess(rando).can_read(workflow_job)
assert not WorkflowJobAccess(rando).can_read(workflow_job)
assert workflow_job not in WorkflowJobAccess(rando).filtered_queryset()

Check warning on line 257 in awx/main/tests/functional/test_rbac_workflow.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tests/functional/test_rbac_workflow.py#L255-L257

Added lines #L255 - L257 were not covered by tests

org = workflow_job.organization
role = getattr(org, org_role)
role.members.add(rando)

Check warning on line 261 in awx/main/tests/functional/test_rbac_workflow.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tests/functional/test_rbac_workflow.py#L259-L261

Added lines #L259 - L261 were not covered by tests

assert UnifiedJobAccess(rando).can_read(workflow_job)
assert WorkflowJobAccess(rando).can_read(workflow_job)
assert workflow_job in WorkflowJobAccess(rando).filtered_queryset()

Check warning on line 265 in awx/main/tests/functional/test_rbac_workflow.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tests/functional/test_rbac_workflow.py#L263-L265

Added lines #L263 - L265 were not covered by tests

# Organization-level permissions should persist after deleting the WFJT
workflow_job_template.delete()
assert UnifiedJobAccess(rando).can_read(workflow_job)
assert WorkflowJobAccess(rando).can_read(workflow_job)
assert workflow_job in WorkflowJobAccess(rando).filtered_queryset()

Check warning on line 271 in awx/main/tests/functional/test_rbac_workflow.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tests/functional/test_rbac_workflow.py#L268-L271

Added lines #L268 - L271 were not covered by tests


@pytest.mark.django_db
class TestWFJTCopyAccess:
Expand Down
Loading