如何授权Kubernetes用户令牌?

时间:2018-10-02 20:23:12

标签: kubernetes rbac

我有两个由kops设置的kubernetes集群。它们都在运行v1.10.8。我已尽力在两者之间建立镜像。它们都启用了RBAC。我在两者上都运行了kubernetes-dashboard。他们两个都有一个/srv/kubernetes/known_tokens.csv和一个admin用户的kube

$ sudo cat /srv/kubernetes/known_tokens.csv ABCD,admin,admin,system:masters DEFG,kube,kube (... other users ...)

我的问题是,考虑到RBAC,这些用户如何获得授权?使用令牌向kubernetes-dashboard进行身份验证时,admin用户的令牌在两个集群上均有效并且具有完全访问权限。但是kube用户的令牌只能访问其中一个群集。在一个群集上,我在仪表板中收到以下错误。

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用户。那么,为什么访问仪表板时会出现差异?我该如何调整呢?

其他一些问题:

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

更新

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

1 个答案:

答案 0 :(得分:2)

很难访问而不访问集群,但是我的猜测是,在集群上工作的merge用户可以在某个地方拥有RoleRoleBinding。不是kube的{​​{1}}。

类似这样的东西:

ClusterRole
  

如何调试诸如此类的授权问题?仪表板日志   只是说这个用户没有访问权限。有什么我可以看到的地方   特定请求或令牌映射到哪个serviceAccount?

您可以在领导者母版的ClusterRoleBinding下查看kube-apiserver日志。或者,如果它在容器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: ""

中运行