Bookmark this page

Define and Apply Permissions with RBAC

Objectives

  • Define role-based access controls and apply permissions to users.

Role-based Access Control (RBAC)

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.

Note

Authorization is a separate step from authentication.

Authorization Process

The authorization process is managed by rules, roles, and bindings.

RBAC ObjectDescription
RuleAllowed actions for objects or groups of objects.
RoleSets of rules. Users and groups can be associated with multiple roles.
BindingAssignment of users or groups to a role.

RBAC Scope

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 LevelDescription
Cluster roleUsers or groups with this role level can manage the OpenShift cluster.
Local roleUsers or groups with this role level can manage only elements at a project level.

Note

Cluster role bindings take precedence over local role bindings.

Managing RBAC with the CLI

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 username

For 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 username

To 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 username

For 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 username

Rules 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 user

Default Roles

OpenShift 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 rolesDescription
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 project

For 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 wordpress

Even 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.

User Types

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.

Regular users

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.

System users

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

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:namespace: prefix, such as 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.

Group Management

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-developers

Likewise, the following command adds the user1 user to the lead-developers group:

[user@host ~]$ oc adm groups add-user lead-developers user1

References

For 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

Kubernetes Namespaces

Revision: do280-4.14-08d11e1