我有两个由kops设置的kubernetes集群。他们都在运行v1.10.8。我已尽力在两者之间镜像配置。它们都启用了RBAC。我在两者上都运行了kubernetes-dashboard。他们都有一个带有/srv/kubernetes/known_tokens.csv和一个admin用户的kube:
$ sudo cat /srv/kubernetes/known_tokens.csvABCD,admin,admin,system:mastersDEFG,kube,kube(... other users ...)
我的问题是这些用户如何获得考虑RBAC的授权?使用 token 对kubernetes-dashboard进行身份验证时,admin用户的 token 在两个集群上均有效,并且具有完全访问权限。但是kube用户的 token 只能访问其中一个集群。在一个群集上,我在仪表板中收到以下错误。
configmaps is forbidden: User "kube" cannot list configmaps in the namespace "default"persistentvolumeclaims is forbidden: User "kube" cannot list persistentvolumeclaims in the namespace "default"secrets is forbidden: User "kube" cannot list secrets in the namespace "default"services is forbidden: User "kube" cannot list services in the namespace "default"ingresses.extensions is forbidden: User "kube" cannot list ingresses.extensions in the namespace "default"daemonsets.apps is forbidden: User "kube" cannot list daemonsets.apps in the namespace "default"pods is forbidden: User "kube" cannot list pods in the namespace "default"events is forbidden: User "kube" cannot list events in the namespace "default"deployments.apps is forbidden: User "kube" cannot list deployments.apps in the namespace "default"replicasets.apps is forbidden: User "kube" cannot list replicasets.apps in the namespace "default"jobs.batch is forbidden: User "kube" cannot list jobs.batch in the namespace "default"cronjobs.batch is forbidden: User "kube" cannot list cronjobs.batch in the namespace "default"replicationcontrollers is forbidden: User "kube" cannot list replicationcontrollers in the namespace "default"statefulsets.apps is forbidden: User "kube" cannot list statefulsets.apps in the namespace "default"
按照official docs,“Kubernetes没有代表普通用户帐户的对象”。

我在工作群集上找不到授权kube的任何地方。同样,我找不到在其他群集上会限制kube的任何内容。我已经检查了ClusterRoleBindingdefault命名空间中的所有kube-system资源。这些都没有引用kube用户。那么,为什么在访问仪表板方面存在差异,我该如何调整呢?

其他一些问题:

  • 如何调试诸如此类的授权问题?仪表板日志仅表明该用户无权访问。我可以在某处看到特定请求或 token 映射到的serviceAccount吗?
  • k8s中的groups是什么? k8s docs提及组很多。甚至静态 token 用户也可以被分配一个组,例如system:masters which looks like a角色/集群角色but there is no system:masters role in my cluster? What exactly are groups`?根据Create user group using RBAC API?,似乎组只是可以为每个用户定义的任意标签。他们有什么意义?我可以将组映射到RBAC serviceAccount吗?

  • 更新

    我重新启动了工作群集,但它不再起作用。我收到与工作群集相同的授权错误。看起来这是某种缓存的访问。对不起,假的问题。我对后续问题仍然感到好奇,但可以将其分为单独的问题。

    最佳答案

    如果不访问集群,很难说出来,但是我的猜测是,在可以正常工作的集群上,您在某个地方有一个RoleRoleBinding,以便kube用户。不是带有ClusterRoleClusterRoleBinding

    像这样:

    kind: Role
    metadata:
      name: my-role
      namespace: default
    rules:
    - apiGroups: [""]
      Resources: ["services", "endpoints", "pods"]
      verbs: ["get", "list", "watch"]
    ---
    kind: RoleBinding
    apiVersion: rbac.authorization.k8s.io/v1beta1
    metadata:
      name: kube-role-binding
      namespace: default
    subjects:
    - kind: User
      name: "kube"
      apiGroup: ""
    roleRef:
      kind: Role
      name: my-role
      apiGroup: ""
    



    您可以查看领导者主机上/var/log/kube-apiserver.log下的kube-apiserver日志。或者,如果它在容器docker logs <container-id-of-kube-apiserver>中运行

    关于kubernetes - Kubernetes用户 token 如何被授权?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52615874/

    10-11 10:33