【发布时间】:2020-05-02 08:45:00
【问题描述】:
我正在尝试授予我的服务帐户foo 获取集群上节点列表的权限(通过kubectl get nodes)。我用这些权限创建了一个集群角色和一个角色绑定:
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: foo-cluster-role
rules:
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "list", "watch"]
当我使用该服务帐户运行 pod 时,我无法运行 kubectl get nodes:
root@debugger:/# kubectl get nodes
Error from server (Forbidden): nodes is forbidden: User "system:serviceaccount:default:foo" cannot list resource "nodes" in API group "" at the cluster scope
奇怪的是,当我通过 kubectl auth can-i 询问时,它告诉我应该可以访问:
root@debugger:/# kubectl auth can-i get nodes
Warning: resource 'nodes' is not namespace scoped
yes
如何设置我的服务帐户,以便我有权列出集群上的节点?
edit clusterrolebinding 看起来像这样:
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: foo-binding
subjects:
- kind: ServiceAccount
name: foo
roleRef:
kind: ClusterRole
name: foo-cluster-role
apiGroup: ""
【问题讨论】:
-
你也可以分享 ClusterRoleBinding 吗?
-
同时检查
kubectl auth can-i get nodes --as=system:serviceaccount:default:foo -
@hoque 添加了绑定。 kubectl auth can-i 也返回 yes
标签: kubernetes