Skip to content

Commit 335c022

Browse files
committed
RHIDP-3975 Managing authorization using the REST API
Signed-off-by: Fabrice Flore-Thébault <[email protected]>
1 parent 9c33568 commit 335c022

9 files changed

+206
-174
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[id='configuring-authorization-in-rhdh']
2+
= Configuring authorization in {product} by using the REST API
3+
4+
To automate the maintenance of {product} permission policies and roles, you can use {product-short} role-based access control (RBAC) REST API.
5+
6+
You can perform the following actions with the REST API:
7+
8+
* Retrieve information about:
9+
** All permission policies
10+
** Specific permission policies
11+
** Specific roles
12+
** Static plugins permission policies
13+
* Create, update, or delete:
14+
** Permission policy
15+
** Role
16+
17+
18+
include::modules/authorization/proc-sending-request-to-the-rbac-rest-api-by-using-curl.adoc[leveloffset=+1]
19+
20+
21+
include::modules/authorization/proc-sending-request-to-the-rbac-rest-api-by-using-a-rest-client.adoc[leveloffset=+1]
22+
23+
24+
include::modules/authorization/ref-rbac-rest-api-endpoints.adoc[leveloffset=+1]
25+
26+
27+
include::modules/authorization/con-permission-policy-and-role-source.adoc[leveloffset=+1]

assemblies/assembly-configuring-authorization-in-rhdh.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ include::modules/authorization/con-user-stats-rhdh.adoc[leveloffset=+1]
6262
include::modules/authorization/proc-download-user-stats-rhdh.adoc[leveloffset=+2]
6363

6464

65-
include::modules/authorization/con-rbac-rest-api.adoc[leveloffset=+1]
65+
include::modules/authorization/con-permission-policy-and-role-source.adoc[leveloffset=+1]
6666

6767

6868
include::modules/authorization/proc-rbac-send-request-rbac-rest-api.adoc[leveloffset=+2]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[id='con-permission-policy-and-role-source']
2+
= Permission policy and role source
3+
4+
Each permission policy and role created using the RBAC plugin is associated with a source to maintain data consistency within the plugin.
5+
You can manipulate permission policies and roles based on the following designated source information:
6+
7+
* CSV file
8+
* Configuration file
9+
* REST API
10+
* Legacy
11+
12+
Managing roles and permission policies originating from CSV files and REST API involves straightforward modification based on their initial source information.
13+
14+
The Configuration file pertains to the default `role:default/rbac_admin` role provided by the RBAC plugin.
15+
The default role has limited permissions to create, read, update, and delete permission policies or roles, and to read catalog entities.
16+
17+
[NOTE]
18+
====
19+
In case the default permissions are insufficient for your administrative requirements, you can create a custom admin role with required permission policies.
20+
====
21+
22+
The legacy source applies to policies and roles defined before RBAC backend plugin version `2.1.3`, and is the least restrictive among the source location options.
23+
You must update the permissions and roles in legacy source to use either REST API or the CSV file sources.
24+
25+
You can use the `GET` requests to query roles and policies and determine the source information, if required.
26+

modules/authorization/con-rbac-rest-api.adoc

Lines changed: 0 additions & 119 deletions
This file was deleted.

modules/authorization/proc-enabling-the-rbac-plugin.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[id='enabling-and-giving-access-to-rbac']
1+
[id='from the web console in a browser.]
22
= Enabling and giving access to the Role-Based Access Control (RBAC) feature
33

44
The Role-Based Access Control (RBAC) feature is disabled by default.

modules/authorization/proc-rbac-send-request-rbac-rest-api.adoc

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[id='proc-rbac-sending-requests-to-the-rbac-rest-api-by-using-a-rest-client_{context}']
2+
= Sending requests to the RBAC REST API by using a REST client
3+
4+
You can send RBAC REST API requests using any REST client.
5+
6+
.Prerequisites
7+
* xref:enabling-and-giving-access-to-rbac[You have access to the RBAC feature].
8+
9+
.Procedure
10+
include::snip-finding-bearer-token.adoc[]
11+
12+
. In your REST client, run a command with the following parameters and review the response:
13+
+
14+
--
15+
Authorization::
16+
Enter your saved authorization token.
17+
18+
HTTP method::
19+
Enter the HTTP method for your xref:ref-rbac-rest-api-endpoints_{context}[API endpoint].
20+
21+
* `GET`: To retrieve specified information from a specified resource endpoint.
22+
* `POST`: To create or update a resource.
23+
* `PUT`: To update a resource.
24+
* `DELETE`: To delete a resource.
25+
26+
URL::
27+
Enter your {product-short} URL and xref:ref-rbac-rest-api-endpoints_{context}[API endpoint]: pass:c,a,q[{my-product-url}/__<endpoint>__], such as
28+
`pass:c,a,q[{my-product-url}/api/permission/policies]`.
29+
30+
Body::
31+
Enter the JSON body with data that your xref:ref-rbac-rest-api-endpoints_{context}[API endpoint] might need with the HTTP `POST` request.
32+
--
33+
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
[id='proc-sending-requests-to-the-rbac-rest-api-by-using-curl_{context}']
2+
= Sending requests to the RBAC REST API by using the curl utility
3+
4+
You can send RBAC REST API requests by using the curl utility.
5+
6+
.Prerequisites
7+
* xref:enabling-and-giving-access-to-rbac[You have access to the RBAC feature].
8+
9+
.Procedure
10+
include::snip-finding-bearer-token.adoc[]
11+
12+
. In a terminal, run the curl command and review the response:
13+
+
14+
--
15+
.Default request
16+
[source,subs="+attributes,+quotes"]
17+
----
18+
curl -v -H "Content-Type: application/json" \
19+
-H "Authorization: Bearer _<token>_" \
20+
-X __<method>__ "{my-product-url}/__<endpoint>__" \
21+
----
22+
23+
.POST request requiring JSON body data
24+
[source,subs="+attributes,+quotes"]
25+
----
26+
curl -v -H "Content-Type: application/json" \
27+
-H "Authorization: Bearer _<token>_" \
28+
-X POST "{my-product-url}/__<endpoint>__" \
29+
-d __<body>__
30+
----
31+
32+
__<token>__::
33+
Enter your saved authorization token.
34+
35+
__<method>__::
36+
Enter the HTTP method for your xref:ref-rbac-rest-api-endpoints_{context}[API endpoint].
37+
38+
* `GET`: To retrieve specified information from a specified resource endpoint.
39+
* `POST`: To create or update a resource.
40+
* `PUT`: To update a resource.
41+
* `DELETE`: To delete a resource.
42+
43+
pass:c,a,q[{my-product-url}]::
44+
Enter your {product-short} URL.
45+
46+
__<endpoint>__::
47+
Enter the xref:ref-rbac-rest-api-endpoints_{context}[API endpoint] to which you want to send a request, such as `/api/permission/policies`.
48+
49+
__<body>__::
50+
Enter the JSON body with data that your xref:ref-rbac-rest-api-endpoints_{context}[API endpoint] might need with the HTTP `POST` request.
51+
52+
.Example request to create or update a role
53+
[source,subs="+attributes,+quotes"]
54+
----
55+
curl -v -H "Content-Type: application/json" \
56+
-H "Authorization: Bearer _<token>_" \
57+
-X POST "{my-product-url}/api/permission/roles" \
58+
-d '{
59+
"memberReferences": ["group:default/example"],
60+
"name": "role:default/test",
61+
"metadata": { "description": "This is a test role" }
62+
}'
63+
----
64+
65+
.Example request to create or update a permission policy
66+
[source,subs="+attributes,+quotes"]
67+
----
68+
curl -v -H "Content-Type: application/json" \
69+
-H "Authorization: Bearer $token" \
70+
-X POST "{my-product-url}/api/permission/policies" \
71+
-d '[{
72+
"entityReference":"role:default/test",
73+
"permission": "catalog-entity",
74+
"policy": "read", "effect":"allow"
75+
}]'
76+
----
77+
78+
.Example request to create or update a condition
79+
[source,subs="+attributes,+quotes"]
80+
----
81+
82+
curl -v -H "Content-Type: application/json" \
83+
-H "Authorization: Bearer $token" \
84+
-X POST "{my-product-url}/api/permission/roles/conditions"\
85+
-d '{
86+
"result": "CONDITIONAL",
87+
"roleEntityRef": "role:default/test",
88+
"pluginId": "catalog",
89+
"resourceType": "catalog-entity",
90+
"permissionMapping": ["read"],
91+
"conditions": {
92+
"rule": "IS_ENTITY_OWNER",
93+
"resourceType": "catalog-entity",
94+
"params": {"claims": ["group:default/janus-authors"]}
95+
}
96+
}'
97+
----
98+
99+
--
100+
101+
.Verification
102+
* Review the returned HTTP status code:
103+
+
104+
--
105+
`200` OK:: The request was successful.
106+
`201` Created:: The request resulted in a new resource being successfully created.
107+
`204` No Content:: The request was successful, and the response payload has no more content.
108+
`400` Bad Request:: Input error with the request.
109+
`401` Unauthorized:: Lacks valid authentication for the requested resource.
110+
`403` Forbidden:: Refusal to authorize request.
111+
`404` Not Found:: Could not find requested resource.
112+
`409` Conflict:: Request conflict with the current state and the target resource.
113+
--
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
. Find your Bearer token to authenticate to the REST API.
2+
.. In your browser, open the web console *Network* tab.
3+
.. In the main screen, reload the {product-short} *Homepage*.
4+
.. In the web console *Network* tab, search for the `query?term=` network call.
5+
.. Save the *token* in the response JSON for the next steps.

0 commit comments

Comments
 (0)