Can you provide another example of roleRef?

Certainly! Here’s another example of a roleRef in a Role Binding that grants permissions to a specific Role within a namespace.

Example Role Definition

First, let's define a Role that allows reading and listing pods in a specific namespace:

kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: pod-reader
  namespace: my-namespace
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "list"]

Example Role Binding

Now, we can create a Role Binding that references this Role using roleRef:

kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: pod-reader-binding
  namespace: my-namespace
subjects:
- kind: User
  name: alice
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: Role
  name: pod-reader
  apiGroup: rbac.authorization.k8s.io

Explanation:

  • Role: The pod-reader Role allows the user to get and list pods in the my-namespace namespace.
  • Role Binding: The pod-reader-binding Role Binding grants the user alice the permissions defined in the pod-reader Role.
  • roleRef: The roleRef specifies that this binding refers to the pod-reader Role, thus linking the user to the permissions defined in that Role.

This setup allows alice to read and list pods specifically in the my-namespace namespace.

0 Comments

no data
Be the first to share your comment!