kubernetes 列表权限是否允许获取集合中的单个对象

Does kubernetes list permissions allow getting individual objects in the collection

下面的角色是否允许获取 bar 命名空间中所有机密的内容,或者只允许获取名为 foo 的机密的内容?我不明白 docs

是什么意思

list (for collections, including full object content)

在此上下文中,“完整对象内容”是什么意思?

apiVersion: rbac.authorization.k8s.io/v1beta1
kind: Role
metadata:
  name: fooer
  namespace: bar
rules:
  - apiGroups: [""]
    resources: [secrets]
    verbs: [list]
  - apiGroups: [""]
    resources: [secrets]
    verbs: [get, watch]
    resourceNames: ["foo"]

谢谢

角色特定于 namespace。所以 yaml 实际上应该看起来像

apiVersion: rbac.authorization.k8s.io/v1beta1
kind: Role
metadata:
  name: role
  namespace: default
rules:
  - apiGroups: [""]
    resources: [secrets]
    verbs: [list]

---

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: role-binding
  namespace: default
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: role
subjects:
- kind: ServiceAccount
  name: default
  namespace: default

对于集合(例如机密)list 表示对列表下的所有资源的权限。因此,您可以使用以下命令获得具有上述角色的所有秘密

kubectl get secrets --as=system:serviceaccount:default:default -n default -o yaml

但您无法使用

单独获取每个秘密
kubectl get secrets/default-token-bwk2x --as=system:serviceaccount:default:default -n default -o yaml
Error from server (Forbidden): secrets "default-token-bwk2x" is forbidden: User "system:serviceaccount:default:default" cannot get resource "secrets" in API group "" in the namespace "default"

包括完整的对象内容 表示所有对象的内容都在该列表下,您可以使用上面的第一个命令看到.

Does kubernetes list permissions allow getting individual objects in the collection

不,不是。您只能获取列表中所有项目的完整聚合内容,而不能单独获取每个项目的内容。