允许访问 K8 资源的子集
Allow access to subset of K8 resources
我授予了对 pod 的读取权限
样本:
kubectl create serviceaccount sa1
kubectl create role pod-reader --verb=get --resource=pods
kubectl create rolebinding sa1-binding --serviceaccount=default:sa1 --role=pod-reader
有什么方法可以根据元数据或标签将此访问权限限制为选定的pods?
据我所知,无法将角色限制为某些标签。实际上这里有一个与此相关的问题:https://github.com/kubernetes/kubernetes/issues/44703
使用 RBAC,您指定对资源的访问权限,这些资源是 API 组的一部分,您 select 可以执行哪些动词 - 仅此而已。
正如评论中所讨论的,您可以使用 resourceNames
来提供对选定资源的访问。
这是 k8s 的摘录 docs。
示例,
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: default
name: configmap-updater
rules:
- apiGroups: [""]
#
# at the HTTP level, the name of the resource for accessing ConfigMap
# objects is "configmaps"
resources: ["configmaps"]
resourceNames: ["my-configmap"]
verbs: ["update", "get"]
Also, You cannot restrict create or deletecollection requests by resourceName. For create, this limitation is because the object name is not known at authorization time.
我授予了对 pod 的读取权限
样本:
kubectl create serviceaccount sa1
kubectl create role pod-reader --verb=get --resource=pods
kubectl create rolebinding sa1-binding --serviceaccount=default:sa1 --role=pod-reader
有什么方法可以根据元数据或标签将此访问权限限制为选定的pods?
据我所知,无法将角色限制为某些标签。实际上这里有一个与此相关的问题:https://github.com/kubernetes/kubernetes/issues/44703
使用 RBAC,您指定对资源的访问权限,这些资源是 API 组的一部分,您 select 可以执行哪些动词 - 仅此而已。
正如评论中所讨论的,您可以使用 resourceNames
来提供对选定资源的访问。
这是 k8s 的摘录 docs。
示例,
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: default
name: configmap-updater
rules:
- apiGroups: [""]
#
# at the HTTP level, the name of the resource for accessing ConfigMap
# objects is "configmaps"
resources: ["configmaps"]
resourceNames: ["my-configmap"]
verbs: ["update", "get"]
Also, You cannot restrict create or deletecollection requests by resourceName. For create, this limitation is because the object name is not known at authorization time.