即使我是所有者和管理员,也无法在GKE中创建群集角色

Seb*_*sch 11 rbac google-cloud-platform kubernetes google-kubernetes-engine

创建新的GKE集群后,创建集群角色失败,并显示以下错误:

Error from server (Forbidden): error when creating "./role.yaml":
clusterroles.rbac.authorization.k8s.io "secret-reader" is forbidden: 
attempt to grant extra privileges: [PolicyRule{Resources:["secrets"], 
APIGroups:[""], Verbs:["get"]} PolicyRule{Resources:["secrets"], 
APIGroups:[""], Verbs:["watch"]} PolicyRule{Resources:["secrets"], 
APIGroups:[""], Verbs:["list"]}] user=&{XXX@gmail.com  
[system:authenticated] map[authenticator:[GKE]]} ownerrules= . 
[PolicyRule{Resources:["selfsubjectaccessreviews" 
"selfsubjectrulesreviews"], APIGroups:["authorization.k8s.io"], Verbs: 
["create"]} PolicyRule{NonResourceURLs:["/api" "/api/*" "/apis" 
"/apis/*" "/healthz" "/swagger-2.0.0.pb-v1" "/swagger.json" 
"/swaggerapi" "/swaggerapi/*" "/version"], Verbs:["get"]}] 
ruleResolutionErrors=[]
Run Code Online (Sandbox Code Playgroud)

我的帐户在IAM中具有以下权限:

Kubernetes Engine Admin

Kubernetes引擎集群管理员

所有者

这是我的role.yaml(来自Kubernetes文档):

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: secret-reader
rules:
- apiGroups: [""]
  resources: ["secrets"]
  verbs: ["get", "watch", "list"]
Run Code Online (Sandbox Code Playgroud)

根据RBAC的GCloud文档,我需要

在尝试创建其他Role或ClusterRole权限之前,创建一个RoleBinding,为您的Google身份提供群集管理员角色.

所以我尝试了这个:

export GCP_USER=$(gcloud config get-value account | head -n 1)
kubectl create clusterrolebinding cluster-admin-binding
--clusterrole=cluster-admin --user=$GCP_USER
Run Code Online (Sandbox Code Playgroud)

哪个成功,但在创建集群角色时仍然会遇到相同的错误.

我有什么想法可能做错了吗?

小智 9

根据Google容器引擎文档,您必须首先创建一个RoleBinding,它授予您要创建的角色中包含的所有权限.

获取当前的Google身份

$ gcloud info | grep Account

Account: [myname@example.org]
Run Code Online (Sandbox Code Playgroud)

将cluster-admin授予您当前的身份

$ kubectl create clusterrolebinding myname-cluster-admin-binding --clusterrole=cluster-admin --user=myname@example.org

Clusterrolebinding "myname-cluster-admin-binding" created
Run Code Online (Sandbox Code Playgroud)

现在您可以毫无问题地创建ClusterRole.

我在CoreOS FAQ/Troubleshooting中找到了答案,请查看更多信息.

  • 这不起作用。我收到错误“clusterrolebindings.rbac.authorization.k8s.io 被禁止:用户“mail@mydomain.com”无法在集群范围内创建 clusterrolebindings.rbac.authorization.k8s.io:需要“container.clusterRoleBindings.create”权限. (2认同)
  • 您需要在 GKE 中被授予“Kubernetes Engine Admin”角色,仅“Editor”是不够的。 (2认同)

Jor*_*itt 1

这是正确的解决方案。XXX@gmail.com获取到的GCP_USER与创建角色错误信息中的用户名是否相同?

  • 这包括外壳吗?FirstLast@gmail.com 与firstlast@gmail.com 不同 (2认同)