Role-based access control (RBAC) is a technique for managing access to resources in a computer system. In Red Hat OpenShift, RBAC determines whether a user can perform certain actions within the cluster or project. You can choose between two role types, depending on the user's level of responsibility: cluster and local.
Authorization is a separate step from authentication.
The authorization process is managed by rules, roles, and bindings.
| RBAC Object | Description |
|---|---|
| Rule | Allowed actions for objects or groups of objects. |
| Role | Sets of rules. Users and groups can be associated with multiple roles. |
| Binding | Assignment of users or groups to a role. |
Red Hat OpenShift Container Platform (RHOCP) defines two groups of roles and bindings depending on the user's scope and responsibility: cluster roles and local roles.
| Role Level | Description |
|---|---|
| Cluster role | Users or groups with this role level can manage the OpenShift cluster. |
| Local role | Users or groups with this role level can manage only elements at a project level. |
Cluster role bindings take precedence over local role bindings.
Cluster administrators can use the oc adm policy command to add and remove cluster roles and namespace roles.
To add a cluster role to a user, use the add-cluster-role-to-user subcommand:
[user@host ~]$ oc adm policy add-cluster-role-to-user cluster-role usernameFor example, to change a regular user to a cluster administrator, use the following command:
[user@host ~]$ oc adm policy add-cluster-role-to-user cluster-admin usernameTo remove a cluster role from a user, use the remove-cluster-role-from-user subcommand:
[user@host ~]$ oc adm policy remove-cluster-role-from-user cluster-role usernameFor example, to change a cluster administrator to a regular user, use the following command:
[user@host ~]$ oc adm policy remove-cluster-role-from-user cluster-admin usernameRules are defined by an action and a resource.
For example, the create user rule is part of the cluster-admin role.
You can use the oc adm policy who-can command to determine whether a user can execute an action on a resource.
For example:
[user@host ~]$ oc adm policy who-can delete userOpenShift ships with a set of default cluster roles that can be assigned locally or to the entire cluster. You can modify these roles for fine-grained access control to OpenShift resources. Other required steps are outside the scope of this course.
| Default roles | Description |
|---|---|
admin
| Users with this role can manage all project resources, including granting access to other users to access the project. |
basic-user
| Users with this role have read access to the project. |
cluster-admin
| Users with this role have superuser access to the cluster resources. These users can perform any action on the cluster, and have full control of all projects. |
cluster-status
| Users with this role can get cluster status information. |
edit
| Users with this role can create, change, and delete common application resources on the project, such as services and deployments. These users cannot act on management resources such as limit ranges and quotas, and cannot manage access permissions to the project. |
self-provisioner
| Users with this role can create projects. It is a cluster role, not a project role. |
view
| Users with this role can view project resources, but cannot modify project resources. |
The admin role gives a user access to project resources such as quotas and limit ranges, and also the ability to create applications.
The edit role gives a user sufficient access to act as a developer inside the project, but working under the constraints that a project administrator configured.
Project administrators can use the oc policy command to add and remove namespace roles.
Add a specified role to a user with the add-role-to-user subcommand.
For example:
[user@host ~]$ oc policy add-role-to-user role-name username -n projectFor example, run the following command to add the dev user to the basic-user cluster role in the wordpress project.
[user@host ~]$ oc policy add-role-to-user basic-user dev -n wordpressEven though basic-user is a cluster role, the add-role-to-user subcommand limits the scope of the role to the wordpress namespace for the dev user.
Interaction with OpenShift Container Platform is associated with a user.
An OpenShift Container Platform user object represents a user who can be granted permissions in the system by adding roles to that user or to a user's group via role bindings.
Most interactive OpenShift Container Platform users are regular users, and are represented with the User object.
This type of user represents a person with access to the platform.
Many system users are created automatically when the infrastructure is defined, mainly for the infrastructure to securely interact with the API. System users include a cluster administrator (with access to everything), a per-node user, users for routers and registries, and various others. An anonymous system user is used by default for unauthenticated requests.
System user names start with a system: prefix, such as system:admin, system:openshift-registry, and system:node:node1.example.com.
Service accounts are system users that are associated with projects. Workloads can use service accounts to invoke Kubernetes APIs.
Some service account users are created automatically during project creation. Project administrators can create more service accounts to grant extra privileges to workloads. By default, service accounts have no roles. Grant roles to service accounts to enable workloads to use specific APIs.
Service accounts are represented with the ServiceAccount object.
System account user names start with a system:serviceaccount: prefix, such as namespace:system:serviceaccount:default:deployer and system:serviceaccount:accounting:builder.
Every user must authenticate before they can access OpenShift Container Platform. API requests with no authentication or invalid authentication are authenticated as requests by the anonymous system user. After successful authentication, the policy determines what the user is authorized to do.
A group resource represents a set of users.
Cluster administrators can use the oc adm groups command to add groups or to add users to groups.
For example, run the following command to add the lead-developers group to the cluster:
[user@host ~]$ oc adm groups new lead-developersLikewise, the following command adds the user1 user to the lead-developers group:
[user@host ~]$ oc adm groups add-user lead-developers user1For more information about RBAC, refer to the Using RBAC to Define and Apply Permissions chapter in the Red Hat OpenShift Container Platform 4.14 Authentication and Authorization documentation at https://access.redhat.com/documentation/en-us/openshift_container_platform/4.14/html-single/authentication_and_authorization/index#using-rbac
For more information about groups, refer to the Understanding Authentication chapter in the Red Hat OpenShift Container Platform 4.14 Authentication and Authorization documentation at https://access.redhat.com/documentation/en-us/openshift_container_platform/4.14/html-single/authentication_and_authorization/index#understanding-authentication