@@ -123,25 +123,7 @@ Here is an example of a RoleBinding that grants the "pod-reader" Role to the use
123
123
within the "default" namespace.
124
124
This allows "jane" to read pods in the "default" namespace.
125
125
126
- ``` yaml
127
- apiVersion : rbac.authorization.k8s.io/v1
128
- # This role binding allows "jane" to read pods in the "default" namespace.
129
- # You need to already have a Role named "pod-reader" in that namespace.
130
- kind : RoleBinding
131
- metadata :
132
- name : read-pods
133
- namespace : default
134
- subjects :
135
- # You can specify more than one "subject"
136
- - kind : User
137
- name : jane # "name" is case sensitive
138
- apiGroup : rbac.authorization.k8s.io
139
- roleRef :
140
- # "roleRef" specifies the binding to a Role / ClusterRole
141
- kind : Role # this must be Role or ClusterRole
142
- name : pod-reader # this must match the name of the Role or ClusterRole you wish to bind to
143
- apiGroup : rbac.authorization.k8s.io
144
- ` ` `
126
+ {{% code_sample file="access/simple-rolebinding-with-role.yaml" %}}
145
127
146
128
A RoleBinding can also reference a ClusterRole to grant the permissions defined in that
147
129
ClusterRole to resources inside the RoleBinding's namespace. This kind of reference
@@ -152,48 +134,15 @@ For instance, even though the following RoleBinding refers to a ClusterRole,
152
134
"dave" (the subject, case sensitive) will only be able to read Secrets in the "development"
153
135
namespace, because the RoleBinding's namespace (in its metadata) is "development".
154
136
155
- ` ` ` yaml
156
- apiVersion : rbac.authorization.k8s.io/v1
157
- # This role binding allows "dave" to read secrets in the "development" namespace.
158
- # You need to already have a ClusterRole named "secret-reader".
159
- kind : RoleBinding
160
- metadata :
161
- name : read-secrets
162
- #
163
- # The namespace of the RoleBinding determines where the permissions are granted.
164
- # This only grants permissions within the "development" namespace.
165
- namespace : development
166
- subjects :
167
- - kind : User
168
- name : dave # Name is case sensitive
169
- apiGroup : rbac.authorization.k8s.io
170
- roleRef :
171
- kind : ClusterRole
172
- name : secret-reader
173
- apiGroup : rbac.authorization.k8s.io
174
- ` ` `
137
+ {{% code_sample file="access/simple-rolebinding-with-clusterrole.yaml" %}}
175
138
176
139
#### ClusterRoleBinding example
177
140
178
141
To grant permissions across a whole cluster, you can use a ClusterRoleBinding.
179
142
The following ClusterRoleBinding allows any user in the group "manager" to read
180
143
secrets in any namespace.
181
144
182
- ` ` ` yaml
183
- apiVersion : rbac.authorization.k8s.io/v1
184
- # This cluster role binding allows anyone in the "manager" group to read secrets in any namespace.
185
- kind : ClusterRoleBinding
186
- metadata :
187
- name : read-secrets-global
188
- subjects :
189
- - kind : Group
190
- name : manager # Name is case sensitive
191
- apiGroup : rbac.authorization.k8s.io
192
- roleRef :
193
- kind : ClusterRole
194
- name : secret-reader
195
- apiGroup : rbac.authorization.k8s.io
196
- ` ` `
145
+ {{% code_sample file="access/simple-clusterrolebinding.yaml" %}}
197
146
198
147
After you create a binding, you cannot change the Role or ClusterRole that it refers to.
199
148
If you try to change a binding's ` roleRef ` , you get a validation error. If you do want
0 commit comments