8000 RBAC should validate the service name for `content_type` · Issue #579 · ansible/django-ansible-base · GitHub
[go: up one dir, main page]

Skip to content

RBAC should validate the service name for content_type #579

Open

Description

@AlanCoding

The /role_definitions/ list accepts content_type as one of the fields in the format of "aap.organization". The intent is that the first prefix is the service name, for a cluster of multiple services stitched together by the JWT and resource_registry communication.

While that's the intent, the code just ignored it, test case:

def test_service_name_is_validated(admin_api_client):
    url = get_relative_url('roledefinition-list')
    response = admin_api_client.post(
        url,
        data={
            'name': 'Random custom role',
            'content_type': 'justsomerandomstuff.organization',
            'permissions': ['aap.view_organization', 'local.change_organization'],
        },
    )
    assert response.status_code == 400, response.data
    assert 'service name not valid for model organization' in str(response.data)

This fails with a 201 response_code.

We already had a requirement that the model name is unique within the permission registry. This is intended to change later, to be unique within the registry for a particular service... specifically to support awx.credential and eda.credential, which is a legitimate problem.

However, since we don't have any non-synced services now, model name is safely unique by itself right now, so writing the serializers, I just stopped where I was. This is a TODO for later, as we develop a permissions-provider functionality.

Activity

  1. added
    bug
    on Aug 21, 2024
  2. aap-platform-services-cicd-bot-sa commented on Sep 3, 2026

    @aap-platform-services-cicd-bot-sa
    Collaborator

    A fix for this has been submitted in PR #1124. The fix adds a ContentTypeSlugField subclass of SlugRelatedField in ansible_base/rbac/api/serializers.py that catches the generic "object does not exist" validation error, checks whether the model portion of the slug exists under any valid service, and raises the specific error message service name not valid for model {model_name} when the service prefix is unrecognized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app:rbacbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0