首页 > 解决方案 > 如何使用组类型查看主题成员

问题描述

有一个默认ClusterRoleBinding名称cluster-admin.
当我跑步时,kubectl get clusterrolebindings cluster-admin -o yaml我得到:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  annotations:
    rbac.authorization.kubernetes.io/autoupdate: "true"
  creationTimestamp: 2018-06-13T12:19:26Z
  labels:
    kubernetes.io/bootstrapping: rbac-defaults
  name: cluster-admin
  resourceVersion: "98"
  selfLink: /apis/rbac.authorization.k8s.io/v1/clusterrolebindings/cluster-admin
  uid: 0361e9f2-6f04-11e8-b5dd-000c2904e34b
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- apiGroup: rbac.authorization.k8s.io
  kind: Group
  name: system:masters

subjects我有的领域:

- apiGroup: rbac.authorization.k8s.io
  kind: Group
  name: system:masters

如何查看群组成员system:masters
在这里阅读了有关组的信息,但我不明白如何查看组内的人员,如上面的示例所示system:masters

我注意到,当我/etc/kubernetes/pki/apiserver-kubelet-client.crt使用命令解码时: openssl x509 -in apiserver-kubelet-client.crt -text -noout它包含主题system:masters,但我仍然不明白该组中的用户是谁:

Issuer: CN=kubernetes
Validity
    Not Before: Jul 31 19:08:36 2018 GMT
    Not After : Jul 31 19:08:37 2019 GMT
Subject: O=system:masters, CN=kube-apiserver-kubelet-client
Subject Public Key Info:
    Public Key Algorithm: rsaEncryption
        Public-Key: (2048 bit)
        Modulus:

标签: kuberneteskubectlrbac

解决方案


答案更新

似乎没有办法使用kubectl. 没有像 Group 这样的对象可以在 Kubernetes 配置中“获取”。

Kubernetes 中的组信息目前由 Authenticator 模块提供,通常只是用户属性中的字符串。

也许您可以从用户证书的主题中获取组列表,或者如果您使用 GKE、EKS 或 AKS,则组属性存储在云用户管理系统中。

https://kubernetes.io/docs/reference/access-authn-authz/rbac/ https://kubernetes.io/docs/reference/access-authn-authz/authentication/

可以从 ClusterRoleBinding 对象请求有关系统组中 ClusterRole 成员资格的信息。(例如,对于“system:masters”,它只显示 cluster-admin ClusterRole):

使用 jq:

kubectl get clusterrolebindings -o json | jq -r '.items[] | select(.subjects[0].kind=="Group") | select(.subjects[0].name=="system:masters")'

如果您只想列出名称:

kubectl get clusterrolebindings -o json | jq -r '.items[] | select(.subjects[0].kind=="Group") | select(.subjects[0].name=="system:masters") | .metadata.name'

使用 go 模板:

kubectl get clusterrolebindings -o go-template='{{range .items}}{{range .subjects}}{{.kind}}-{{.name}} {{end}} {{" - "}} {{.metadata.name}} {{"\n"}}{{end}}' | grep "^Group-system:masters"

有关系统组的一些附加信息可以在GitHub 问题 #44418RBAC 文档中找到:


推荐阅读