Open SHift RBAC role exampel YAML file - unix1998/technical_notes GitHub Wiki

both RoleBindings and ClusterRoleBindings are Kubernetes objects that are typically defined in YAML files. You can create or update them by applying the YAML files using the oc apply -f command in OpenShift. Here's how you can create RoleBindings and ClusterRoleBindings using YAML files:

1. RoleBindings YAML Example:

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: example-rolebinding
  namespace: your-namespace
subjects:
- kind: User
  name: alice
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: Role
  name: example-role
  apiGroup: rbac.authorization.k8s.io
  • This YAML file creates a RoleBinding named example-rolebinding in the specified namespace.
  • It binds the user alice to the Role named example-role.

2. ClusterRoleBindings YAML Example:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: example-clusterrolebinding
subjects:
- kind: Group
  name: administrators
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: ClusterRole
  name: cluster-admin
  apiGroup: rbac.authorization.k8s.io
  • This YAML file creates a ClusterRoleBinding named example-clusterrolebinding.
  • It binds the group administrators to the ClusterRole named cluster-admin.

Applying YAML Files:

To apply the YAML files and create or update the RoleBindings and ClusterRoleBindings:

  1. Save the YAML files locally with the appropriate configurations.
  2. Run the following commands:
oc apply -f RoleBindings.yaml
oc apply -f ClusterRoleBindings.yaml
  • Replace RoleBindings.yaml and ClusterRoleBindings.yaml with the paths to your YAML files.

These commands will apply the configurations specified in the YAML files and create or update the RoleBindings and ClusterRoleBindings in your OpenShift cluster. Make sure to have the necessary permissions to create or update RBAC resources within the cluster.