当多个集群角色分配给 kubernetes 中的一个服务帐户时会发生什么?

tou*_*med 4 rbac kubernetes

我知道当您希望服务帐户访问多个命名空间时,您可以为一个服务帐户分配多个角色,但我想知道当您向它分配多个集群范围内的集群角色时,它会如何表现。从我的角度来看,我认为它会选择其中之一,但我不确定。

Abd*_*UMI 6

权限纯粹是附加的(没有“拒绝”规则)。

参考

这是我们必须记住的 kubernetes RBAC 角色的黄金法则。

“纯附加”意味着始终不允许撤销。

因此,“纯累加”意味着既不存在冲突,也不存在优先顺序

  • 这与AWS IAM 策略不同,我们有 DENY 和 ALLOW 。此时,我们必须知道哪一个具有最高优先级。
  • 它不像子网 ACL,我们有 DENY 和 ALLOW .. 这时,我们需要为每个规则分配编号。这个数字将决定优先顺序。

例子:

---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  # "namespace" omitted since ClusterRoles are not namespaced
  name: pod-reader
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "watch", "list"]
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  # "namespace" omitted since ClusterRoles are not namespaced
  name: node-reader
rules:
- apiGroups: [""]
  resources: ["nodes"]
  verbs: ["get", "watch", "list"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: pod-reader
subjects:
- kind: User
  name: abdennour
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: ClusterRole
  name: pod-reader
  apiGroup: rbac.authorization.k8s.io
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: node-reader
subjects:
- kind: User
  name: abdennour
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: ClusterRole
  name: node-reader
  apiGroup: rbac.authorization.k8s.io

Run Code Online (Sandbox Code Playgroud)

正如您在此示例中所看到的,用户 Abdennour 最后应该拥有对节点和 Pod 的广泛读取访问权限。

  • 非常感谢 @Abdennour TOUMI 先生的清晰解释 (2认同)