kubernetes - 如何使用组类型查看主题成员
问题描述
有一个默认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:
解决方案
答案更新:
似乎没有办法使用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 问题 #44418或RBAC 文档中找到:
推荐阅读
- angular6 - 如何从Angular 6中的[object object]获取数据
- python - url 的内部服务器错误:https://api.linkedin.com/v1/people/
- java - 想法 YAML 文件警告:无法解析配置属性 KEY
- php - “docker-compose up”错误:无法启动服务 php:OCI 运行时创建失败:container_linux.go:345
- ios - 可以转换为 Swift 5
- lazarus - 当我尝试将文本输出到透明图像时没有任何反应
- html - 如何使用css创建带有数字点的垂直线?
- ruby-on-rails - 如何修复“Bundler 2 需要 RubyGems 2.5 或更高版本”
- javascript - 如何在获取承诺中获得第一个数组
- windows-10 - 运行 npm run dist 后 dist 文件夹被锁定