Chapter 5. Role-Based Access Control (RBAC) in Red Hat Developer Hub
Role-Based Access Control is a security paradigm that restricts access to authorized users. This feature includes defining roles with specific permissions and then assigning those roles to the users.
The Red Hat Developer Hub uses RBAC to improve the permission system within the platform. The RBAC feature in Developer Hub introduces an administrator role and leverages the organizational structure including teams, groups, and users by facilitating efficient access control.
5.1. Permission policies configuration Copy linkLink copied to clipboard!
There are two approaches to configure the permission policies in Red Hat Developer Hub, including:
- Configuration of permission policies administrators
- Configuration of permission policies defined in an external file
5.1.1. Configuration of permission policies administrators Copy linkLink copied to clipboard!
The permission policies for users and groups in the Developer Hub are managed by permission policy administrators. Only permission policy administrators can access the Role-Based Access Control REST API.
The purpose of configuring policy administrators is to enable a specific, restricted number of authenticated users to access the RBAC REST API. The permission policies are defined in a policy.csv file, which is referenced in the app-config-rhdh ConfigMap. OpenShift platform administrators or cluster administrators can perform this task with access to the namespace where Red Hat Developer Hub is deployed.
You can set the credentials of a permission policy administrator in the app-config.yaml file as follows:
permission:
enabled: true
rbac:
admin:
users:
- name: user:default/joeuser
5.1.2. Configuration of permission policies defined in an external file Copy linkLink copied to clipboard!
You can follow this approach of configuring the permission policies before starting the Red Hat Developer Hub. If permission policies are defined in an external file, then you can import the same file in the Developer Hub. The permission policies need to be defined in Casbin rules format. For information about the Casbin rules format, see Basics of Casbin rules.
The following is an example of permission policies configuration:
p, role:default/guests, catalog-entity, read, deny
p, role:default/guests, catalog.entity.create, create, deny
g, user:default/<USER_TO_ROLE>, role:default/guests
If a defined permission does not contain an action associated with it, then add use as a policy. See the following example:
p, role:default/guests, kubernetes.proxy, use, deny
You can define the policy.csv file path in the app-config.yaml file:
permission:
enabled: true
rbac:
policies-csv-file: /some/path/rbac-policy.csv
5.1.2.1. Mounting policy.csv file to the Developer Hub Helm Chart Copy linkLink copied to clipboard!
When the Red Hat Developer Hub is deployed with the Helm Chart, then you must define the policy.csv file by mounting it to the Developer Hub Helm Chart.
You can add your policy.csv file to the Developer Hub Helm Chart by creating a configMap and mounting it.
Prerequisites
- You are logged in to your OpenShift Container Platform account using the OpenShift Container Platform web console.
Red Hat Developer Hub is installed and deployed using Helm Chart.
For more information about installing the Red Hat Developer Hub on OpenShift Container Platform using Helm Chart, see Section 2.1, “Deploying Red Hat Developer Hub on OpenShift Container Platform using Helm Chart”.
Procedure
In OpenShift Container Platform, create a ConfigMap to hold the policies as shown in the following example:
Example
ConfigMapkind: ConfigMap apiVersion: v1 metadata: name: rbac-policy namespace: rhdh data: rbac-policy.csv: | p, role:default/guests, catalog-entity, read, allow p, role:default/guests, catalog.entity.create, create, allow g, user:default/<YOUR_USER>, role:default/guests-
In the Developer Hub Helm Chart, go to Root Schema
Backstage chart schema Backstage parameters Backstage container additional volume mounts. Select Add Backstage container additional volume mounts and add the following values:
-
mountPath:
opt/app-root/src/rbac -
Name:
rbac-policy
-
mountPath:
Add the RBAC policy to the Backstage container additional volumes in the Developer Hub Helm Chart:
-
name:
rbac-policy configMap
-
defaultMode:
420 -
name:
rbac-policy
-
defaultMode:
-
name:
Update the policy path in the
app-config.yamlfile as follows:Example
app-config.yamlfilepermission: enabled: true rbac: policies-csv-file: ./rbac/rbac-policy.csv
5.1.3. Permission policies in Red Hat Developer Hub Copy linkLink copied to clipboard!
Permission policies in Red Hat Developer Hub are a set of rules to govern access to resources or functionalities. These policies state the authorization level that is granted to users based on their roles. The permission policies are implemented to maintain security and confidentiality within a given environment.
The following permission policies are supported in the Developer Hub:
- Catalog permissions
| Name | Resource type | Policy | Description |
|---|---|---|---|
|
|
| read | Allows user or role to read from the catalog |
|
| create | Allows user or role to create catalog entities, including registering an existing component in the catalog | |
|
|
| update | Allows user or role to refresh a single or multiple entities from the catalog |
|
|
| delete | Allows user or role to delete a single or multiple entities from the catalog |
|
| read | Allows user or role to read a single or multiple locations from the catalog | |
|
| create | Allows user or role to create locations within the catalog | |
|
| delete | Allows user or role to delete locations from the catalog |
- Scaffolder permissions
| Name | Resource type | Policy | Description |
|---|---|---|---|
|
|
| Allows the execution of an action from a template | |
|
|
| read | Allows user or role to read a single or multiple one parameters from a template |
|
|
| read | Allows user or role to read a single or multiple steps from a template |
- RBAC permissions
| Name | Resource type | Policy | Description |
|---|---|---|---|
|
|
| read | Allows user or role to read permission policies and roles |
|
|
| create | Allows user or role to create a single or multiple permission policies and roles |
|
|
| update | Allows user or role to update a single or multiple permission policies and roles |
|
|
| delete | Allows user or role to delete a single or multiple permission policies and roles |
- Kubernetes permissions
| Name | Resource type | Policy | Description |
|---|---|---|---|
|
| Allows user or role to access the proxy endpoint |
5.2. Managing role-based access controls (RBAC) using the Red Hat Developer Hub Web UI Copy linkLink copied to clipboard!
Administrators can use the Developer Hub web interface (Web UI) to allocate specific roles and permissions to individual users or groups. Allocating roles ensures that access to resources and functionalities is regulated across the Developer Hub.
With the administrator role in Developer Hub, you can assign permissions to users and groups, which allow users or groups to view, create, modify, and delete the roles using the Developer Hub Web UI.
To access the RBAC features in the Web UI, you must install and configure the @janus-idp/backstage-plugin-rbac plugin as a dynamic plugin. For more information about installing a dynamic plugin, see Chapter 6, Dynamic plugin installation.
After you install the @janus-idp/backstage-plugin-rbac plugin, the Administration option appears at the bottom of the sidebar. When you can click Administration, the RBAC tab appears by default, displaying all of the existing roles created in the Developer Hub. In the RBAC tab, you can also view the total number of users, groups, and the total number of permission policies associated with a role. You can also edit or delete a role using the Actions column.
5.2.1. Creating a role in the Red Hat Developer Hub Web UI Copy linkLink copied to clipboard!
You can create a role in the Red Hat Developer Hub using the Web UI.
Prerequisites
- You have an administrator role in the Developer Hub.
-
You have installed the
@janus-idp/backstage-plugin-rbacplugin in Developer Hub. For more information, see Chapter 6, Dynamic plugin installation. - You have configured the required permission policies. For more information, see Section 5.1, “Permission policies configuration”.
Procedure
Go to Administration at the bottom of the sidebar in the Developer Hub.
The RBAC tab appears, displaying all the created roles in the Developer Hub.
- (Optional) Click any role to view the role information on the OVERVIEW page.
- Click CREATE to create a role.
- Enter the name and description of the role in the given fields and click NEXT.
- Add users and groups using the search field, and click NEXT.
- Select Plugin and Permission from the drop-downs in the Add permission policies section.
- Select or clear the Policy that you want to set in the Add permission policies section, and click NEXT.
- Review the added information in the Review and create section.
- Click CREATE.
Verification
The created role appears in the list available in the RBAC tab.
5.2.2. Editing a role in the Red Hat Developer Hub Web UI Copy linkLink copied to clipboard!
You can edit a role in the Red Hat Developer Hub using the Web UI.
The policies generated from a policy.csv or ConfigMap file cannot be edited or deleted using the Developer Hub Web UI.
Prerequisites
- You have an administrator role in the Developer Hub.
-
You have installed the
@janus-idp/backstage-plugin-rbacplugin in Developer Hub. For more information, see Chapter 6, Dynamic plugin installation. - You have configured the required permission policies. For more information, see Section 5.1, “Permission policies configuration”.
- The role that you want to edit is created in the Developer Hub.
Procedure
Go to Administration at the bottom of the sidebar in the Developer Hub.
The RBAC tab appears, displaying all the created roles in the Developer Hub.
- (Optional) Click any role to view the role information on the OVERVIEW page.
- Select the edit icon for the role that you want to edit.
- Edit the details of the role, such as name, description, users and groups, and permission policies, and click NEXT.
- Review the edited details of the role and click SAVE.
After editing a role, you can view the edited details of a role on the OVERVIEW page of a role. You can also edit a role’s users and groups or permissions by using the edit icon on the respective cards on the OVERVIEW page.
5.2.3. Deleting a role in the Red Hat Developer Hub Web UI Copy linkLink copied to clipboard!
You can delete a role in the Red Hat Developer Hub using the Web UI.
The policies generated from a policy.csv or ConfigMap file cannot be edited or deleted using the Developer Hub Web UI.
Prerequisites
- You have an administrator role in the Developer Hub.
-
You have installed the
@janus-idp/backstage-plugin-rbacplugin in Developer Hub. For more information, see Chapter 6, Dynamic plugin installation. - You have configured the required permission policies. For more information, see Section 5.1, “Permission policies configuration”.
- The role that you want to delete is created in the Developer Hub.
Procedure
Go to Administration at the bottom of the sidebar in the Developer Hub.
The RBAC tab appears, displaying all the created roles in the Developer Hub.
- (Optional) Click any role to view the role information on the OVERVIEW page.
Select the delete icon from the Actions column for the role that you want to delete.
Delete this role? pop-up appears on the screen.
- Click DELETE.
5.3. Role-based Access Control (RBAC) REST API Copy linkLink copied to clipboard!
Red Hat Developer Hub provides RBAC REST API that you can use to manage the permissions and roles in the Developer Hub. This API supports you to facilitate and automate the maintenance of Developer Hub permission policies and roles.
Using the RBAC REST API, you can perform the following actions:
- Retrieve information about all permission policies or specific permission policies, or roles
- Create, update, or delete a permission policy or a role
- Retrieve permission policy information about static plugins
The RBAC REST API requires the following components:
Authorization
The RBAC REST API requires Bearer token authorization for the permitted user role. For development purposes, you can access a web console in a browser. When you refresh a token request in the list of network requests, you find the token in the response JSON.
Authorization: Bearer $token
For example, on the Homepage of the Developer Hub, you can navigate to the Network tab and search for the query?term= network call. Alternatively, you can go to the Catalog page and select any network call with entity-facets to acquire the Bearer token.
HTTP methods
The RBAC REST API supports the following HTTP methods for API requests:
-
GET: Retrieves specified information from a specified resource endpoint -
POST: Creates or updates a resource -
PUT: Updates a resource -
DELETE: Deletes a resource
Base URL
The base URL for RBAC REST API requests is http://SERVER:PORT/api/permission/policies, such as http://localhost:7007/api/permission/policies.
Endpoints
RBAC REST API endpoints, such as /api/permission/policies/[kind]/[namespace]/[name] for specified kind, namespace, and username, are the URI that you append to the base URL to access the corresponding resource.
Example request URL for /api/permission/policies/[kind]/[namespace]/[name] endpoint is:
http://localhost:7007/api/permission/policies/user/default/johndoe
If at least one permission is assigned to user:default/johndoe, then the example request URL mentioned previously returns a result if sent in a GET response with a valid authorization token. However, if permission is only assigned to roles, then the example request URL does not return an output.
Request data
HTTP POST requests in the RBAC REST API may require a JSON request body with data to accompany the request.
Example POST request URL and JSON request body data for http://localhost:7007/api/permission/policies:
{
"entityReference": "role:default/test",
"permission": "catalog-entity",
"policy": "delete",
"effect": "allow"
}
HTTP status codes
The RBAC REST API supports the following HTTP status codes to return as responses:
-
200OK: The request was successful. -
201Created: The request resulted in a new resource being successfully created. -
204No Content: The request was successful, but there is no additional content to send in the response payload. -
400Bad Request: input error with the request -
401Unauthorized: lacks valid authentication for the requested resource -
403Forbidden: refusal to authorize request -
404Not Found: could not find requested resource -
409Conflict: request conflict with the current state and the target resource
5.3.1. Sending requests with the RBAC REST API using a REST client or curl utility Copy linkLink copied to clipboard!
The RBAC REST API enables you to interact with the permission policies and roles in Developer Hub without using the user interface. You can send RBAC REST API requests using any REST client or curl utility.
Prerequisites
- Red Hat Developer Hub is installed and running. For more information about installing Red Hat Developer Hub, see Section 2.1, “Deploying Red Hat Developer Hub on OpenShift Container Platform using Helm Chart”. .
- You have access to the Developer Hub.
Procedure
Identify a relevant API endpoint to which you want to send a request, such as
POST /api/permission/policies. Adjust any request details according to your use case.For REST client:
- Authorization: Enter the generated token from the web console.
-
HTTP method: Set to
POST. -
URL: Enter the RBAC REST API base URL and endpoint such as
http://localhost:7007/api/permission/policies.
For curl utility:
-
-X: Set toPOST -H: Set the following header:Content-type: application/jsonAuthorization: Bearer $token$tokenis the requested token from the web console in a browser.-
URL: Enter the following RBAC REST API base URL endpoint, such as
http://localhost:7007/api/permission/policies -
-d: Add a request JSON body
Example request:
curl -X POST "http://localhost:7007/api/permission/policies" -d '{"entityReference":"role:default/test", "permission": "catalog-entity", "policy": "read", "effect":"allow"}' -H "Content-Type: application/json" -H "Authorization: Bearer $token" -v- Execute the request and review the response.
5.3.2. Supported RBAC REST API endpoints Copy linkLink copied to clipboard!
The RBAC REST API provides the following endpoints for managing permission policies and roles in the Developer Hub and for retrieving information about the policies and roles.
5.3.2.1. Permission policies Copy linkLink copied to clipboard!
The RBAC REST API supports the following endpoints for managing permission policies in the Red Hat Developer Hub.
- [GET] /api/permission/policies
Returns permission policies list for all users.
Example response (JSON)
[ { "entityReference": "role:default/test", "permission": "catalog-entity", "policy": "read", "effect": "allow" }, { "entityReference": "role:default/test", "permission": "catalog.entity.create", "policy": "use", "effect": "allow" }, ]- [GET] /api/permission/policies/{kind}/{namespace}/{name}
Returns permission policies related to the specified entity reference.
Expand Table 5.1. Request parameters Name Description Type Requirement kindKind of the entity
String
Required
namespaceNamespace of the entity
String
Required
nameUsername related to the entity
String
Required
Example response (JSON)
[ { "entityReference": "role:default/test", "permission": "catalog-entity", "policy": "read", "effect": "allow" }, { "entityReference": "role:default/test", "permission": "catalog.entity.create", "policy": "use", "effect": "allow" } ]- [POST] /api/permission/policies
Creates a permission policy for a specified entity.
Expand Table 5.2. Request parameters Name Description Type Requirement entityReferenceReference values of an entity including namespace and name
String
Required
permissionType of the permission
String
Required
policyRead or write policy to the permission
String
Required
effectIndication of allowing or not allowing the policy
String
Required
Example request body (JSON)
{ "entityReference": "role:default/test", "permission": "catalog-entity", "policy": "read", "effect": "allow" }Example response
201 Created- [PUT] /api/permission/policies/{kind}/{namespace}/{name}
Updates a permission policy for a specified entity.
Request parameters
The request body contains the
oldPolicyandnewPolicyobjects:Expand Name Description Type Requirement permissionType of the permission
String
Required
policyRead or write policy to the permission
String
Required
effectIndication of allowing or not allowing the policy
String
Required
Example request body (JSON)
{ "oldPolicy": { "permission": "catalog-entity", "policy": "read", "effect": "deny" }, "newPolicy": { "permission": "policy-entity", "policy": "read", "effect": "allow" } }Example response
200- [DELETE] /api/permission/policies/{kind}/{namespace}/{name}?permission={value1}&policy={value2}&effect={value3}
Deletes a permission policy added to the specified entity.
Expand Table 5.3. Request parameters Name Description Type Requirement kindKind of the entity
String
Required
namespaceNamespace of the entity
String
Required
nameUsername related to the entity
String
Required
permissionType of the permission
String
Required
policyRead or write policy to the permission
String
Required
effectIndication of allowing or not allowing the policy
String
Required
Example response
204 No Content- [GET] /api/permission/plugins/policies
Returns permission policies for all static plugins.
Example response (JSON)
[ { "pluginId": "catalog", "policies": [ { "permission": "catalog-entity", "policy": "read" }, { "permission": "catalog.entity.create", "policy": "create" }, { "permission": "catalog-entity", "policy": "delete" }, { "permission": "catalog-entity", "policy": "update" }, { "permission": "catalog.location.read", "policy": "read" }, { "permission": "catalog.location.create", "policy": "create" }, { "permission": "catalog.location.delete", "policy": "delete" } ] }, ... ]
5.3.2.2. Roles Copy linkLink copied to clipboard!
The RBAC REST API supports the following endpoints for managing roles in the Red Hat Developer Hub.
- [GET] /api/permission/roles
Returns all roles in Developer Hub.
Example response (JSON)
[ { "memberReferences": ["user:default/pataknight"], "name": "role:default/guests" }, { "memberReferences": [ "group:default/janus-authors", "user:default/matt" ], "name": "role:default/rbac_admin" } ]- [GET] /api/permission/roles/{kind}/{namespace}/{name}
Creates a role in Developer Hub.
Expand Table 5.4. Request parameters Name Description Type Requirement bodyThe
memberReferences,group,namespace, andnamethe new role to be created.Request body
Required
Example request body (JSON)
{ "memberReferences": ["group:default/test"], "name": "role:default/test_admin" }Example response
201 Created- [PUT] /api/permission/roles/{kind}/{namespace}/{name}
Updates
memberReferences,kind,namespace, ornamefor a role in Developer Hub.Request parameters
The request body contains the
oldRoleandnewRoleobjects:Expand Name Description Type Requirement bodyThe
memberReferences,group,namespace, andnamethe new role to be created.Request body
Required
Example request body (JSON)
{ "oldRole": { "memberReferences": ["group:default/test"], "name": "role:default/test_admin" }, "newRole": { "memberReferences": ["group:default/test", "user:default/test2"], "name": "role:default/test_admin" } }Example response
200 OK- [DELETE] /api/permission/roles/{kind}/{namespace}/{name}?memberReferences=<VALUE>
Deletes the specified user or group from a role in Developer Hub.
Expand Table 5.5. Request parameters Name Description Type Requirement kindKind of the entity
String
Required
namespaceNamespace of the entity
String
Required
nameUsername related to the entity
String
Required
memberReferencesAssociated group information
String
Required
Example response
204- [DELETE] /api/permission/roles/{kind}/{namespace}/{name}
Deletes a specified role from Developer Hub.
Expand Table 5.6. Request parameters Name Description Type Requirement kindKind of the entity
String
Required
namespaceNamespace of the entity
String
Required
nameUsername related to the entity
String
Required
Example response
204