You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This section tells how to use the API endpoints as a client;
4
-
what requests to make and how to build request data.
3
+
This section explains how to use the RBAC API endpoints to manage permissions. The API follows a clear hierarchy that reflects the system architecture.
5
4
6
-
You need a server running a Django project that uses this system.
7
-
Use test_app in this repo for a demo, see `test_app/README.md` for bootstrap.
8
-
The server runs at http://127.0.0.1:8000, and links within that will be referenced here.
9
-
Default password for admin user is "admin".
5
+
### Prerequisites
10
6
11
-
### Create Custom Role (Definition)
7
+
You need a server running a Django project that uses DAB RBAC.
8
+
Use test_app in this repo for a demo (see `test_app/README.md` for setup).
9
+
The server runs at http://127.0.0.1:8000, and examples reference this base URL.
10
+
Default admin password is "admin".
12
11
13
-
After logging in to test_app/, you can visit this endpoint to get the role definition API.
12
+
### API Workflow Overview
14
13
15
-
http://127.0.0.1:8000/api/v1/role_definitions/
14
+
The RBAC API follows standard REST practices where models have relational dependencies. The typical order for establishing permissions:
16
15
17
-
Perform an OPTIONS request, and you will find this gives choices for `content_type`.
18
-
Out of the choices a single `content_type` needs to be chosen for a role definition.
16
+
1.**Types** (`/api/v1/role_metadata/`) - Read-only, managed by app developers
17
+
2.**Permissions** - Read-only, created when models are registered
18
+
3.**Role Definitions** (`/api/v1/role_definitions/`) - Managed and custom roles
19
+
4.**Role Assignments** - User assignments (`/api/v1/role_user_assignments/`) and team assignments (`/api/v1/role_team_assignments/`)
19
20
20
-
Multiple permissions can be selected, and are accepted in the form of a list.
21
-
To find out what permissions are valid for a role definition for a given `content_type`
22
-
make a GET to `/api/v1/role_metadata/` and look up the type under "allowed_permissions".
21
+
Users interact primarily with steps 3 and 4, while steps 1 and 2 are controlled by the application configuration.
23
22
24
-
A POST to this endpoint will create a new role definition, example data:
23
+
## Step 1: Understanding Available Types and Permissions
24
+
25
+
### View Available Content Types
26
+
27
+
Get the available content types and their permissions:
28
+
29
+
```
30
+
GET /api/v1/role_metadata/
31
+
```
32
+
33
+
This returns read-only information configured by app developers:
34
+
- Available content types (e.g., "aap.inventory", "shared.organization")
35
+
- Permissions allowed for each content type
36
+
- No user interaction required with this data
37
+
38
+
## Step 2: Creating Role Definitions
39
+
40
+
### Create a Custom Role Definition
41
+
42
+
```
43
+
POST /api/v1/role_definitions/
44
+
```
45
+
46
+
Example request body:
25
47
26
48
```json
27
49
{
28
50
"permissions": ["view_inventory"],
29
51
"content_type": "aap.inventory",
30
52
"name": "View a single inventory",
31
-
"description": "custom role"
53
+
"description": "Custom role for inventory viewing"
32
54
}
33
55
```
34
56
35
-
Name can be any string that's not blank. Description can be any string.
57
+
Required fields:
58
+
-`permissions`: List of permission codenames (from step 1)
59
+
-`content_type`: Content type string (from step 1)
60
+
-`name`: Display name for the role definition
61
+
62
+
Optional fields:
63
+
-`description`: Additional context about the role definition
64
+
65
+
### Managed vs Custom Role Definitions
66
+
67
+
-**Managed roles**: Created by app developers, cannot be modified via API
68
+
-**Custom roles**: Created by users, fully manageable via API
36
69
37
-
### Assigning a User a Role to an Object
70
+
##Step 3: User Role Assignments
38
71
39
-
Select a role definition from `/api/v1/role_definitions/`, use the id as `role_definition`
40
-
and a user from `/api/v1/users/` and use the id as `user`.
41
-
Given the type of the role definition, check the available objects of that type,
42
-
in this case `/api/v1/inventories/` and obtain the desired id, this will become `object_id`.
72
+
### Assign Role Definition to User for Object
73
+
74
+
Once you have a role definition, assign it to a user for a specific object:
75
+
76
+
```
77
+
POST /api/v1/role_user_assignments/
78
+
```
43
79
44
-
With all 3 ids ready, POST to http://127.0.0.1:8000/api/v1/role_user_assignments/
80
+
Example request body:
45
81
46
82
```json
47
83
{
@@ -51,26 +87,39 @@ With all 3 ids ready, POST to http://127.0.0.1:8000/api/v1/role_user_assignments
51
87
}
52
88
```
53
89
54
-
This will give user id=3 view permission to a single inventory id=3, assuming the role definition
55
-
referenced is what was created in the last section.
90
+
Required fields:
91
+
-`role_definition`: ID from `/api/v1/role_definitions/`
92
+
-`user`: ID from `/api/v1/users/`
93
+
-`object_id`: ID of the target object (e.g., from `/api/v1/inventories/`)
56
94
57
-
### Assigning a User as a Member of a Team
95
+
This grants the user the role definition's permissions for only the specified object.
58
96
59
-
While this is possible with the RBAC API, it is not covered here,
60
-
because it may come from an external source.
97
+
### Assign Role Definition to User Globally
61
98
62
-
The "member_team" permission may later be prohibited from use in custom role definitions.
99
+
For system-wide permissions, omit the `object_id`:
63
100
64
-
### Assigning a Team a Role to an Object
101
+
```json
102
+
{
103
+
"role_definition": 5,
104
+
"user": 3
105
+
}
106
+
```
65
107
66
-
If you used the test_app bootstrap script, then you will find the user "angry_spud"
67
-
is a member of the "awx_devs" team.
108
+
The role definition must have `content_type: null` for global assignments.
First, users must be members of teams. Team membership grants the "member_team" permission and automatically inherits all permissions assigned to the team.
115
+
116
+
### Assign Role Definition to Team
117
+
118
+
```
119
+
POST /api/v1/role_team_assignments/
120
+
```
72
121
73
-
with data
122
+
Example request body:
74
123
75
124
```json
76
125
{
@@ -80,36 +129,58 @@ with data
80
129
}
81
130
```
82
131
83
-
This has a similar effect to user assignments, but in this case will give
84
-
permissions to all users of a team
132
+
This grants the role definition's permissions to all members of the team for the specified object.
133
+
134
+
## Management Operations
135
+
136
+
### View Existing Assignments
85
137
86
-
### Viewing Assignments
138
+
List assignments for a specific object:
87
139
88
-
For the single inventory mentioned above, it is possible to view the existing permission
89
-
assignments directly to that object.
140
+
```
141
+
GET /api/v1/role_user_assignments/?object_id=3&content_type__model=inventory
142
+
GET /api/v1/role_team_assignments/?object_id=3&content_type__model=inventory
0 commit comments